From 6dc87a5d88acb9d586f65549f704e02b1ca556f4 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sat, 1 Apr 2023 21:00:22 +0400 Subject: [PATCH] order + client (file) --- .../Implements/OrderStorage.cs | 21 ++++++++++++++----- JewelryStoreFileImplement/Models/Order.cs | 6 ++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/JewelryStoreFileImplement/Implements/OrderStorage.cs b/JewelryStoreFileImplement/Implements/OrderStorage.cs index 1ad73b1..8e4cd3d 100644 --- a/JewelryStoreFileImplement/Implements/OrderStorage.cs +++ b/JewelryStoreFileImplement/Implements/OrderStorage.cs @@ -47,11 +47,22 @@ namespace JewelryStoreFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) - { - return new(); - } - return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); + if (model.DateFrom.HasValue) + return source.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + if (model.ClientId.HasValue && !model.Id.HasValue) + return source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + if (model.Id.HasValue) + return source.Orders + .Where(x => x.Id.Equals(model.Id)) + .Select(x => x.GetViewModel) + .ToList(); + return new(); } public List GetFullList() diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs index fc8fa48..627c3d0 100644 --- a/JewelryStoreFileImplement/Models/Order.cs +++ b/JewelryStoreFileImplement/Models/Order.cs @@ -5,6 +5,7 @@ using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -14,6 +15,7 @@ namespace JewelryStoreFileImplement.Models public class Order : IOrderModel { public int JewelId { get; private set; } + public int ClientId { get; private set; } public string JewelName { get; private set; } = string.Empty; @@ -40,6 +42,7 @@ namespace JewelryStoreFileImplement.Models Id = model.Id, JewelId = model.JewelId, JewelName = model.JewelName, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -59,6 +62,7 @@ namespace JewelryStoreFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), JewelId = Convert.ToInt32(element.Element("JewelId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), JewelName = element.Element("JewelName")!.Value, Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), @@ -91,6 +95,7 @@ namespace JewelryStoreFileImplement.Models { Id = Id, JewelId = JewelId, + ClientId = ClientId, JewelName = JewelName, Count = Count, Sum = Sum, @@ -103,6 +108,7 @@ namespace JewelryStoreFileImplement.Models new XAttribute("Id", Id), new XElement("JewelName", JewelName), new XElement("JewelId", JewelId.ToString()), + new XElement("ClientId", ClientId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()),