From ba3967437706a6b0ce41d22ba1f8b58fe19f48d8 Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 1 May 2024 15:33:34 +0400 Subject: [PATCH] =?UTF-8?q?+=20=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=B2=20=D1=81=D1=83=D1=89=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=C2=AB=D0=97=D0=B0=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/OrderBindingModel.cs | 1 + .../SearchModels/OrderSearchModel.cs | 1 + .../ConfectioneryContracts/ViewModels/OrderViewModel.cs | 4 ++++ Confectionery/ConfectioneryDataModels/IOrderModel.cs | 1 + Confectionery/ConfectioneryDatabaseImplement/Order.cs | 8 ++++++++ .../ConfectioneryDatabaseImplement/OrderStorage.cs | 6 +++++- 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs index 8262c80..d51f207 100644 --- a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs +++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -12,6 +12,7 @@ namespace ConfectioneryContracts.BindingModels { public int Id { get; set; } public int PastryId { get; set; } + public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs index 9c4821b..d636d99 100644 --- a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs +++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -9,6 +9,7 @@ namespace ConfectioneryContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs index 217f85f..f09bcf1 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -13,6 +13,10 @@ namespace ConfectioneryContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int ClientId { get; set; } + + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; public int PastryId { get; set; } [DisplayName("Изделие")] public string PastryName { get; set; } = string.Empty; diff --git a/Confectionery/ConfectioneryDataModels/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/IOrderModel.cs index 40e889f..97508bb 100644 --- a/Confectionery/ConfectioneryDataModels/IOrderModel.cs +++ b/Confectionery/ConfectioneryDataModels/IOrderModel.cs @@ -10,6 +10,7 @@ namespace ConfectioneryDataModels.Models public interface IOrderModel : IId { int PastryId { get; } + int ClientId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/Confectionery/ConfectioneryDatabaseImplement/Order.cs b/Confectionery/ConfectioneryDatabaseImplement/Order.cs index 8bd0ea9..d5f3e6c 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Order.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Order.cs @@ -14,6 +14,10 @@ namespace ConfectioneryDatabaseImplement.Models public class Order : IOrderModel { public int Id { get; private set; } + [Required] + public int ClientId { get; private set; } + + public virtual Client Client { get; private set; } = new(); [Required] public int PastryId { get; private set; } @@ -39,6 +43,8 @@ namespace ConfectioneryDatabaseImplement.Models return new Order() { Id = model.Id, + ClientId = model.ClientId, + Client = context.Clients.First(x => x.Id == model.ClientId), PastryId = model.PastryId, Pastry = context.Pastrys.First(x => x.Id == model.PastryId), Count = model.Count, @@ -62,6 +68,8 @@ namespace ConfectioneryDatabaseImplement.Models public OrderViewModel GetViewModel => new() { Id = Id, + ClientId = ClientId, + ClientFIO = Client.ClientFIO, PastryId = PastryId, PastryName = Pastry.PastryName, Count = Count, diff --git a/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs b/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs index 1b26475..2372bb9 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs @@ -17,7 +17,7 @@ namespace ConfectioneryDatabaseImplement.Implements public List GetFullList() { using var context = new ConfectioneryDatabase(); - return context.Orders.Include(x => x.Pastry).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -27,6 +27,10 @@ namespace ConfectioneryDatabaseImplement.Implements { return context.Orders.Include(x => x.Pastry).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); } + if (model.ClientId.HasValue) + { + return context.Orders.Include(x => x.Pastry).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + } return context.Orders.Include(x => x.Pastry).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); }