PIbd-21 Lab6 KozyrevSS SewingDresses #19
@ -0,0 +1,76 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.BusinessLogicsContracts;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ImplementLogic : IImplementLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementStorage _storage;
|
||||
public ImplementLogic(ILogger<ImplementLogic> logger, IImplementStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
public ImplementViewModel? ReadElement(ImplementSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
_logger.LogInformation("ReadElement. FIO:{ImplementFIO}. Id:{Id}", model.ImplementFIO, model.Id);
|
||||
var element = _storage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public List<ImplementViewModel>? ReadList(ImplementSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
private void CheckModel(ImplementBindingModel? model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(model.ImplementFIO))
|
||||
throw new ArgumentException("Нет ФИО исполнителя", nameof(model.ImplementFIO));
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
|
||||
}
|
||||
if (model.WorkExperience < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стаж меньше 0", nameof(model.WorkExperience));
|
||||
}
|
||||
if (model.Qualification < 0)
|
||||
{
|
||||
throw new ArgumentException("Квалификация меньше 0", nameof(model.Qualification));
|
||||
}
|
||||
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. WorkExperience:{WorkExperience}. Qualification:{Qualification}. Id: {Id} ", model.ImplementFIO, model.Password, model.WorkExperience, model.Qualification, model.Id);
|
||||
var element = _storage.GetElement(new ImplementSearchModel { ImplementFIO = model.ImplementFIO });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с этим именем уже существует");
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
static readonly object locker = new object();
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
@ -19,6 +20,22 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var elem = _orderStorage.GetElement(model);
|
||||
if (elem == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement found. Id:{Id}", elem.Id);
|
||||
return elem;
|
||||
}
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
||||
@ -32,12 +49,16 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model)
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество заказов должно быть больше нуля");
|
||||
@ -68,6 +89,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
|
||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
CheckModel (model, false);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
@ -87,7 +109,10 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
lock (locker)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
|
@ -0,0 +1,78 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SewingDressesContracts.BusinessLogicsContracts;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDataModels.Enums;
|
||||
|
||||
namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class WorkModeling : IWorkProcess
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Random _rnd;
|
||||
private IOrderLogic _orderLogic;
|
||||
public WorkModeling(ILogger<WorkModeling> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
public void DoWork(IImplementLogic implementLogic, IOrderLogic orderLogic)
|
||||
{
|
||||
_orderLogic = orderLogic;
|
||||
var implementers = implementLogic.ReadList(null);
|
||||
if (implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
|
||||
if (orders == null || orders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||
foreach (var implementer in implementers) {
|
||||
Task.Run(() => Worker);
|
||||
}
|
||||
|
||||
}
|
||||
private async Task WorkerWorkAsync(ImplementViewModel implement, List<OrderViewModel> orders)
|
||||
{
|
||||
if (_orderLogic == null || implement == null)
|
||||
return;
|
||||
await RunOr
|
||||
}
|
||||
|
||||
private async Task RunOrderInWork(ImplementViewModel implement)
|
||||
{
|
||||
if (_orderLogic == null || implement == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementId = implement.Id,
|
||||
Status = OrderStatus.Выполняется
|
||||
}));
|
||||
if (runOrder == null)
|
||||
return;
|
||||
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implement.Id, runOrder.Id);
|
||||
Thread.Sleep(implement.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implement.Id, runOrder.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel { Id = runOrder.Id });
|
||||
Thread.Sleep(implement.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning("Error try get work");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.BindingModels
|
||||
{
|
||||
public class ImplementBindingModel : IImplementModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ImplementFIO { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public int WorkExperience { get; set; }
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@ namespace SewingDressesContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int DressId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementId { get; set; }
|
||||
public string? ImplementFIO { get; set; } = string.Empty;
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
@ -0,0 +1,20 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IImplementLogic
|
||||
{
|
||||
List<ImplementViewModel>? ReadList(ImplementSearchModel? model);
|
||||
ImplementViewModel? ReadElement(ImplementSearchModel? model);
|
||||
bool Create(ImplementBindingModel? model);
|
||||
bool Update(ImplementBindingModel? model);
|
||||
bool Delete(ImplementBindingModel? model);
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ namespace SewingDressesContracts.BusinessLogicsContracts
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IWorkProcess
|
||||
{
|
||||
void DoWork(IImplementLogic implementLogic, IOrderLogic orderLogic);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.SearchModels
|
||||
{
|
||||
public class ImplementSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ImplementFIO { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
namespace SewingDressesContracts.SearchModels
|
||||
using SewingDressesDataModels.Enums;
|
||||
|
||||
namespace SewingDressesContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public int? ImplementId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.StoragesContracts
|
||||
{
|
||||
public interface IImplementStorage
|
||||
{
|
||||
List<ImplementViewModel> GetFullList();
|
||||
List<ImplementViewModel> GetFilteredList(ImplementSearchModel model);
|
||||
ImplementViewModel? GetElement(ImplementSearchModel model);
|
||||
ImplementViewModel? Insert(ImplementSearchModel? model);
|
||||
ImplementViewModel? Update(ImplementSearchModel? model);
|
||||
ImplementViewModel? Delete(ImplementSearchModel? model);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.ViewModels
|
||||
{
|
||||
public class ImplementViewModel : IImplementModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя исполнителя")]
|
||||
public string ImplementFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[DisplayName("Опыт работы")]
|
||||
public int WorkExperience { get; set; }
|
||||
[DisplayName("Квалификация")]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
@ -9,9 +9,12 @@ namespace SewingDressesContracts.ViewModels
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int DressId { get; set; }
|
||||
public int? ImplementId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Имя клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Имя исполнителя")]
|
||||
public string ImplementFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Платье")]
|
||||
public string DressName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
|
@ -0,0 +1,10 @@
|
||||
namespace SewingDressesDataModels.Models
|
||||
{
|
||||
public interface IImplementModel : IId
|
||||
{
|
||||
string ImplementFIO { get; }
|
||||
string Password { get; }
|
||||
int WorkExperience { get; }
|
||||
int Qualification { get; }
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ namespace SewingDressesDataModels.Models
|
||||
int DressId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementId { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
|
@ -0,0 +1,56 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Implements
|
||||
{
|
||||
public class ImplementStorage : IImplementStorage
|
||||
{
|
||||
public ImplementViewModel? Insert(ImplementBindingModel model)
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
var newImplement = Implement.Create(model);
|
||||
if (newImplement == null)
|
||||
return null;
|
||||
context.Implements.Add(newImplement);
|
||||
context.SaveChanges();
|
||||
return newImplement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Update(ImplementBindingModel model)
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
var implement = context.Implements.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (implement == null) return null;
|
||||
implement.Update(model);
|
||||
context.SaveChanges();
|
||||
return implement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Delete(ImplementBindingModel model)
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
var implement = context.Implements.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (implement == null) return null;
|
||||
context.Implements.Remove(implement);
|
||||
context.SaveChanges();
|
||||
return implement.GetViewModel;
|
||||
}
|
||||
public List<ImplementViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
return context.Implements.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<ImplementViewModel> GetFilteredList(ImplementSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementFIO)) return new();
|
||||
using var context = new SewingDressesDatabase();
|
||||
return context.Implements.Where(x => x.ImplementFIO.Equals(model.ImplementFIO)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
@ -8,33 +9,37 @@ namespace SewingDressesDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel?> GetFullList()
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
return context.Orders.Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<OrderViewModel?> GetFilteredList(OrderSearchModel model)
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue)
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Status.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SewingDressesDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList(); return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
else if (model.ClientId.HasValue)
|
||||
return context.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||
else if (model.DateFrom != null)
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
|
||||
else
|
||||
return context.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.DateCreate >= model.DateFrom).Where(x => x.Status.Equals(model.Status)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && (!model.ImplementId.HasValue || !model.Status.HasValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SewingDressesDatabase();
|
||||
return AcessDressesStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel, context);
|
||||
if (model.Id.HasValue)
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.ImplementId == model.ImplementId && x.Status == model.Status)?.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
|
@ -0,0 +1,59 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Models
|
||||
{
|
||||
public class Implement : IImplementModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string ImplementFIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int WorkExperience { get; private set; }
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int Qualification { get; private set; }
|
||||
[ForeignKey("ImplementId")]
|
||||
public virtual List<Order>? Orders { get; set; } = new();
|
||||
public static Implement? Create(ImplementBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
return new Implement
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementFIO = model.ImplementFIO,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Password = model.Password,
|
||||
Qualification = model.Qualification,
|
||||
};
|
||||
}
|
||||
public ImplementViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementFIO = ImplementFIO,
|
||||
WorkExperience = WorkExperience,
|
||||
Password = Password,
|
||||
Qualification = Qualification
|
||||
};
|
||||
public void Update(ImplementBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
ImplementFIO = model.ImplementFIO;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Password = model.Password;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
[Required]
|
||||
public int? ImplementId { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
@ -23,6 +25,9 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public virtual Dress Dress { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
public virtual Implement? Implement { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
@ -35,6 +40,7 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
Id = model.Id,
|
||||
DressId = model.DressId,
|
||||
ClientId = model.ClientId,
|
||||
ImplementId = model.ImplementId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -55,6 +61,8 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
Id = Id,
|
||||
DressId = DressId,
|
||||
ClientId = ClientId,
|
||||
ImplementId = ImplementId,
|
||||
ImplementFIO = Implement?.ImplementFIO,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -17,5 +17,6 @@ namespace SewingDressesDatabaseImplement
|
||||
public virtual DbSet<DressComponent> DressComponents { get; set; }
|
||||
public virtual DbSet<Order> Orders { get; set; }
|
||||
public virtual DbSet<Client> Clients { get; set; }
|
||||
public virtual DbSet<Implement> Implements { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user