From bb8974a2f6e6c151dfc19185e63952e1b9ff6167 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Fri, 21 Jun 2024 14:39:07 +0400 Subject: [PATCH] lab 6 in process --- Pizzeria/Pizzeria/Program.cs | 4 +++ .../BusinessLogic/OrderLogic.cs | 32 +++++++++++++++++-- .../BindingModels/OrderBindingModel.cs | 1 + .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../SearchModels/OrderSearchModel.cs | 6 +++- .../ViewModels/OrderViewModel.cs | 4 +++ .../PizzeriaDataModels/Models/IOrderModel.cs | 1 + .../Implements/OrderStorage.cs | 7 +++- .../PizzeriaDatabaseImplement/Models/Order.cs | 11 ++++++- Pizzeria/PizzeriaRestApi/Program.cs | 2 ++ 10 files changed, 64 insertions(+), 5 deletions(-) diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index d447ad0..e788c1d 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -39,12 +39,14 @@ namespace Pizzeria services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -60,6 +62,8 @@ namespace Pizzeria services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs index c9fa888..f9408de 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -38,11 +38,31 @@ namespace PizzeriaBusinessLogic.BusinessLogic } return true; } - + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, 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 List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); + _logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { @@ -92,6 +112,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic } model.Status = status; + if (order.ImplementerId.HasValue) + { + model.ImplementerId = order.ImplementerId; + } if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; @@ -132,6 +156,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic { throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + } _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PizzaId: {PizzaId}. PizzaCount: {Count}", model.Id, model.Sum, model.PizzaId, model.Count); } } diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs index 88d6a4a..0379065 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -9,6 +9,7 @@ namespace PizzeriaContracts.BindingModels public int Id { get; set; } public int PizzaId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs index a2507e3..ce429f4 100644 --- a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,5 +12,6 @@ namespace PizzeriaContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); } } diff --git a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs index f796587..5c10320 100644 --- a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs +++ b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs @@ -1,9 +1,13 @@ -namespace PizzeriaContracts.SearchModels +using PizzeriaDataModels.Enums; + +namespace PizzeriaContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } public int? ClientId { get; set; } + public OrderStatus? Status { get; set; } + public int? ImplementerId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index cb411df..ae25144 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -19,6 +19,10 @@ namespace PizzeriaContracts.ViewModels [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string? ImplementerFIO { get; set; } = null; + [DisplayName("Количество")] public int Count { get; set; } diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs index 83add86..6ed8326 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -7,6 +7,7 @@ namespace PizzeriaDataModels.Models { int PizzaId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs index 0fd2a4f..527e0e7 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs @@ -14,7 +14,12 @@ namespace PizzeriaDatabaseImplement.Implements public List GetFullList() { using var context = new PizzeriaDatabase(); - return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + return context.Orders + .Include(x => x.Pizza) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(OrderSearchModel model) diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs index b319b00..fa38216 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs @@ -22,6 +22,9 @@ namespace PizzeriaDatabaseImplement.Models public virtual Pizza Pizza { get; set; } = new(); + public int? ImplementerId { get; private set; } + public virtual Implementer? Implementer { get; set; } = new(); + [Required] public int Count { get; private set; } @@ -45,6 +48,8 @@ namespace PizzeriaDatabaseImplement.Models Client = context.Clients.First(x => x.Id == model.ClientId), PizzaId = model.PizzaId, Pizza = context.Pizzas.First(x => x.Id == model.PizzaId), + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -53,7 +58,7 @@ namespace PizzeriaDatabaseImplement.Models }; } - public void Update(OrderBindingModel? model) + public void Update(PizzeriaDatabase context, OrderBindingModel? model) { if (model == null) { @@ -61,6 +66,8 @@ namespace PizzeriaDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null; } public OrderViewModel GetViewModel => new() @@ -70,6 +77,8 @@ namespace PizzeriaDatabaseImplement.Models ClientFIO = Client.ClientFIO, PizzaId = PizzaId, PizzaName = Pizza.PizzaName, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, Count = Count, Sum = Sum, Status = Status, diff --git a/Pizzeria/PizzeriaRestApi/Program.cs b/Pizzeria/PizzeriaRestApi/Program.cs index 004702c..dadd31c 100644 --- a/Pizzeria/PizzeriaRestApi/Program.cs +++ b/Pizzeria/PizzeriaRestApi/Program.cs @@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle