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(); }