diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index c7a3f78..8899a1e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -15,7 +15,9 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } - public int ManufactureId { get; set; } + public int ClientId { get; set; } + + public int ManufactureId { get; set; } [DisplayName("Изделие")] public string ManufactureName { get; set; } = string.Empty; @@ -34,5 +36,5 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } - } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index c36654a..a7de5a6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -13,6 +13,9 @@ namespace BlacksmithWorkshopDataModels.Models //id продукта int ManufactureId { get; } + //id клиента + int ClientId { get; } + //кол-во продуктов int Count { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs index cce5138..3b3022a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs @@ -22,47 +22,69 @@ namespace BlacksmithWorkshopFileImplement.Implements public List GetFullList() { - return source.Clients.Select(x => GetViewModel(x)).ToList(); + return source.Clients.Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(ClientSearchModel model) { - throw new NotImplementedException(); - } + return source.Clients.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } public ClientViewModel? GetElement(ClientSearchModel model) { - throw new NotImplementedException(); - } - - //для загрузки названий изделия в заказе - private ClientViewModel GetViewModel(Client client) - { - var viewModel = order.GetViewModel; - - var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == order.ManufactureId); - - if (manufacture != null) + if (!model.Id.HasValue) { - viewModel.ManufactureName = manufacture.ManufactureName; + return null; } - return viewModel; + return source.Clients.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public ClientViewModel? Insert(ClientBindingModel model) { - throw new NotImplementedException(); - } + model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1; + + var newClient = Client.Create(model); + + if (newClient == null) + { + return null; + } + + source.Clients.Add(newClient); + source.SaveClients(); + + return newClient.GetViewModel; + } public ClientViewModel? Update(ClientBindingModel model) { - throw new NotImplementedException(); - } + var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + + if (client == null) + { + return null; + } + + client.Update(model); + source.SaveClients(); + + return client.GetViewModel; + } public ClientViewModel? Delete(ClientBindingModel model) { - throw new NotImplementedException(); + var element = source.Clients.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Clients.Remove(element); + source.SaveClients(); + + return element.GetViewModel; + } + + return null; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index dbd7ffe..dc79c2c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -17,7 +17,9 @@ namespace BlacksmithWorkshopFileImplement.Models { public int Id { get; private set; } - public int ManufactureId { get; private set; } + public int ClientId { get; private set; } + + public int ManufactureId { get; private set; } public int Count { get; private set; } @@ -39,6 +41,7 @@ namespace BlacksmithWorkshopFileImplement.Models return new Order() { Id = model.Id, + ClientId = model.ClientId, ManufactureId = model.ManufactureId, Count = model.Count, Sum = model.Sum, @@ -58,7 +61,8 @@ namespace BlacksmithWorkshopFileImplement.Models return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value), + ClientId = Convert.ToInt32(element.Attribute("Id")!.Value), + ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -82,6 +86,7 @@ namespace BlacksmithWorkshopFileImplement.Models public OrderViewModel GetViewModel => new() { Id = Id, + ClientId = ClientId, ManufactureId = ManufactureId, Count = Count, Sum = Sum, @@ -90,14 +95,14 @@ namespace BlacksmithWorkshopFileImplement.Models DateImplement = DateImplement }; - public XElement GetXElement => new("Order", new XAttribute("Id", Id), - new XElement("ManufactureId", ManufactureId.ToString()), + new XElement("ClientId", ClientId.ToString()), + new XElement("ManufactureId", ManufactureId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString())); - } + } }