From c2efaf95248f9509a49d8a4358ba9572f783f237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 2 May 2023 21:35:39 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8F=20=D0=B2=20listimplement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Implementer.cs | 8 ++ .../DataListSingleton.cs | 6 +- .../Implements/ImplementerStorage.cs | 119 ++++++++++++++++++ .../Implements/OrderStorage.cs | 46 ++++++- .../Models/Implementer.cs | 48 +++++++ .../Models/Order.cs | 15 ++- 6 files changed, 233 insertions(+), 9 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..929eb18 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs @@ -0,0 +1,8 @@ +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index 062f7e3..6625a94 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -9,13 +9,15 @@ namespace BlacksmithWorkshopListImplement public List Orders { get; set; } public List Manufactures { get; set; } public List Clients { get; set; } - private DataListSingleton() + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Manufactures = new List(); Clients = new List(); - } + Implementers = new List(); + } public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..261100d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,119 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var implementer in _source.Implementers) + { + if (model.Id.HasValue && implementer.Id == model.Id) + { + return implementer.GetViewModel; + } + if (model.ImplementerFIO != null && model.Password != null && implementer.ImplementerFIO.Equals(model.ImplementerFIO) && implementer.Password.Equals(model.Password)) + { + return implementer.GetViewModel; + } + if (model.ImplementerFIO != null && implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + return implementer.GetViewModel; + } + } + return null; + } + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + if (model.Id.HasValue) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + else + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO == model.ImplementerFIO) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index a84095f..162060f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -79,7 +79,22 @@ namespace BlacksmithWorkshopListImplement.Implements } } } - return result; + else if (model.Status.HasValue)//далее ищем по статусу + { + foreach (var order in _source.Orders) + { + if (order.Status == model.Status) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + result.Add(vm); + } + } + } + return result; } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -98,7 +113,34 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ClientFIO = client?.ClientFIO ?? string.Empty; return vm; } - } + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + return vm; + } + else if (model.ImplementerId.HasValue && !model.Status.HasValue) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + return vm; + } + else if (model.ImplementerId.HasValue && model.Status.HasValue) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + return vm; + } + } return null; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..15a429a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs @@ -0,0 +1,48 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; private set; } = string.Empty; + public int WorkExperience { get; private set; } + public int Qualification { get; private set; } + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 4d95925..c183499 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -16,9 +16,8 @@ namespace BlacksmithWorkshopListImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } public int ClientId { get; private set; } - //TODO - public int? ImplementerId => throw new NotImplementedException(); - public static Order? Create(OrderBindingModel? model) + public int? ImplementerId { get; private set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) { @@ -33,7 +32,8 @@ namespace BlacksmithWorkshopListImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId + ClientId = model.ClientId, + ImplementerId = model.ImplementerId }; } public void Update(OrderBindingModel? model) @@ -43,6 +43,10 @@ namespace BlacksmithWorkshopListImplement.Models return; } Status = model.Status; + if (model.ImplementerId != null) + { + ImplementerId = model.ImplementerId; + } if (model.DateImplement != null) { DateImplement = model.DateImplement; @@ -57,6 +61,7 @@ namespace BlacksmithWorkshopListImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - }; + ImplementerFIO = DataListSingleton.GetInstance().Implementers.SingleOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty + }; } } \ No newline at end of file -- 2.25.1 From da2318fda7b4c96e641053086b52c3c10ed91aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 2 May 2023 21:53:34 +0400 Subject: [PATCH 2/2] fileimplement --- .../DataFileSingleton.cs | 10 ++- .../Implements/ImplementerStorage.cs | 88 +++++++++++++++++++ .../Implements/OrderStorage.cs | 13 +-- .../Models/Implementer.cs | 65 +++++++++++++- .../Models/Order.cs | 19 ++-- .../Implements/OrderStorage.cs | 20 ++++- .../Models/Order.cs | 3 +- 7 files changed, 199 insertions(+), 19 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ImplementerStorage.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs index 4c631a2..ec51aa2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs @@ -9,10 +9,12 @@ namespace BlacksmithWorkshopFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string ManufactureFileName = "Manufacture.xml"; private readonly string ClientFileName = "Client.xml"; - public List Components { get; private set; } + private readonly string ImplementerFileName = "Implementer.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Manufactures { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -25,13 +27,15 @@ namespace BlacksmithWorkshopFileImplement public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName, "Manufactures", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); - private DataFileSingleton() + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementer", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; - } + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..47c1eba --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,88 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (!model.Id.HasValue && (string.IsNullOrEmpty(model.ImplementerFIO) || string.IsNullOrEmpty(model.Password))) + { + return new(); + } + if (model.Id.HasValue)//Сначала ищем по Id + { + return _source.Implementers + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + return _source.Implementers//Затем по логину и паролю + .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + if (model.Id.HasValue) + { + return _source.Implementers + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + return _source.Implementers + .Where(x => x.ImplementerFIO == model.ImplementerFIO) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index 3ab0d7b..c7755b6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -14,16 +14,17 @@ namespace BlacksmithWorkshopFileImplement.Implements { source = DataFileSingleton.GetInstance(); } - private OrderViewModel AddManufactureAndClientName (OrderViewModel model) + private OrderViewModel AddManufactureAndClientAndImplementerName (OrderViewModel model) { model.ManufactureName = source.Manufactures.SingleOrDefault(x => x.Id == model.ManufactureId)?.ManufactureName ?? string.Empty; model.ClientFIO = source.Clients.SingleOrDefault(x => x.Id == model.ClientId)?.ClientFIO ?? string.Empty; + model.ImplementerFIO = source.Implementers.SingleOrDefault(x => x.Id == model.ImplementerId)?.ImplementerFIO ?? string.Empty; return model; } public List GetFullList() { return source.Orders - .Select(x => AddManufactureAndClientName(x.GetViewModel)) + .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel)) .ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -36,21 +37,21 @@ namespace BlacksmithWorkshopFileImplement.Implements { return source.Orders .Where(x => x.Id == model.Id) - .Select(x => AddManufactureAndClientName(x.GetViewModel)) + .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel)) .ToList(); } else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если Id в модели нет, ищем по датам { return source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => AddManufactureAndClientName(x.GetViewModel)) + .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel)) .ToList(); } else if (model.ClientId.HasValue)//далее ищем по Id клиента { return source.Orders .Where(x => x.ClientId == model.ClientId) - .Select(x => AddManufactureAndClientName(x.GetViewModel)) + .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel)) .ToList(); } return new();//если нет ни того, ни другого, ни третьего, возвращаем пустой список @@ -66,7 +67,7 @@ namespace BlacksmithWorkshopFileImplement.Implements { return null; } - return AddManufactureAndClientName(order); + return AddManufactureAndClientAndImplementerName(order); } public OrderViewModel? Insert(OrderBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs index 929eb18..49b3d73 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs @@ -1,8 +1,71 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { public class Implementer : IImplementerModel { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; private set; } = string.Empty; + public int WorkExperience { get; private set; } + public int Qualification { get; private set; } + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index 1e1e0d5..55d50b4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -2,6 +2,7 @@ using BlacksmithWorkshopContracts.ViewModels; using BlacksmithWorkshopDataModels.Enums; using BlacksmithWorkshopDataModels.Models; +using System.Reflection; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models @@ -16,8 +17,7 @@ namespace BlacksmithWorkshopFileImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } public int ClientId { get; private set; } - //TODO - public int? ImplementerId => throw new NotImplementedException(); + public int? ImplementerId { get; set; } public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -33,8 +33,9 @@ namespace BlacksmithWorkshopFileImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId - }; + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, + }; } public static Order? Create(XElement element) { @@ -57,7 +58,8 @@ namespace BlacksmithWorkshopFileImplement.Models DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), DateImplement = dateImplement, ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - }; + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), + }; } public void Update(OrderBindingModel? model) { @@ -66,6 +68,10 @@ namespace BlacksmithWorkshopFileImplement.Models return; } Status = model.Status; + if (model.ImplementerId != null) + { + ImplementerId = model.ImplementerId; + } if (model.DateImplement != null) { DateImplement = model.DateImplement; @@ -91,7 +97,8 @@ namespace BlacksmithWorkshopFileImplement.Models new XElement("Status", (int)Status), new XElement("DateCreate", DateCreate), new XElement("DateImplement", DateImplement), - new XElement("ClientId", ClientId) + new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId) ); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 162060f..fc24ebd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -23,6 +23,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; result.Add(vm); } return result; @@ -45,6 +47,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; result.Add(vm); } } @@ -60,6 +64,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; result.Add(vm); } } @@ -75,6 +81,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; result.Add(vm); } } @@ -90,6 +98,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; result.Add(vm); } } @@ -111,7 +121,9 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; - return vm; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; + return vm; } else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) { @@ -120,6 +132,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; return vm; } else if (model.ImplementerId.HasValue && !model.Status.HasValue) @@ -129,6 +143,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; return vm; } else if (model.ImplementerId.HasValue && model.Status.HasValue) @@ -138,6 +154,8 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; var client = _source.Clients.Find(x => x.Id == order.ClientId); vm.ClientFIO = client?.ClientFIO ?? string.Empty; + var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId); + vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty; return vm; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index c183499..0817af2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -60,8 +60,7 @@ namespace BlacksmithWorkshopListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement, - ImplementerFIO = DataListSingleton.GetInstance().Implementers.SingleOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty + DateImplement = DateImplement }; } } \ No newline at end of file -- 2.25.1