diff --git a/ConfectionaryFileImplement/Order.cs b/ConfectionaryFileImplement/Order.cs index 8a00130..177a901 100644 --- a/ConfectionaryFileImplement/Order.cs +++ b/ConfectionaryFileImplement/Order.cs @@ -12,6 +12,9 @@ namespace ConfectioneryFileImplement.Models public int PastryId { get; private set; } + public int ClientId { get; set; } + + public int Count { get; private set; } public double Sum { get; private set; } @@ -31,6 +34,7 @@ namespace ConfectioneryFileImplement.Models return new Order() { PastryId = model.PastryId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -53,6 +57,7 @@ namespace ConfectioneryFileImplement.Models Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), PastryId = Convert.ToInt32(element.Element("PastryId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement), }; @@ -75,7 +80,9 @@ namespace ConfectioneryFileImplement.Models public OrderViewModel GetViewModel => new() { PastryName = DataFileSingleton.GetInstance().Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty, + ClientFIO = DataFileSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, PastryId = PastryId, + ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, @@ -86,6 +93,7 @@ namespace ConfectioneryFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("PastryId", PastryId), + new XElement("ClientId", ClientId), new XElement("Count", Count), new XElement("Sum", Sum.ToString()), new XElement("Status", (int)Status), diff --git a/ConfectionaryFileImplement/OrderStorage.cs b/ConfectionaryFileImplement/OrderStorage.cs index 3b3d169..266422d 100644 --- a/ConfectionaryFileImplement/OrderStorage.cs +++ b/ConfectionaryFileImplement/OrderStorage.cs @@ -44,6 +44,13 @@ namespace ConfectioneryFileImplement .Select(x => x.GetViewModel) .ToList(); } + if (!model.Id.HasValue && model.ClientId.HasValue) + { + return _source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } var result = GetElement(model); return result != null ? new() { result } : new(); } diff --git a/ConfectionaryListImplement/Order.cs b/ConfectionaryListImplement/Order.cs index a6e154f..9954ae8 100644 --- a/ConfectionaryListImplement/Order.cs +++ b/ConfectionaryListImplement/Order.cs @@ -11,6 +11,8 @@ namespace ConfectioneryListImplement.Models public int PastryId { get; private set; } + public int ClientId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -30,6 +32,7 @@ namespace ConfectioneryListImplement.Models return new Order() { PastryId = model.PastryId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -55,6 +58,8 @@ namespace ConfectioneryListImplement.Models public OrderViewModel GetViewModel => new() { PastryId = PastryId, + ClientFIO = DataListSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, diff --git a/ConfectionaryListImplement/OrderStorage.cs b/ConfectionaryListImplement/OrderStorage.cs index 6a47716..8b0558a 100644 --- a/ConfectionaryListImplement/OrderStorage.cs +++ b/ConfectionaryListImplement/OrderStorage.cs @@ -54,6 +54,13 @@ namespace ConfectioneryListImplement .Select(x => x.GetViewModel) .ToList(); } + if (!model.Id.HasValue && model.ClientId.HasValue) + { + return _source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } foreach (var order in _source.Orders) { if (order.Id == model.Id) diff --git a/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/ConfectioneryContracts/BindingModels/OrderBindingModel.cs index 0e3ce64..62eec79 100644 --- a/ConfectioneryContracts/BindingModels/OrderBindingModel.cs +++ b/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -7,6 +7,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/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/ConfectioneryContracts/SearchModels/OrderSearchModel.cs index ee7338e..2aaa9a2 100644 --- a/ConfectioneryContracts/SearchModels/OrderSearchModel.cs +++ b/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -7,5 +7,7 @@ public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + + public int? ClientId { get; set; } } } diff --git a/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/ConfectioneryContracts/ViewModels/OrderViewModel.cs index 1afadd8..32a6d71 100644 --- a/ConfectioneryContracts/ViewModels/OrderViewModel.cs +++ b/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -15,6 +15,11 @@ namespace ConfectioneryContracts.ViewModels public int Id { get; set; } public int PastryId { get; set; } + public int ClientId { get; set; } + + [DisplayName("Фамилия клиента")] + public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Изделие")] public string PastryName { get; set; } = string.Empty; diff --git a/ConfectioneryDataModels/IOrderModel.cs b/ConfectioneryDataModels/IOrderModel.cs index 01118fd..c168d51 100644 --- a/ConfectioneryDataModels/IOrderModel.cs +++ b/ConfectioneryDataModels/IOrderModel.cs @@ -5,6 +5,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/ConfectioneryDatabaseImplement/Order.cs b/ConfectioneryDatabaseImplement/Order.cs index 81c2c1f..4d1289b 100644 --- a/ConfectioneryDatabaseImplement/Order.cs +++ b/ConfectioneryDatabaseImplement/Order.cs @@ -21,6 +21,9 @@ namespace ConfectioneryDatabaseImplement.Models [Required] public int PastryId { get; private set; } + [Required] + public int ClientId { get; private set; } + [Required] public int Count { get; private set; } @@ -49,6 +52,7 @@ namespace ConfectioneryDatabaseImplement.Models return new Order() { PastryId = model.PastryId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -80,6 +84,7 @@ namespace ConfectioneryDatabaseImplement.Models return new() { PastryName = context.Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty, + ClientFIO = Client.ClientFIO, PastryId = PastryId, Count = Count, Sum = Sum, diff --git a/ConfectioneryDatabaseImplement/OrderStorage.cs b/ConfectioneryDatabaseImplement/OrderStorage.cs index 1a5433e..9192987 100644 --- a/ConfectioneryDatabaseImplement/OrderStorage.cs +++ b/ConfectioneryDatabaseImplement/OrderStorage.cs @@ -34,16 +34,27 @@ namespace ConfectioneryDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по айдишнику, значит ищем по диапазону дат + if (model.Id.HasValue) + { + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + using var context = new ConfectioneryDatabase(); + if (model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по айдишнику, значит ищем по диапазону дат { - using var context = new ConfectioneryDatabase(); return context.Orders .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); } - var result = GetElement(model); - return result != null ? new() { result } : new(); + if (model.ClientId.HasValue) + { + return context.Orders + .Where(x => x.Client.Id == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); } public List GetFullList()