diff --git a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/ImplementerLogic.cs b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..e9c7a8a --- /dev/null +++ b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,124 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.BusinessLogicsContracts; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.StoragesContracts; +using FoodOrdersContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FoodOrdersBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + 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 ArgumentNullException("Квалификация исполнителя должен быть больше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. Id: {Id}. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Qualification: {Qualification}. " + + "WorkExperience: {WorkExperience}", model.Id, model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже существует"); + } + } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs index dce0d77..2018573 100644 --- a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs @@ -14,12 +14,31 @@ namespace FoodOrdersBusinessLogic.BusinessLogics private readonly IOrderStorage _orderStorage; + static readonly object locker = new(); + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id: {Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -52,7 +71,10 @@ namespace FoodOrdersBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) @@ -115,6 +137,10 @@ namespace FoodOrdersBusinessLogic.BusinessLogics model.Sum = order.Sum; model.DateCreate = order.DateCreate; model.Status = newStatus; + if (order.ImplementerId.HasValue) + { + model.ImplementerId = order.ImplementerId; + } if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; diff --git a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/WorkModeling.cs b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..6af0eb8 --- /dev/null +++ b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,144 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.BusinessLogicsContracts; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.ViewModels; +using FoodOrdersDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace FoodOrdersBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.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(() => WorkerWorkAsync(implementer, orders)); + } + } + + /// + /// Иммитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/BindingModels/ImplementerBindingModel.cs b/FoodOrders/FoodOrdersContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..a38c037 --- /dev/null +++ b/FoodOrders/FoodOrdersContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,17 @@ +using FoodOrdersDataModels.Models; + +namespace FoodOrdersContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/BindingModels/OrderBindingModel.cs b/FoodOrders/FoodOrdersContracts/BindingModels/OrderBindingModel.cs index 07a269d..e560c9d 100644 --- a/FoodOrders/FoodOrdersContracts/BindingModels/OrderBindingModel.cs +++ b/FoodOrders/FoodOrdersContracts/BindingModels/OrderBindingModel.cs @@ -8,8 +8,11 @@ namespace FoodOrdersContracts.BindingModels public int Id { get; set; } public int DishId { get; set; } + public int ClientId { get; set; } + public int? ImplementerId { get; set; } + public int Count { get; set; } public double Sum { get; set; } diff --git a/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IImplementerLogic.cs b/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..5a1474f --- /dev/null +++ b/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.ViewModels; + +namespace FoodOrdersContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs b/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs index b15541b..e1fc221 100644 --- a/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -8,6 +8,8 @@ namespace FoodOrdersContracts.BusinessLogicsContracts { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); diff --git a/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IWorkProcess.cs b/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..a7f3d11 --- /dev/null +++ b/FoodOrders/FoodOrdersContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,10 @@ +namespace FoodOrdersContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/SearchModels/ImplementerSearchModel.cs b/FoodOrders/FoodOrdersContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..215da14 --- /dev/null +++ b/FoodOrders/FoodOrdersContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace FoodOrdersContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/SearchModels/OrderSearchModel.cs b/FoodOrders/FoodOrdersContracts/SearchModels/OrderSearchModel.cs index 85b1289..0096433 100644 --- a/FoodOrders/FoodOrdersContracts/SearchModels/OrderSearchModel.cs +++ b/FoodOrders/FoodOrdersContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,6 @@ -namespace FoodOrdersContracts.SearchModels +using FoodOrdersDataModels.Enums; + +namespace FoodOrdersContracts.SearchModels { public class OrderSearchModel { @@ -6,5 +8,7 @@ public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } } } \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/StoragesContracts/IImplementerStorage.cs b/FoodOrders/FoodOrdersContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..2fdd0f2 --- /dev/null +++ b/FoodOrders/FoodOrdersContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.ViewModels; + +namespace FoodOrdersContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + + List GetFilteredList(ImplementerSearchModel model); + + ImplementerViewModel? GetElement(ImplementerSearchModel model); + + ImplementerViewModel? Insert(ImplementerBindingModel model); + + ImplementerViewModel? Update(ImplementerBindingModel model); + + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/ViewModels/ImplementerViewModel.cs b/FoodOrders/FoodOrdersContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..5164819 --- /dev/null +++ b/FoodOrders/FoodOrdersContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,22 @@ +using FoodOrdersDataModels.Models; +using System.ComponentModel; + +namespace FoodOrdersContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersContracts/ViewModels/OrderViewModel.cs b/FoodOrders/FoodOrdersContracts/ViewModels/OrderViewModel.cs index 77385cc..bebe542 100644 --- a/FoodOrders/FoodOrdersContracts/ViewModels/OrderViewModel.cs +++ b/FoodOrders/FoodOrdersContracts/ViewModels/OrderViewModel.cs @@ -16,6 +16,10 @@ namespace FoodOrdersContracts.ViewModels public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/FoodOrders/FoodOrdersDataModels/Models/IImplementerModel.cs b/FoodOrders/FoodOrdersDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..5954a80 --- /dev/null +++ b/FoodOrders/FoodOrdersDataModels/Models/IImplementerModel.cs @@ -0,0 +1,13 @@ +namespace FoodOrdersDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersDataModels/Models/IOrderModel.cs b/FoodOrders/FoodOrdersDataModels/Models/IOrderModel.cs index 361c315..3006381 100644 --- a/FoodOrders/FoodOrdersDataModels/Models/IOrderModel.cs +++ b/FoodOrders/FoodOrdersDataModels/Models/IOrderModel.cs @@ -6,6 +6,8 @@ namespace FoodOrdersDataModels.Models { int DishId { get; } + int? ImplementerId { get; } + int Count { get; } double Sum { get; } diff --git a/FoodOrders/FoodOrdersDatabaseImplement/FoodOrdersDatabase.cs b/FoodOrders/FoodOrdersDatabaseImplement/FoodOrdersDatabase.cs index 39191f8..0504961 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/FoodOrdersDatabase.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/FoodOrdersDatabase.cs @@ -24,5 +24,6 @@ optionsBuilder) public virtual DbSet DishComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Implemets/ImplementerStorage.cs b/FoodOrders/FoodOrdersDatabaseImplement/Implemets/ImplementerStorage.cs new file mode 100644 index 0000000..5930a0c --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Implemets/ImplementerStorage.cs @@ -0,0 +1,86 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.StoragesContracts; +using FoodOrdersContracts.ViewModels; +using FoodOrdersDatabaseImplement.Models; + +namespace FoodOrdersDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new FoodOrdersDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new FoodOrdersDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new FoodOrdersDatabase(); + return context.Implementers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new FoodOrdersDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new FoodOrdersDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new FoodOrdersDatabase(); + var element = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Implemets/OrderStorage.cs b/FoodOrders/FoodOrdersDatabaseImplement/Implemets/OrderStorage.cs index 1d8ec06..7cc7bfc 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Implemets/OrderStorage.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Implemets/OrderStorage.cs @@ -16,12 +16,19 @@ namespace FoodOrdersDatabaseImplement.Implements { public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } using var context = new FoodOrdersDatabase(); - return context.Orders.Include(x => x.Dish).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders + .Include(x => x.Dish) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id)?.GetViewModel; ; } public List GetFilteredList(OrderSearchModel model) @@ -32,6 +39,7 @@ namespace FoodOrdersDatabaseImplement.Implements return context.Orders .Include(x => x.Dish) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -41,6 +49,7 @@ namespace FoodOrdersDatabaseImplement.Implements return context.Orders .Include(x => x.Dish) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -50,17 +59,38 @@ namespace FoodOrdersDatabaseImplement.Implements return context.Orders .Include(x => x.Dish) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return context.Orders + .Include(x => x.Dish) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Status != null) + { + return context.Orders + .Include(x => x.Dish) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } return new(); } public List GetFullList() { using var context = new FoodOrdersDatabase(); - return context.Orders.Include(x => x.Dish).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Dish).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -73,7 +103,7 @@ namespace FoodOrdersDatabaseImplement.Implements using var context = new FoodOrdersDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Dish).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + return context.Orders.Include(x => x.Dish).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -86,7 +116,7 @@ namespace FoodOrdersDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Dish).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Dish).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20240504212438_Implem.Designer.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20240504212438_Implem.Designer.cs new file mode 100644 index 0000000..a4ffdf4 --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20240504212438_Implem.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using FoodOrdersDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FoodOrdersDatabaseImplement.Migrations +{ + [DbContext(typeof(FoodOrdersDatabase))] + [Migration("20240504212438_Implem")] + partial class Implem + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DishName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Dishs"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DishId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DishId"); + + b.ToTable("DishComponents"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("DishId") + .HasColumnType("int"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("DishId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b => + { + b.HasOne("FoodOrdersDatabaseImplement.Models.Component", "Component") + .WithMany("DishComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish") + .WithMany("Components") + .HasForeignKey("DishId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Dish"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => + { + b.HasOne("FoodOrdersDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish") + .WithMany("Orders") + .HasForeignKey("DishId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FoodOrdersDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + + b.Navigation("Dish"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => + { + b.Navigation("DishComponents"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20240504212438_Implem.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20240504212438_Implem.cs new file mode 100644 index 0000000..62b42be --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20240504212438_Implem.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FoodOrdersDatabaseImplement.Migrations +{ + /// + public partial class Implem : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs index f0f6d7e..7502ecc 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs @@ -113,6 +113,33 @@ namespace FoodOrdersDatabaseImplement.Migrations b.ToTable("DishComponents"); }); + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace FoodOrdersDatabaseImplement.Migrations b.Property("DishId") .HasColumnType("int"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -148,6 +178,8 @@ namespace FoodOrdersDatabaseImplement.Migrations b.HasIndex("DishId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -184,9 +216,15 @@ namespace FoodOrdersDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("FoodOrdersDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.Navigation("Client"); b.Navigation("Dish"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Client", b => @@ -205,6 +243,11 @@ namespace FoodOrdersDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Models/Implementer.cs b/FoodOrders/FoodOrdersDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..0ec9d4c --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,77 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.ViewModels; +using FoodOrdersDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace FoodOrdersDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + [Required] + public string ImplementerFIO { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public int WorkExperience { get; set; } + + [Required] + public int Qualification { get; set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public static Implementer Create(ImplementerViewModel model) + { + return new Implementer + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Models/Order.cs b/FoodOrders/FoodOrdersDatabaseImplement/Models/Order.cs index 7742097..9c61e35 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Models/Order.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Models/Order.cs @@ -19,6 +19,7 @@ namespace FoodOrdersDatabaseImplement.Models public int DishId { get; private set; } [Required] public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } [Required] public int Count { get; private set; } [Required] @@ -31,6 +32,7 @@ namespace FoodOrdersDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public virtual Dish Dish { get; private set; } public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -42,6 +44,7 @@ namespace FoodOrdersDatabaseImplement.Models { DishId = model.DishId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -59,6 +62,7 @@ namespace FoodOrdersDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -66,13 +70,15 @@ namespace FoodOrdersDatabaseImplement.Models Id = Id, DishId = DishId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, DateCreate = DateCreate, DateImplement = DateImplement, Status = Status, - DishName = Dish.DishName, - ClientFIO = Client.ClientFIO + DishName = Dish.DishName ?? string.Empty, + ClientFIO = Client.ClientFIO ?? string.Empty, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty }; } } diff --git a/FoodOrders/FoodOrdersFileImplement/DataFileSingleton.cs b/FoodOrders/FoodOrdersFileImplement/DataFileSingleton.cs index ba7ea46..0b4985c 100644 --- a/FoodOrders/FoodOrdersFileImplement/DataFileSingleton.cs +++ b/FoodOrders/FoodOrdersFileImplement/DataFileSingleton.cs @@ -12,14 +12,18 @@ namespace FoodOrdersFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string DishFileName = "Dish.xml"; + private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Dishs { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { @@ -36,6 +40,7 @@ namespace FoodOrdersFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { @@ -43,6 +48,7 @@ namespace FoodOrdersFileImplement Dishs = LoadData(DishFileName, "Dish", x => Dish.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/FoodOrders/FoodOrdersFileImplement/Implements/ImplementerStorage.cs b/FoodOrders/FoodOrdersFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..53c833d --- /dev/null +++ b/FoodOrders/FoodOrdersFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,88 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.StoragesContracts; +using FoodOrdersContracts.ViewModels; +using FoodOrdersFileImplement.Models; + +namespace FoodOrdersFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + return source.Implementers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FoodOrders/FoodOrdersFileImplement/Implements/OrderStorage.cs b/FoodOrders/FoodOrdersFileImplement/Implements/OrderStorage.cs index 7c3751a..8a6f4c3 100644 --- a/FoodOrders/FoodOrdersFileImplement/Implements/OrderStorage.cs +++ b/FoodOrders/FoodOrdersFileImplement/Implements/OrderStorage.cs @@ -45,21 +45,34 @@ namespace FoodOrdersFileImplement.Implements .Select(x => AddDishName(x.GetViewModel)) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => AddDishName(x.GetViewModel)) + .ToList(); + } + else if (model.Status != null) + { + return source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => AddDishName(x.GetViewModel)) + .ToList(); + } return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - return AddDishName(order.GetViewModel); + var order = source.Orders.FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id); + return order?.GetViewModel != null ? AddDishName(order.GetViewModel) : null; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/FoodOrders/FoodOrdersFileImplement/Models/Implementer.cs b/FoodOrders/FoodOrdersFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..3e5a680 --- /dev/null +++ b/FoodOrders/FoodOrdersFileImplement/Models/Implementer.cs @@ -0,0 +1,81 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.ViewModels; +using FoodOrdersDataModels.Models; +using System.Xml.Linq; + +namespace FoodOrdersFileImplement.Models +{ + internal class Implementer : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification) + ); + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersFileImplement/Models/Order.cs b/FoodOrders/FoodOrdersFileImplement/Models/Order.cs index add3855..38a1064 100644 --- a/FoodOrders/FoodOrdersFileImplement/Models/Order.cs +++ b/FoodOrders/FoodOrdersFileImplement/Models/Order.cs @@ -15,6 +15,8 @@ namespace FoodOrdersFileImplement.Models public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -36,6 +38,7 @@ namespace FoodOrdersFileImplement.Models Id = model.Id, DishId = model.DishId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -55,6 +58,7 @@ namespace FoodOrdersFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), DishId = Convert.ToInt32(element.Element("DishId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -79,6 +83,7 @@ namespace FoodOrdersFileImplement.Models Id = Id, DishId = DishId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -90,6 +95,7 @@ namespace FoodOrdersFileImplement.Models new XAttribute("Id", Id), new XElement("DishId", DishId), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/FoodOrders/FoodOrdersListImplement/DataListSingleton.cs b/FoodOrders/FoodOrdersListImplement/DataListSingleton.cs index 897289c..90aef00 100644 --- a/FoodOrders/FoodOrdersListImplement/DataListSingleton.cs +++ b/FoodOrders/FoodOrdersListImplement/DataListSingleton.cs @@ -13,12 +13,15 @@ namespace FoodOrdersListImplement public List Dishs { get; set; } public List Clients { get; private set; } + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Dishs = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() diff --git a/FoodOrders/FoodOrdersListImplement/Implements/ImplementerStorage.cs b/FoodOrders/FoodOrdersListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..99fbbb4 --- /dev/null +++ b/FoodOrders/FoodOrdersListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,109 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.StoragesContracts; +using FoodOrdersContracts.ViewModels; +using FoodOrdersListImplement.Models; + +namespace FoodOrdersListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + foreach (var implementer in _source.Implementers) + { + if ((!string.IsNullOrEmpty(model.ImplementerFIO) && implementer.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + || (model.Id.HasValue && implementer.Id == model.Id)) + { + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FoodOrders/FoodOrdersListImplement/Implements/OrderStorage.cs b/FoodOrders/FoodOrdersListImplement/Implements/OrderStorage.cs index c397e30..ae1bb39 100644 --- a/FoodOrders/FoodOrdersListImplement/Implements/OrderStorage.cs +++ b/FoodOrders/FoodOrdersListImplement/Implements/OrderStorage.cs @@ -58,12 +58,32 @@ namespace FoodOrdersListImplement.Implements } } } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(AddDishName(order.GetViewModel)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(AddDishName(order.GetViewModel)); + } + } + } return result; } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -73,6 +93,14 @@ namespace FoodOrdersListImplement.Implements { return AddDishName(order.GetViewModel); } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return AddDishName(order.GetViewModel); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return AddDishName(order.GetViewModel); + } } return null; } diff --git a/FoodOrders/FoodOrdersListImplement/Models/Implementer.cs b/FoodOrders/FoodOrdersListImplement/Models/Implementer.cs new file mode 100644 index 0000000..d8d9870 --- /dev/null +++ b/FoodOrders/FoodOrdersListImplement/Models/Implementer.cs @@ -0,0 +1,56 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.ViewModels; +using FoodOrdersDataModels.Models; + +namespace FoodOrdersListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersListImplement/Models/Order.cs b/FoodOrders/FoodOrdersListImplement/Models/Order.cs index 4194116..296bca4 100644 --- a/FoodOrders/FoodOrdersListImplement/Models/Order.cs +++ b/FoodOrders/FoodOrdersListImplement/Models/Order.cs @@ -13,6 +13,8 @@ namespace FoodOrdersListImplement.Models public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -34,6 +36,7 @@ namespace FoodOrdersListImplement.Models Id = model.Id, DishId = model.DishId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -50,6 +53,7 @@ namespace FoodOrdersListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -57,6 +61,7 @@ namespace FoodOrdersListImplement.Models Id = Id, DishId = DishId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, diff --git a/FoodOrders/FoodOrdersRestApi/Controllers/ImplementerController.cs b/FoodOrders/FoodOrdersRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..8cd0bcb --- /dev/null +++ b/FoodOrders/FoodOrdersRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.BusinessLogicsContracts; +using FoodOrdersContracts.SearchModels; +using FoodOrdersContracts.ViewModels; +using FoodOrdersDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace AbstractShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Employee authorization error"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error receiving new orders"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error of receiving the current order of an implementer"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Taking order №{Id} in work error", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Finishing order №{Id} error", model.Id); + throw; + } + } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormImplementer.Designer.cs b/FoodOrders/FoodOrdersView/FormImplementer.Designer.cs new file mode 100644 index 0000000..e4a5fd0 --- /dev/null +++ b/FoodOrders/FoodOrdersView/FormImplementer.Designer.cs @@ -0,0 +1,173 @@ +namespace FoodOrdersView +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxPassword = new TextBox(); + labelPassword = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxFIO = new TextBox(); + labelFIO = new Label(); + textBoxWorkExperience = new TextBox(); + labelWorkExperience = new Label(); + textBoxQualification = new TextBox(); + labelQualification = new Label(); + SuspendLayout(); + // + // textBoxPassword + // + textBoxPassword.Location = new Point(102, 44); + textBoxPassword.Margin = new Padding(4, 3, 4, 3); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(235, 23); + textBoxPassword.TabIndex = 15; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(3, 48); + labelPassword.Margin = new Padding(4, 0, 4, 0); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(55, 15); + labelPassword.TabIndex = 14; + labelPassword.Text = "Пароль :"; + // + // buttonCancel + // + buttonCancel.Location = new Point(242, 140); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(147, 140); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 16; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(102, 16); + textBoxFIO.Margin = new Padding(4, 3, 4, 3); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(235, 23); + textBoxFIO.TabIndex = 13; + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(3, 19); + labelFIO.Margin = new Padding(4, 0, 4, 0); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(40, 15); + labelFIO.TabIndex = 12; + labelFIO.Text = "ФИО :"; + // + // textBoxWorkExperience + // + textBoxWorkExperience.Location = new Point(102, 74); + textBoxWorkExperience.Margin = new Padding(4, 3, 4, 3); + textBoxWorkExperience.Name = "textBoxWorkExperience"; + textBoxWorkExperience.Size = new Size(235, 23); + textBoxWorkExperience.TabIndex = 19; + // + // labelWorkExperience + // + labelWorkExperience.AutoSize = true; + labelWorkExperience.Location = new Point(3, 78); + labelWorkExperience.Margin = new Padding(4, 0, 4, 0); + labelWorkExperience.Name = "labelWorkExperience"; + labelWorkExperience.Size = new Size(85, 15); + labelWorkExperience.TabIndex = 18; + labelWorkExperience.Text = "Стаж работы :"; + // + // textBoxQualification + // + textBoxQualification.Location = new Point(102, 103); + textBoxQualification.Margin = new Padding(4, 3, 4, 3); + textBoxQualification.Name = "textBoxQualification"; + textBoxQualification.Size = new Size(235, 23); + textBoxQualification.TabIndex = 21; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(3, 106); + labelQualification.Margin = new Padding(4, 0, 4, 0); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(94, 15); + labelQualification.TabIndex = 20; + labelQualification.Text = "Квалификация :"; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(350, 178); + Controls.Add(textBoxQualification); + Controls.Add(labelQualification); + Controls.Add(textBoxWorkExperience); + Controls.Add(labelWorkExperience); + Controls.Add(textBoxPassword); + Controls.Add(labelPassword); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxFIO); + Controls.Add(labelFIO); + Margin = new Padding(2, 2, 2, 2); + Name = "FormImplementer"; + Text = "Исполнитель"; + Load += FormImplementer_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxPassword; + private Label labelPassword; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxFIO; + private Label labelFIO; + private TextBox textBoxWorkExperience; + private Label labelWorkExperience; + private TextBox textBoxQualification; + private Label labelQualification; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormImplementer.cs b/FoodOrders/FoodOrdersView/FormImplementer.cs new file mode 100644 index 0000000..1d510c6 --- /dev/null +++ b/FoodOrders/FoodOrdersView/FormImplementer.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.BusinessLogicsContracts; +using FoodOrdersContracts.SearchModels; + +namespace FoodOrdersView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + + private readonly IImplementerLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Receiving implementer"); + var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + textBoxQualification.Text = view.Qualification.ToString(); + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Receiving implementer error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО исполнителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxWorkExperience.Text)) + { + MessageBox.Show("Заполните стаж работы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxQualification.Text)) + { + MessageBox.Show("Заполните квалификацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving implementer"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Saving implementer error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FoodOrders/FoodOrdersView/FormImplementer.resx b/FoodOrders/FoodOrdersView/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FoodOrders/FoodOrdersView/FormImplementer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormImplementers.cs b/FoodOrders/FoodOrdersView/FormImplementers.cs new file mode 100644 index 0000000..65c3c5a --- /dev/null +++ b/FoodOrders/FoodOrdersView/FormImplementers.cs @@ -0,0 +1,106 @@ +using FoodOrdersContracts.BindingModels; +using FoodOrdersContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FoodOrdersView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + + private readonly IImplementerLogic _logic; + + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Implementers loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementers loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of implementer"); + try + { + if (!_logic.Delete(new ImplementerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementer deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormImplementers.designer.cs b/FoodOrders/FoodOrdersView/FormImplementers.designer.cs new file mode 100644 index 0000000..0cf1b1f --- /dev/null +++ b/FoodOrders/FoodOrdersView/FormImplementers.designer.cs @@ -0,0 +1,127 @@ +namespace FoodOrdersView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 0; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormImplementers"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Исполнители"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormImplementers.resx b/FoodOrders/FoodOrdersView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FoodOrders/FoodOrdersView/FormImplementers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormMain.cs b/FoodOrders/FoodOrdersView/FormMain.cs index 2ada5da..2e69062 100644 --- a/FoodOrders/FoodOrdersView/FormMain.cs +++ b/FoodOrders/FoodOrdersView/FormMain.cs @@ -13,12 +13,15 @@ namespace FoodOrdersView private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -38,6 +41,8 @@ namespace FoodOrdersView dataGridView.Columns["DishName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -76,52 +81,6 @@ namespace FoodOrdersView } } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -188,5 +147,20 @@ namespace FoodOrdersView form.ShowDialog(); } } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormMain.designer.cs b/FoodOrders/FoodOrdersView/FormMain.designer.cs index 8a2011a..7c7ef6b 100644 --- a/FoodOrders/FoodOrdersView/FormMain.designer.cs +++ b/FoodOrders/FoodOrdersView/FormMain.designer.cs @@ -32,17 +32,17 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); БлюдаToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); списокБлюдToolStripMenuItem = new ToolStripMenuItem(); компонентыПоБлюдамToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); buttonIssuedOrder = new Button(); - buttonOrderReady = new Button(); - buttonTakeOrderInWork = new Button(); buttonCreateOrder = new Button(); dataGridView = new DataGridView(); buttonUpd = new Button(); - клиентыToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -50,17 +50,17 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Padding = new Padding(8, 3, 0, 3); - menuStrip.Size = new Size(1178, 30); + menuStrip.Size = new Size(1323, 30); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, БлюдаToolStripMenuItem, клиентыToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, БлюдаToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -68,17 +68,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(185, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // БлюдаToolStripMenuItem // БлюдаToolStripMenuItem.Name = "БлюдаToolStripMenuItem"; - БлюдаToolStripMenuItem.Size = new Size(224, 26); + БлюдаToolStripMenuItem.Size = new Size(185, 26); БлюдаToolStripMenuItem.Text = "Еда"; БлюдаToolStripMenuItem.Click += БлюдоToolStripMenuItem_Click; // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(185, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокБлюдToolStripMenuItem, компонентыПоБлюдамToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -107,10 +121,17 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += СписокЗаказовToolStripMenuItem_Click; // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(114, 24); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // // buttonIssuedOrder // buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonIssuedOrder.Location = new Point(965, 308); + buttonIssuedOrder.Location = new Point(1110, 146); buttonIssuedOrder.Margin = new Padding(5, 4, 5, 4); buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Size = new Size(199, 36); @@ -119,34 +140,10 @@ buttonIssuedOrder.UseVisualStyleBackColor = true; buttonIssuedOrder.Click += ButtonIssuedOrder_Click; // - // buttonOrderReady - // - buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonOrderReady.Location = new Point(965, 228); - buttonOrderReady.Margin = new Padding(5, 4, 5, 4); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(199, 36); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonTakeOrderInWork.Location = new Point(965, 156); - buttonTakeOrderInWork.Margin = new Padding(5, 4, 5, 4); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(199, 36); - buttonTakeOrderInWork.TabIndex = 2; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // // buttonCreateOrder // buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.Location = new Point(965, 77); + buttonCreateOrder.Location = new Point(1110, 77); buttonCreateOrder.Margin = new Padding(5, 4, 5, 4); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(199, 36); @@ -170,13 +167,13 @@ dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 51; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(944, 427); + dataGridView.Size = new Size(1089, 427); dataGridView.TabIndex = 0; // // buttonUpd // buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonUpd.Location = new Point(965, 387); + buttonUpd.Location = new Point(1110, 216); buttonUpd.Margin = new Padding(5, 4, 5, 4); buttonUpd.Name = "buttonUpd"; buttonUpd.Size = new Size(199, 36); @@ -185,22 +182,13 @@ buttonUpd.UseVisualStyleBackColor = true; buttonUpd.Click += ButtonUpd_Click; // - // клиентыToolStripMenuItem - // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(224, 26); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1178, 463); + ClientSize = new Size(1323, 463); Controls.Add(buttonUpd); Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(dataGridView); Controls.Add(menuStrip); @@ -224,8 +212,6 @@ private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem БлюдаToolStripMenuItem; private Button buttonIssuedOrder; - private Button buttonOrderReady; - private Button buttonTakeOrderInWork; private Button buttonCreateOrder; private DataGridView dataGridView; private Button buttonUpd; @@ -234,6 +220,8 @@ private ToolStripMenuItem компонентыПоБлюдамToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } diff --git a/FoodOrders/FoodOrdersView/Program.cs b/FoodOrders/FoodOrdersView/Program.cs index 5d472ef..b97fbbf 100644 --- a/FoodOrders/FoodOrdersView/Program.cs +++ b/FoodOrders/FoodOrdersView/Program.cs @@ -41,12 +41,15 @@ namespace FoodOrdersView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -55,6 +58,8 @@ namespace FoodOrdersView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient();