From 8a1e2acacbd1ee8297dd21994ec1e4202d4fad06 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 14:57:32 +0400 Subject: [PATCH 01/21] =?UTF-8?q?=D0=92=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar.sln | 14 ++- SushiBar/SushiBar/Program.cs | 2 +- SushiBar/SushiBar/SushiBarView.csproj | 1 + .../DataFileSingleton.cs | 53 +++++++++++ .../Implements/IngredientStorage.cs | 74 +++++++++++++++ .../Implements/OrderStorage.cs | 91 +++++++++++++++++++ .../Implements/SushiStorage.cs | 74 +++++++++++++++ .../Models/Ingredient.cs | 59 ++++++++++++ .../SushiBarFileImplement/Models/Order.cs | 84 +++++++++++++++++ .../SushiBarFileImplement/Models/Sushi.cs | 82 +++++++++++++++++ .../SushiBarFileImplement.csproj | 14 +++ 11 files changed, 543 insertions(+), 5 deletions(-) create mode 100644 SushiBar/SushiBarFileImplement/DataFileSingleton.cs create mode 100644 SushiBar/SushiBarFileImplement/Implements/IngredientStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/Ingredient.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/Order.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/Sushi.cs create mode 100644 SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj diff --git a/SushiBar/SushiBar.sln b/SushiBar/SushiBar.sln index d25d4a8..6fc6147 100644 --- a/SushiBar/SushiBar.sln +++ b/SushiBar/SushiBar.sln @@ -5,13 +5,15 @@ VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarView", "SushiBar\SushiBarView.csproj", "{021299FA-4932-4367-A9A7-378EB340D8BC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{8DD9F541-A4FA-4C0B-8E7D-8525C0D77E1C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{8DD9F541-A4FA-4C0B-8E7D-8525C0D77E1C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1B31E006-79D1-4376-AEEB-55AF60806AB1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1B31E006-79D1-4376-AEEB-55AF60806AB1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{2755BF17-8728-4D7E-A4EE-BC8810C508F6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{2755BF17-8728-4D7E-A4EE-BC8810C508F6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarListImplement", "SushiBarListImplement\SushiBarListImplement.csproj", "{81A91405-3721-40EF-A47C-CEBD92C0A4D0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarListImplement", "SushiBarListImplement\SushiBarListImplement.csproj", "{81A91405-3721-40EF-A47C-CEBD92C0A4D0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarFileImplement", "SushiBarFileImplement\SushiBarFileImplement.csproj", "{A26B0D9A-31CB-4845-ABC3-D84E60BECE46}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {81A91405-3721-40EF-A47C-CEBD92C0A4D0}.Debug|Any CPU.Build.0 = Debug|Any CPU {81A91405-3721-40EF-A47C-CEBD92C0A4D0}.Release|Any CPU.ActiveCfg = Release|Any CPU {81A91405-3721-40EF-A47C-CEBD92C0A4D0}.Release|Any CPU.Build.0 = Release|Any CPU + {A26B0D9A-31CB-4845-ABC3-D84E60BECE46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A26B0D9A-31CB-4845-ABC3-D84E60BECE46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A26B0D9A-31CB-4845-ABC3-D84E60BECE46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A26B0D9A-31CB-4845-ABC3-D84E60BECE46}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 07ff1b6..35f5754 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -4,7 +4,7 @@ using NLog.Extensions.Logging; using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; -using SushiBarListImplement.Implements; +using SushiBarFileImplement.Implements; using SushiBarView; namespace SushiBar diff --git a/SushiBar/SushiBar/SushiBarView.csproj b/SushiBar/SushiBar/SushiBarView.csproj index dceb0d9..237037b 100644 --- a/SushiBar/SushiBar/SushiBarView.csproj +++ b/SushiBar/SushiBar/SushiBarView.csproj @@ -17,6 +17,7 @@ + diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..7461a1d --- /dev/null +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -0,0 +1,53 @@ +using SushiBarFileImplement.Models; +using System.Xml.Linq; + +namespace SushiBarFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string IngredientFileName = "Ingredient.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string SushiFileName = "Sushi.xml"; + public List Ingredients { get; private set; } + public List Orders { get; private set; } + public List ListSushi { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveIngredients() => SaveData(Ingredients, IngredientFileName, + "Ingredients", x => x.GetXElement); + public void SaveListSushi() => SaveData(ListSushi, SushiFileName, + "ListSushi", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Ingredients = LoadData(IngredientFileName, "Ingredient", x => Ingredient.Create(x)!)!; + ListSushi = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, + Func selectFunction) + { + if (File.Exists(filename)) + { + return + XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string + xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarFileImplement/Implements/IngredientStorage.cs b/SushiBar/SushiBarFileImplement/Implements/IngredientStorage.cs new file mode 100644 index 0000000..5366cf1 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/IngredientStorage.cs @@ -0,0 +1,74 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; + +namespace SushiBarFileImplement.Implements +{ + public class IngredientStorage : IIngredientStorage + { + private readonly DataFileSingleton source; + public IngredientStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Ingredients.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(IngredientSearchModel model) + { + if (string.IsNullOrEmpty(model.IngredientName)) + { + return new(); + } + return source.Ingredients.Where(x => + x.IngredientName.Contains(model.IngredientName)).Select(x => x.GetViewModel).ToList(); + } + public IngredientViewModel? GetElement(IngredientSearchModel model) + { + if (string.IsNullOrEmpty(model.IngredientName) && !model.Id.HasValue) + { + return null; + } + return source.Ingredients.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.IngredientName) && x.IngredientName == + model.IngredientName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; + } + public IngredientViewModel? Insert(IngredientBindingModel model) + { + model.Id = source.Ingredients.Count > 0 ? source.Ingredients.Max(x => x.Id) + 1 : 1; + var newIngredient = Ingredient.Create(model); + if (newIngredient == null) + { + return null; + } + source.Ingredients.Add(newIngredient); + source.SaveIngredients(); + return newIngredient.GetViewModel; + } + public IngredientViewModel? Update(IngredientBindingModel model) + { + var ingredient = source.Ingredients.FirstOrDefault(x => x.Id == model.Id); + if (ingredient == null) + { + return null; + } + ingredient.Update(model); + source.SaveIngredients(); + return ingredient.GetViewModel; + } + public IngredientViewModel? Delete(IngredientBindingModel model) + { + var element = source.Ingredients.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Ingredients.Remove(element); + source.SaveIngredients(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..b2770d1 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,91 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; + +namespace SushiBarFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + return source.Orders.FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var sushi in _source.ListSushi) + { + if (sushi.Id == order.SushiId) + { + viewModel.SushiName = sushi.SushiName; + break; + } + } + return viewModel; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs new file mode 100644 index 0000000..a4a8add --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs @@ -0,0 +1,74 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; + +namespace SushiBarFileImplement.Implements +{ + public class SushiStorage : ISushiStorage + { + private readonly DataFileSingleton source; + public SushiStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.ListSushi.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(SushiSearchModel model) + { + if (string.IsNullOrEmpty(model.SushiName)) + { + return new(); + } + return source.ListSushi.Where(x => + x.SushiName.Contains(model.SushiName)).Select(x => x.GetViewModel).ToList(); + } + public SushiViewModel? GetElement(SushiSearchModel model) + { + if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue) + { + return null; + } + return source.ListSushi.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.SushiName) && x.SushiName == + model.SushiName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public SushiViewModel? Insert(SushiBindingModel model) + { + model.Id = source.ListSushi.Count > 0 ? source.ListSushi.Max(x => x.Id) + 1 : 1; + var newSushi = Sushi.Create(model); + if (newSushi == null) + { + return null; + } + source.ListSushi.Add(newSushi); + source.SaveListSushi(); + return newSushi.GetViewModel; + } + public SushiViewModel? Update(SushiBindingModel model) + { + var sushi = source.ListSushi.FirstOrDefault(x => x.Id == model.Id); + if (sushi == null) + { + return null; + } + sushi.Update(model); + source.SaveListSushi(); + return sushi.GetViewModel; + } + public SushiViewModel? Delete(SushiBindingModel model) + { + var element = source.ListSushi.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.ListSushi.Remove(element); + source.SaveListSushi(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/Ingredient.cs b/SushiBar/SushiBarFileImplement/Models/Ingredient.cs new file mode 100644 index 0000000..d940c5a --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Ingredient.cs @@ -0,0 +1,59 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + public class Ingredient : IIngredientModel + { + public int Id { get; private set; } + public string IngredientName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Ingredient? Create(IngredientBindingModel model) + { + if (model == null) + { + return null; + } + return new Ingredient() + { + Id = model.Id, + IngredientName = model.IngredientName, + Cost = model.Cost + }; + } + public static Ingredient? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Ingredient() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + IngredientName = element.Element("IngredientName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(IngredientBindingModel model) + { + if (model == null) + { + return; + } + IngredientName = model.IngredientName; + Cost = model.Cost; + } + public IngredientViewModel GetViewModel => new() + { + Id = Id, + IngredientName = IngredientName, + Cost = Cost + }; + public XElement GetXElement => new("Ingredient", + new XAttribute("Id", Id), + new XElement("IngredientName", IngredientName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs new file mode 100644 index 0000000..6431e5b --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -0,0 +1,84 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int SushiId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + SushiId = model.SushiId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = Convert.ToDateTime(element.Element("DateImplement")!.Value) + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + SushiId = SushiId, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("SushiId", SushiId), + 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())); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarFileImplement/Models/Sushi.cs b/SushiBar/SushiBarFileImplement/Models/Sushi.cs new file mode 100644 index 0000000..d697e76 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Sushi.cs @@ -0,0 +1,82 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + public class Sushi : ISushiModel + { + public int Id { get; private set; } + public string SushiName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Ingredients { get; private set; } = new(); + private Dictionary? _productIngredients = null; + public Dictionary SushiIngredients + { + get + { + if (_productIngredients == null) + { + var source = DataFileSingleton.GetInstance(); + _productIngredients = Ingredients.ToDictionary(x => x.Key, y => ((source.Ingredients.FirstOrDefault(z => z.Id == y.Key) as IIngredientModel)!, y.Value)); + } + return _productIngredients; + } + } + public static Sushi? Create(SushiBindingModel model) + { + if (model == null) + { + return null; + } + return new Sushi() + { + Id = model.Id, + SushiName = model.SushiName, + Price = model.Price, + Ingredients = model.SushiIngredients.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Sushi? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Sushi() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + SushiName = element.Element("SushiName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Ingredients = element.Element("SushiIngredients")!.Elements("SushiIngredient").ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(SushiBindingModel model) + { + if (model == null) + { + return; + } + SushiName = model.SushiName; + Price = model.Price; + Ingredients = model.SushiIngredients.ToDictionary(x => x.Key, x => + x.Value.Item2); + _productIngredients = null; + } + public SushiViewModel GetViewModel => new() + { + Id = Id, + SushiName = SushiName, + Price = Price, + SushiIngredients = SushiIngredients + }; + public XElement GetXElement => new("Sushi", + new XAttribute("Id", Id), + new XElement("SushiName", SushiName), + new XElement("Price", Price.ToString()), + new XElement("SushiIngredients", Ingredients.Select(x => new XElement("SushiIngredient", + new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj new file mode 100644 index 0000000..00e2c96 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + -- 2.25.1 From a8888dd285b64fdef2d44e1d1c589b61eb9795a9 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 15:29:29 +0400 Subject: [PATCH 02/21] =?UTF-8?q?=D0=9B=D0=A02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 12 ++++++------ SushiBar/SushiBarFileImplement/Models/Order.cs | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index b2770d1..0dbe30a 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -16,7 +16,7 @@ namespace SushiBarFileImplement.Implements public List GetFullList() { - return source.Orders.Select(x => x.GetViewModel).ToList(); + return source.Orders.Select(x => GetViewModel(x)).ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -25,7 +25,7 @@ namespace SushiBarFileImplement.Implements { return new(); } - return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => x.GetViewModel).ToList(); + return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -41,7 +41,7 @@ namespace SushiBarFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var sushi in _source.ListSushi) + foreach (var sushi in source.ListSushi) { if (sushi.Id == order.SushiId) { @@ -61,7 +61,7 @@ namespace SushiBarFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -73,7 +73,7 @@ namespace SushiBarFileImplement.Implements } order.Update(model); source.SaveOrders(); - return order.GetViewModel; + return GetViewModel(order); } public OrderViewModel? Delete(OrderBindingModel model) @@ -83,7 +83,7 @@ namespace SushiBarFileImplement.Implements { source.Orders.Remove(element); source.SaveOrders(); - return element.GetViewModel; + return GetViewModel(element); } return null; } diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index 6431e5b..6d1f581 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -39,16 +39,23 @@ namespace SushiBarFileImplement.Models { return null; } - return new Order() + var order = new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), - Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), - Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), - DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = Convert.ToDateTime(element.Element("DateImplement")!.Value) + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), }; + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + order.DateImplement = dateImpl; + + if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) + { + return null; + } + order.Status = status; + return order; } public void Update(OrderBindingModel? model) -- 2.25.1 From b91edc375c284288c5f45bc3db87ea92814f6dc6 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 16:00:47 +0400 Subject: [PATCH 03/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarFileImplement/Models/Order.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index 6d1f581..3f8160b 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -39,23 +39,16 @@ namespace SushiBarFileImplement.Models { return null; } - var order = new Order() + return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), - Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), - DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) }; - DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); - order.DateImplement = dateImpl; - - if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) - { - return null; - } - order.Status = status; - return order; } public void Update(OrderBindingModel? model) -- 2.25.1 From e378dbb4e99a62244895e7ff1040ce849af891ff Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 16:27:41 +0400 Subject: [PATCH 04/21] =?UTF-8?q?=D0=9B=D0=A02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index f38dd3a..6d5e99a 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -4,7 +4,7 @@ using NLog.Extensions.Logging; using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; -using SushiBarListImplement.Implements; +using SushiBarFileImplement.Implements; namespace SushiBarView { -- 2.25.1 From 863deea9872df65ad92db59e31f4bdf351665be1 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Feb 2023 11:36:38 +0400 Subject: [PATCH 05/21] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B5=D0=B3=D0=BE=20usi?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormIngredients.cs | 1 - SushiBar/SushiBar/FormListSushi.cs | 1 - SushiBar/SushiBar/FormMain.cs | 1 - SushiBar/SushiBar/FormSushi.cs | 1 - 4 files changed, 4 deletions(-) diff --git a/SushiBar/SushiBar/FormIngredients.cs b/SushiBar/SushiBar/FormIngredients.cs index 73d7cfa..781205f 100644 --- a/SushiBar/SushiBar/FormIngredients.cs +++ b/SushiBar/SushiBar/FormIngredients.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; diff --git a/SushiBar/SushiBar/FormListSushi.cs b/SushiBar/SushiBar/FormListSushi.cs index 333b51c..d20376b 100644 --- a/SushiBar/SushiBar/FormListSushi.cs +++ b/SushiBar/SushiBar/FormListSushi.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 4ea5668..a9b93ee 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarDataModels.Enums; diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 67496b1..515011f 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; -- 2.25.1 From 9d5759527ee98fd35262f7b16d89b57f9f891e90 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 4 Mar 2023 10:34:01 +0400 Subject: [PATCH 06/21] =?UTF-8?q?=D0=94=D0=BE=D1=84=D0=B8=D0=B3=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=D0=B3=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=D0=B0,=20=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=D0=B0=20=D1=83?= =?UTF-8?q?=D0=B6=D0=B5=20=D1=87=D1=82=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0(=D0=BA=D0=BE=D1=80=D0=BE=D1=87=D0=B5=20?= =?UTF-8?q?=D1=83=20=D0=BC=D0=B5=D0=BD=D1=8F=20=D0=B1=D1=8B=D0=BB=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=D0=BE=D0=B9-=D1=82=D0=BE=20=D0=BF=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=20=D0=B8=20=D1=8F=20=D0=B5=D0=B3=D0=BE=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=B4=D0=B5=D1=80=D0=B6=D0=B8=D0=B2=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.Designer.cs | 38 ++++-- SushiBar/SushiBar/FormMain.cs | 10 ++ SushiBar/SushiBar/FormSellSushi.Designer.cs | 126 ++++++++++++++++++ SushiBar/SushiBar/FormSellSushi.cs | 90 +++++++++++++ SushiBar/SushiBar/FormSellSushi.resx | 60 +++++++++ SushiBar/SushiBar/FormShop.Designer.cs | 64 ++++++--- SushiBar/SushiBar/FormShop.cs | 4 +- SushiBar/SushiBar/Program.cs | 1 + SushiBar/SushiBar/SushiBarView.csproj | 1 - .../BusinessLogics/OrderLogic.cs | 20 ++- .../BusinessLogics/ShopLogic.cs | 62 ++++++++- .../BindingModels/ShopBindingModel.cs | 2 + .../BusinessLogicsContracts/IShopLogic.cs | 2 + .../StoragesContracts/IShopStorage.cs | 3 + .../StoragesContracts/ISushiStorage.cs | 3 + .../ViewModels/ShopViewModel.cs | 2 + .../SushiBarDataModels/Models/IShopModel.cs | 1 + .../DataFileSingleton.cs | 4 + .../Implements/ShopStorage.cs | 109 +++++++++++++++ .../Implements/SushiStorage.cs | 37 +++++ SushiBar/SushiBarFileImplement/Models/Shop.cs | 107 +++++++++++++++ .../DataListSingleton.cs | 4 +- .../Implements/IngredientStorage.cs | 4 +- .../Implements/OrderStorage.cs | 4 +- .../Implements/ShopStorage.cs | 15 ++- .../Implements/SushiStorage.cs | 15 ++- .../Models/Ingredient.cs | 2 +- .../SushiBarListImplement/Models/Order.cs | 2 +- SushiBar/SushiBarListImplement/Models/Shop.cs | 4 +- .../SushiBarListImplement/Models/Sushi.cs | 2 +- 30 files changed, 746 insertions(+), 52 deletions(-) create mode 100644 SushiBar/SushiBar/FormSellSushi.Designer.cs create mode 100644 SushiBar/SushiBar/FormSellSushi.cs create mode 100644 SushiBar/SushiBar/FormSellSushi.resx create mode 100644 SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/Shop.cs diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index c1af807..c92d394 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -40,6 +40,7 @@ this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonAddSushiInShop = new System.Windows.Forms.Button(); + this.buttonSellSushi = new System.Windows.Forms.Button(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -87,10 +88,10 @@ // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(781, 299); + this.buttonUpdate.Location = new System.Drawing.Point(778, 237); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(170, 58); + this.buttonUpdate.Size = new System.Drawing.Size(170, 62); this.buttonUpdate.TabIndex = 12; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; @@ -98,10 +99,10 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(781, 237); + this.buttonSetToFinish.Location = new System.Drawing.Point(778, 171); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; - this.buttonSetToFinish.Size = new System.Drawing.Size(170, 58); + this.buttonSetToFinish.Size = new System.Drawing.Size(170, 62); this.buttonSetToFinish.TabIndex = 11; this.buttonSetToFinish.Text = "Заказ выдан"; this.buttonSetToFinish.UseVisualStyleBackColor = true; @@ -109,10 +110,10 @@ // // buttonSetToDone // - this.buttonSetToDone.Location = new System.Drawing.Point(781, 175); + this.buttonSetToDone.Location = new System.Drawing.Point(778, 179); this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToDone.Name = "buttonSetToDone"; - this.buttonSetToDone.Size = new System.Drawing.Size(170, 58); + this.buttonSetToDone.Size = new System.Drawing.Size(170, 62); this.buttonSetToDone.TabIndex = 10; this.buttonSetToDone.Text = "Заказ готов"; this.buttonSetToDone.UseVisualStyleBackColor = true; @@ -120,10 +121,10 @@ // // buttonSetToWork // - this.buttonSetToWork.Location = new System.Drawing.Point(781, 113); + this.buttonSetToWork.Location = new System.Drawing.Point(778, 104); this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToWork.Name = "buttonSetToWork"; - this.buttonSetToWork.Size = new System.Drawing.Size(170, 58); + this.buttonSetToWork.Size = new System.Drawing.Size(170, 62); this.buttonSetToWork.TabIndex = 9; this.buttonSetToWork.Text = "Отдать на выполнение"; this.buttonSetToWork.UseVisualStyleBackColor = true; @@ -131,10 +132,10 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(781, 51); + this.buttonCreateOrder.Location = new System.Drawing.Point(778, 38); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(170, 58); + this.buttonCreateOrder.Size = new System.Drawing.Size(170, 62); this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; @@ -154,20 +155,32 @@ // // buttonAddSushiInShop // - this.buttonAddSushiInShop.Location = new System.Drawing.Point(781, 361); + this.buttonAddSushiInShop.Location = new System.Drawing.Point(778, 302); this.buttonAddSushiInShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonAddSushiInShop.Name = "buttonAddSushiInShop"; - this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 58); + this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 62); this.buttonAddSushiInShop.TabIndex = 13; this.buttonAddSushiInShop.Text = "Добавить суши в магазин"; this.buttonAddSushiInShop.UseVisualStyleBackColor = true; this.buttonAddSushiInShop.Click += new System.EventHandler(this.ButtonAddSushiInShop_Click); // + // buttonSellSushi + // + this.buttonSellSushi.Location = new System.Drawing.Point(778, 367); + this.buttonSellSushi.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSellSushi.Name = "buttonSellSushi"; + this.buttonSellSushi.Size = new System.Drawing.Size(170, 62); + this.buttonSellSushi.TabIndex = 14; + this.buttonSellSushi.Text = "Продать суши"; + this.buttonSellSushi.UseVisualStyleBackColor = true; + this.buttonSellSushi.Click += new System.EventHandler(this.ButtonSellSushi_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(975, 450); + this.Controls.Add(this.buttonSellSushi); this.Controls.Add(this.buttonAddSushiInShop); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); @@ -202,5 +215,6 @@ private DataGridView dataGridView; private ToolStripMenuItem shopsToolStripMenuItem; private Button buttonAddSushiInShop; + private Button buttonSellSushi; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index cf0fa99..7bac443 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -160,5 +160,15 @@ namespace SushiBarView form.ShowDialog(); } } + + private void ButtonSellSushi_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellSushi)); + if (service is FormSellSushi form) + { + form.ShowDialog(); + LoadData(); + } + } } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSellSushi.Designer.cs b/SushiBar/SushiBar/FormSellSushi.Designer.cs new file mode 100644 index 0000000..745456b --- /dev/null +++ b/SushiBar/SushiBar/FormSellSushi.Designer.cs @@ -0,0 +1,126 @@ +namespace SushiBarView +{ + partial class FormSellSushi + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelSushi = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelSushi + // + this.labelSushi.AutoSize = true; + this.labelSushi.Location = new System.Drawing.Point(9, 11); + this.labelSushi.Name = "labelSushi"; + this.labelSushi.Size = new System.Drawing.Size(39, 15); + this.labelSushi.TabIndex = 0; + this.labelSushi.Text = "Суши"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(11, 51); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество"; + // + // comboBoxSushi + // + this.comboBoxSushi.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(100, 11); + this.comboBoxSushi.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(230, 23); + this.comboBoxSushi.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(100, 51); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 4; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(160, 78); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(248, 78); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellSushi + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(349, 119); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelSushi); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormSellSushi"; + this.Text = "Продажа суши"; + this.Load += new System.EventHandler(this.FormSellSushi_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelSushi; + private Label labelCount; + private ComboBox comboBoxSushi; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSellSushi.cs b/SushiBar/SushiBar/FormSellSushi.cs new file mode 100644 index 0000000..b985fe7 --- /dev/null +++ b/SushiBar/SushiBar/FormSellSushi.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormSellSushi : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicSushi; + private readonly IShopLogic _logicShop; + + public FormSellSushi(ILogger logger, ISushiLogic logicI, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicSushi = logicI; + _logicShop = logicS; + } + + private void FormSellSushi_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка суши для продажи"); + try + { + var list = _logicSushi.ReadList(null); + if (list != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = list; + comboBoxSushi.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле 'Количество'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите суши", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа суши"); + try + { + var operationResult = _logicShop.SellSushi(_logicSushi.ReadElement(new SushiSearchModel() + { + Id = Convert.ToInt32(comboBoxSushi.SelectedValue) + })!, Convert.ToInt32(textBoxCount.Text)); + if (!operationResult) + { + throw new Exception("Ошибка при продаже суши. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка продажи суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBar/FormSellSushi.resx b/SushiBar/SushiBar/FormSellSushi.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormSellSushi.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormShop.Designer.cs b/SushiBar/SushiBar/FormShop.Designer.cs index 71971de..62944f2 100644 --- a/SushiBar/SushiBar/FormShop.Designer.cs +++ b/SushiBar/SushiBar/FormShop.Designer.cs @@ -34,13 +34,16 @@ this.labelTime = new System.Windows.Forms.Label(); this.labelAddress = new System.Windows.Forms.Label(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.labelShop = new System.Windows.Forms.Label(); - this.textBoxShop = new System.Windows.Forms.TextBox(); - this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnSushiName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.labelShop = new System.Windows.Forms.Label(); + this.textBoxShop = new System.Windows.Forms.TextBox(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.labelCount = new System.Windows.Forms.Label(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); this.SuspendLayout(); // // buttonSave @@ -69,13 +72,13 @@ // this.textBoxAddress.Location = new System.Drawing.Point(159, 27); this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.Size = new System.Drawing.Size(141, 23); this.textBoxAddress.TabIndex = 14; // // labelTime // this.labelTime.AutoSize = true; - this.labelTime.Location = new System.Drawing.Point(386, 9); + this.labelTime.Location = new System.Drawing.Point(306, 9); this.labelTime.Name = "labelTime"; this.labelTime.Size = new System.Drawing.Size(87, 15); this.labelTime.TabIndex = 13; @@ -106,6 +109,23 @@ this.dataGridView.Size = new System.Drawing.Size(581, 240); this.dataGridView.TabIndex = 11; // + // ColumnID + // + this.ColumnID.HeaderText = "ID"; + this.ColumnID.Name = "ColumnID"; + this.ColumnID.Visible = false; + // + // ColumnSushiName + // + this.ColumnSushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnSushiName.HeaderText = "Суши"; + this.ColumnSushiName.Name = "ColumnSushiName"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + // // labelShop // this.labelShop.AutoSize = true; @@ -124,33 +144,34 @@ // // dateTimePicker // - this.dateTimePicker.Location = new System.Drawing.Point(386, 27); + this.dateTimePicker.Location = new System.Drawing.Point(306, 27); this.dateTimePicker.Name = "dateTimePicker"; - this.dateTimePicker.Size = new System.Drawing.Size(207, 23); + this.dateTimePicker.Size = new System.Drawing.Size(141, 23); this.dateTimePicker.TabIndex = 19; // - // ColumnID + // labelCount // - this.ColumnID.HeaderText = "ID"; - this.ColumnID.Name = "ColumnID"; - this.ColumnID.Visible = false; + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(453, 9); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(134, 15); + this.labelCount.TabIndex = 20; + this.labelCount.Text = "Вместимость магазина"; // - // ColumnSushiName + // numericUpDownCount // - this.ColumnSushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ColumnSushiName.HeaderText = "Суши"; - this.ColumnSushiName.Name = "ColumnSushiName"; - // - // ColumnCount - // - this.ColumnCount.HeaderText = "Количество"; - this.ColumnCount.Name = "ColumnCount"; + this.numericUpDownCount.Location = new System.Drawing.Point(453, 27); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(140, 23); + this.numericUpDownCount.TabIndex = 21; // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(605, 337); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.labelCount); this.Controls.Add(this.dateTimePicker); this.Controls.Add(this.textBoxShop); this.Controls.Add(this.buttonSave); @@ -165,6 +186,7 @@ this.Load += new System.EventHandler(this.FormShop_Load); this.Click += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -184,5 +206,7 @@ private DataGridViewTextBoxColumn ColumnID; private DataGridViewTextBoxColumn ColumnSushiName; private DataGridViewTextBoxColumn ColumnCount; + private Label labelCount; + private NumericUpDown numericUpDownCount; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormShop.cs b/SushiBar/SushiBar/FormShop.cs index c97776f..332b18d 100644 --- a/SushiBar/SushiBar/FormShop.cs +++ b/SushiBar/SushiBar/FormShop.cs @@ -39,6 +39,7 @@ namespace SushiBarView textBoxShop.Text = view.ShopName; textBoxAddress.Text = view.Address; dateTimePicker.Text = view.DateOpening.ToString(); + numericUpDownCount.Value = view.MaxCountSushi; _shopListSushi = view.ListSushi ?? new Dictionary(); LoadData(); } @@ -93,7 +94,8 @@ namespace SushiBarView Id = _id ?? 0, ShopName = textBoxShop.Text, Address = textBoxAddress.Text, - DateOpening = dateTimePicker.Value.Date + DateOpening = dateTimePicker.Value.Date, + MaxCountSushi = (int)numericUpDownCount.Value }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index bedf854..781349c 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -54,6 +54,7 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/SushiBar/SushiBar/SushiBarView.csproj b/SushiBar/SushiBar/SushiBarView.csproj index 237037b..5ef3c81 100644 --- a/SushiBar/SushiBar/SushiBarView.csproj +++ b/SushiBar/SushiBar/SushiBarView.csproj @@ -18,7 +18,6 @@ - \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 3baee63..139f769 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -12,11 +12,15 @@ namespace SushiBarBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; + private readonly ISushiStorage _sushiStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, ISushiStorage sushiStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _sushiStorage = sushiStorage; } public List? ReadList(OrderSearchModel? model) { @@ -86,7 +90,19 @@ namespace SushiBarBusinessLogic.BusinessLogics return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + var sushi = _sushiStorage.GetElement(new() { Id = viewModel.SushiId }); + if (sushi == null) + { + throw new ArgumentNullException(nameof(sushi)); + } + if (!_shopLogic.AddSushi(sushi, viewModel.Count)) + { + throw new Exception($"AddSushis operation failed. Shop is full."); + } + } else { model.DateImplement = viewModel.DateImplement; diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index bb6147e..16156ed 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -6,7 +6,7 @@ using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace SushiBusinessLogic +namespace SushiBarBusinessLogic.BusinessLogics { public class ShopLogic : IShopLogic { @@ -93,6 +93,12 @@ namespace SushiBusinessLogic { throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); } + if (model.MaxCountSushi < 0) + { + throw new ArgumentException( + "Максимальное количество суши в магазине не может быть меньше нуля", + nameof(model.MaxCountSushi)); + } _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", model.ShopName, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel @@ -123,6 +129,11 @@ namespace SushiBusinessLogic _logger.LogWarning("AddSushiInShop element not found"); return false; } + if (element.MaxCountSushi - + element.ListSushi.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("Магазин переполнен", nameof(count)); + } _logger.LogInformation("AddSushiInShop find. Id:{Id}", element.Id); if (element.ListSushi.TryGetValue(sushi.Id, out var pair)) @@ -144,9 +155,56 @@ namespace SushiBusinessLogic Address = element.Address, ShopName = element.ShopName, DateOpening = element.DateOpening, - ListSushi = element.ListSushi + MaxCountSushi = element.MaxCountSushi, + ListSushi = element.ListSushi, }); return true; } + + public bool AddSushi(ISushiModel model, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество суши должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddSushi. ShopName:{ShopName}. Id:{Id}", model.SushiName, model.Id); + foreach (var shop in _shopStorage.GetFullList()) + { + int free = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum(); + if (free < count) + { + if (!AddSushiInShop(new() { Id = shop.Id }, model, free)) + { + _logger.LogWarning("AddSushi operation failed."); + return false; + } + count -= free; + } + else + { + if (!AddSushiInShop(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddSushiInShop operation failed."); + return false; + } + count = 0; + } + if (count == 0) + { + return true; + } + } + _logger.LogWarning("AddSushi operation failed."); + return false; + } + + public bool SellSushi(ISushiModel model, int count) + { + return _shopStorage.SellSushi(model, count); + } } } diff --git a/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs index 006a3eb..c3ddb34 100644 --- a/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs @@ -16,5 +16,7 @@ namespace SushiBarContracts.BindingModels get; set; } = new(); + + public int MaxCountSushi { get; set; } } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs index f1f455b..230c941 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs @@ -13,5 +13,7 @@ namespace SushiBarContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count); + bool AddSushi(ISushiModel sushi, int count); + bool SellSushi(ISushiModel sushi, int count); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs index 8ebaaf5..0028fe5 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; namespace SushiBarContracts.StoragesContracts { @@ -12,5 +13,7 @@ namespace SushiBarContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool IsEnoughSushi(ISushiModel model, int count); + bool SellSushi(ISushiModel model, int count); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs index ff49391..f968fb1 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -1,6 +1,7 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; namespace SushiBarContracts.StoragesContracts { @@ -12,5 +13,7 @@ namespace SushiBarContracts.StoragesContracts SushiViewModel? Insert(SushiBindingModel model); SushiViewModel? Update(SushiBindingModel model); SushiViewModel? Delete(SushiBindingModel model); + bool HasSushi(ISushiModel model, int needCount); + bool SellSushi(ISushiModel model, int count); } } diff --git a/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs index f53c548..79620ca 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -14,6 +14,8 @@ namespace SushiBarContracts.ViewModels [DisplayName("Дата открытия")] public DateTime DateOpening { get; set; } = DateTime.Now; + [DisplayName("Максимальное количество суши")] + public int MaxCountSushi { get; set; } public Dictionary ListSushi { diff --git a/SushiBar/SushiBarDataModels/Models/IShopModel.cs b/SushiBar/SushiBarDataModels/Models/IShopModel.cs index 2c7c569..648784e 100644 --- a/SushiBar/SushiBarDataModels/Models/IShopModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IShopModel.cs @@ -6,5 +6,6 @@ string Address { get; } DateTime DateOpening { get; } Dictionary ListSushi { get; } + int MaxCountSushi { get; } } } diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index 7461a1d..cf30335 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ namespace SushiBarFileImplement private readonly string IngredientFileName = "Ingredient.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string SushiFileName = "Sushi.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Ingredients { get; private set; } public List Orders { get; private set; } public List ListSushi { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -25,11 +27,13 @@ namespace SushiBarFileImplement public void SaveListSushi() => SaveData(ListSushi, SushiFileName, "ListSushi", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Ingredients = LoadData(IngredientFileName, "Ingredient", x => Ingredient.Create(x)!)!; ListSushi = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..0e1161f --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,109 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using SushiBarFileImplement.Models; + +namespace SushiBarFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops.Where(x => + x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == + model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + public bool IsEnoughSushi(ISushiModel model, int count) + { + int temp = source.Shops + .Select(x => x.ListSushi.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum(); + return temp >= count; + } + + public bool SellSushi(ISushiModel model, int count) + { + if (!IsEnoughSushi(model, count)) + { + return false; + } + foreach (var shop in source.Shops.Where(x => x.ListSushi.ContainsKey(model.Id))) + { + int countInCurrentShop = shop.ListSushi[model.Id].Item2; + if (countInCurrentShop <= count) + { + shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, 0); + count -= countInCurrentShop; + } + else + { + shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, countInCurrentShop - count); + count = 0; + } + if (count == 0) + { + return true; + } + } + return false; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs index a4a8add..04399ba 100644 --- a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs @@ -2,7 +2,9 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; using SushiBarFileImplement.Models; +using System.Reflection; namespace SushiBarFileImplement.Implements { @@ -70,5 +72,40 @@ namespace SushiBarFileImplement.Implements } return null; } + public bool HasSushi(ISushiModel sushi, int needCount) + { + var temp = source.Shops + .Select(x => x.ListSushi + .FirstOrDefault(x => x.Key == sushi.Id).Value.Item2).Sum(); + return temp >= needCount; + } + + public bool SellSushi(ISushiModel model, int count) + { + if (!HasSushi(model, count)) + { + return false; + } + + foreach (var shop in source.Shops.Where(x => x.ListSushi.ContainsKey(model.Id))) + { + if (shop.ListSushi[model.Id].Item2 < count) + { + shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, 0); + count -= shop.ListSushi[model.Id].Item2; + } + else + { + shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, + shop.ListSushi[model.Id].Item2 - count); + count -= count; + } + if (count <= 0) + { + return true; + } + } + return true; + } } } diff --git a/SushiBar/SushiBarFileImplement/Models/Shop.cs b/SushiBar/SushiBarFileImplement/Models/Shop.cs new file mode 100644 index 0000000..fb4a66a --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Shop.cs @@ -0,0 +1,107 @@ + +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System.Reflection.Metadata; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime DateOpening { get; private set; } + public int MaxCountSushi { get; private set; } + public Dictionary CountSushi + { + get; + private set; + } = new(); + + private Dictionary? _shopSushi = null; + public Dictionary ListSushi + { + get + { + if (_shopSushi == null) + { + var source = DataFileSingleton.GetInstance(); + _shopSushi = + CountSushi.ToDictionary(x => x.Key, + y => ((source.ListSushi.FirstOrDefault(z => z.Id == y.Key) as ISushiModel)!, y.Value)); + } + return _shopSushi; + } + } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + MaxCountSushi = model.MaxCountSushi, + DateOpening = model.DateOpening, + CountSushi = model.ListSushi.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + MaxCountSushi = Convert.ToInt32(element.Element("MaxCountSushi")!.Value), + CountSushi = element.Element("ListSushi")!.Elements("Sushi").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + MaxCountSushi = model.MaxCountSushi; + CountSushi = model.ListSushi.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopSushi = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + ListSushi = ListSushi, + DateOpening = DateOpening, + MaxCountSushi = MaxCountSushi, + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening), + new XElement("MaxCountSushi", MaxCountSushi), + new XElement("ListSushi", CountSushi + .Select(x => new XElement("Sushi", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + ).ToArray())); + } +} diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index 04beee0..f398fdd 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -1,6 +1,6 @@ -using SushiBarListImplement.Models; +using SushiBarFileImplement.Models; -namespace SushiBarListImplement +namespace SushiBarFileImplement { public class DataListSingleton { diff --git a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs index 92a771b..0ee51d8 100644 --- a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs @@ -2,9 +2,9 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarListImplement.Models; +using SushiBarFileImplement.Models; -namespace SushiBarListImplement.Implements +namespace SushiBarFileImplement.Implements { public class IngredientStorage : IIngredientStorage { diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs index 3254155..dedc1f8 100644 --- a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -2,9 +2,9 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarListImplement.Models; +using SushiBarFileImplement.Models; -namespace SushiBarListImplement.Implements +namespace SushiBarFileImplement.Implements { public class OrderStorage : IOrderStorage { diff --git a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs index a36aef1..e5fff04 100644 --- a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs @@ -2,9 +2,10 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarListImplement.Models; +using SushiBarDataModels.Models; +using SushiBarFileImplement.Models; -namespace SushiBarListImplement.Implements +namespace SushiBarFileImplement.Implements { public class ShopStorage : IShopStorage { @@ -98,5 +99,15 @@ namespace SushiBarListImplement.Implements } return null; } + + public bool IsEnoughSushi(ISushiModel model, int count) + { + throw new NotImplementedException(); + } + + public bool SellSushi(ISushiModel model, int count) + { + throw new NotImplementedException(); + } } } diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index d2878ca..c65caf2 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -2,9 +2,10 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarListImplement.Models; +using SushiBarDataModels.Models; +using SushiBarFileImplement.Models; -namespace SushiBarListImplement.Implements +namespace SushiBarFileImplement.Implements { public class SushiStorage : ISushiStorage { @@ -98,5 +99,15 @@ namespace SushiBarListImplement.Implements } return null; } + + public bool HasSushi(ISushiModel model, int needCount) + { + throw new NotImplementedException(); + } + + public bool SellSushi(ISushiModel model, int count) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/Models/Ingredient.cs b/SushiBar/SushiBarListImplement/Models/Ingredient.cs index 2f61296..01a2271 100644 --- a/SushiBar/SushiBarListImplement/Models/Ingredient.cs +++ b/SushiBar/SushiBarListImplement/Models/Ingredient.cs @@ -2,7 +2,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace SushiBarListImplement.Models +namespace SushiBarFileImplement.Models { public class Ingredient : IIngredientModel { diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 445b162..81908bf 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -3,7 +3,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; -namespace SushiBarListImplement.Models +namespace SushiBarFileImplement.Models { public class Order : IOrderModel { diff --git a/SushiBar/SushiBarListImplement/Models/Shop.cs b/SushiBar/SushiBarListImplement/Models/Shop.cs index abbecfc..b27761d 100644 --- a/SushiBar/SushiBarListImplement/Models/Shop.cs +++ b/SushiBar/SushiBarListImplement/Models/Shop.cs @@ -2,7 +2,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace SushiBarListImplement.Models +namespace SushiBarFileImplement.Models { public class Shop : IShopModel { @@ -49,5 +49,7 @@ namespace SushiBarListImplement.Models ListSushi = ListSushi, DateOpening = DateOpening, }; + + public int MaxCountSushi => throw new NotImplementedException(); } } diff --git a/SushiBar/SushiBarListImplement/Models/Sushi.cs b/SushiBar/SushiBarListImplement/Models/Sushi.cs index 3a589e8..1ae291c 100644 --- a/SushiBar/SushiBarListImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarListImplement/Models/Sushi.cs @@ -2,7 +2,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace SushiBarListImplement.Models +namespace SushiBarFileImplement.Models { public class Sushi : ISushiModel { -- 2.25.1 From 5939957007cc0089ad7ca6f017a4c1510e5dc3f5 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 4 Mar 2023 10:34:01 +0400 Subject: [PATCH 07/21] =?UTF-8?q?=D0=94=D0=BE=D1=84=D0=B8=D0=B3=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=D0=B3=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=D0=B0,=20=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=D0=B0=20=D1=83?= =?UTF-8?q?=D0=B6=D0=B5=20=D1=87=D1=82=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0(=D0=BA=D0=BE=D1=80=D0=BE=D1=87=D0=B5=20?= =?UTF-8?q?=D1=83=20=D0=BC=D0=B5=D0=BD=D1=8F=20=D0=B1=D1=8B=D0=BB=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=D0=BE=D0=B9-=D1=82=D0=BE=20=D0=BF=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=20=D0=B8=20=D1=8F=20=D0=B5=D0=B3=D0=BE=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=B4=D0=B5=D1=80=D0=B6=D0=B8=D0=B2=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormSellSushi.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SushiBar/SushiBar/FormSellSushi.cs b/SushiBar/SushiBar/FormSellSushi.cs index b985fe7..d1b4354 100644 --- a/SushiBar/SushiBar/FormSellSushi.cs +++ b/SushiBar/SushiBar/FormSellSushi.cs @@ -19,12 +19,12 @@ namespace SushiBarView private readonly ISushiLogic _logicSushi; private readonly IShopLogic _logicShop; - public FormSellSushi(ILogger logger, ISushiLogic logicI, IShopLogic logicS) + public FormSellSushi(ILogger logger, ISushiLogic logicSushi, IShopLogic logicShop) { InitializeComponent(); _logger = logger; - _logicSushi = logicI; - _logicShop = logicS; + _logicSushi = logicSushi; + _logicShop = logicShop; } private void FormSellSushi_Load(object sender, EventArgs e) -- 2.25.1 From 80c35aa7629b89308e6802ee7e80d7c4506a522d Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 4 Mar 2023 10:40:57 +0400 Subject: [PATCH 08/21] =?UTF-8?q?=D0=9A=D1=80=D0=B0=D1=81=D0=BE=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormSellSushi.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/SushiBar/SushiBar/FormSellSushi.cs b/SushiBar/SushiBar/FormSellSushi.cs index d1b4354..afff76c 100644 --- a/SushiBar/SushiBar/FormSellSushi.cs +++ b/SushiBar/SushiBar/FormSellSushi.cs @@ -1,15 +1,6 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace SushiBarView { -- 2.25.1 From 6447cc832d7bf036b9663d380847c2dcc61a999a Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 4 Mar 2023 10:46:26 +0400 Subject: [PATCH 09/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D1=81=D1=82=D0=B2=D0=B0=20=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarListImplement/DataListSingleton.cs | 4 ++-- .../SushiBarListImplement/Implements/IngredientStorage.cs | 4 ++-- SushiBar/SushiBarListImplement/Implements/OrderStorage.cs | 4 ++-- SushiBar/SushiBarListImplement/Implements/ShopStorage.cs | 4 ++-- SushiBar/SushiBarListImplement/Implements/SushiStorage.cs | 4 ++-- SushiBar/SushiBarListImplement/Models/Ingredient.cs | 2 +- SushiBar/SushiBarListImplement/Models/Order.cs | 2 +- SushiBar/SushiBarListImplement/Models/Shop.cs | 2 +- SushiBar/SushiBarListImplement/Models/Sushi.cs | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index f398fdd..04beee0 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -1,6 +1,6 @@ -using SushiBarFileImplement.Models; +using SushiBarListImplement.Models; -namespace SushiBarFileImplement +namespace SushiBarListImplement { public class DataListSingleton { diff --git a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs index 0ee51d8..92a771b 100644 --- a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs @@ -2,9 +2,9 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarFileImplement.Models; +using SushiBarListImplement.Models; -namespace SushiBarFileImplement.Implements +namespace SushiBarListImplement.Implements { public class IngredientStorage : IIngredientStorage { diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs index dedc1f8..3254155 100644 --- a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -2,9 +2,9 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarFileImplement.Models; +using SushiBarListImplement.Models; -namespace SushiBarFileImplement.Implements +namespace SushiBarListImplement.Implements { public class OrderStorage : IOrderStorage { diff --git a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs index e5fff04..f7c55c9 100644 --- a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs @@ -3,9 +3,9 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -using SushiBarFileImplement.Models; +using SushiBarListImplement.Models; -namespace SushiBarFileImplement.Implements +namespace SushiBarListImplement.Implements { public class ShopStorage : IShopStorage { diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index c65caf2..a57a5f8 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -3,9 +3,9 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -using SushiBarFileImplement.Models; +using SushiBarListImplement.Models; -namespace SushiBarFileImplement.Implements +namespace SushiBarListImplement.Implements { public class SushiStorage : ISushiStorage { diff --git a/SushiBar/SushiBarListImplement/Models/Ingredient.cs b/SushiBar/SushiBarListImplement/Models/Ingredient.cs index 01a2271..2f61296 100644 --- a/SushiBar/SushiBarListImplement/Models/Ingredient.cs +++ b/SushiBar/SushiBarListImplement/Models/Ingredient.cs @@ -2,7 +2,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace SushiBarFileImplement.Models +namespace SushiBarListImplement.Models { public class Ingredient : IIngredientModel { diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 81908bf..445b162 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -3,7 +3,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; -namespace SushiBarFileImplement.Models +namespace SushiBarListImplement.Models { public class Order : IOrderModel { diff --git a/SushiBar/SushiBarListImplement/Models/Shop.cs b/SushiBar/SushiBarListImplement/Models/Shop.cs index b27761d..f209f1d 100644 --- a/SushiBar/SushiBarListImplement/Models/Shop.cs +++ b/SushiBar/SushiBarListImplement/Models/Shop.cs @@ -2,7 +2,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace SushiBarFileImplement.Models +namespace SushiBarListImplement.Models { public class Shop : IShopModel { diff --git a/SushiBar/SushiBarListImplement/Models/Sushi.cs b/SushiBar/SushiBarListImplement/Models/Sushi.cs index 1ae291c..3a589e8 100644 --- a/SushiBar/SushiBarListImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarListImplement/Models/Sushi.cs @@ -2,7 +2,7 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace SushiBarFileImplement.Models +namespace SushiBarListImplement.Models { public class Sushi : ISushiModel { -- 2.25.1 From 1db299c9b16839e404b1f289ca7744a670e79f36 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 7 Mar 2023 21:28:41 +0400 Subject: [PATCH 10/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=83?= =?UTF-8?q?=D1=81=D0=B0=20"=D0=93=D0=BE=D1=82=D0=BE=D0=B2"=20=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D1=83=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.Designer.cs | 32 ++++++++--------- .../BusinessLogics/ShopLogic.cs | 34 +++++++++---------- .../Implements/ShopStorage.cs | 2 +- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index c92d394..b5be1c6 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -51,7 +51,7 @@ this.справочникиToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(975, 24); + this.menuStrip.Size = new System.Drawing.Size(974, 24); this.menuStrip.TabIndex = 0; this.menuStrip.Text = "menuStrip1"; // @@ -88,10 +88,10 @@ // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(778, 237); + this.buttonUpdate.Location = new System.Drawing.Point(778, 212); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(170, 62); + this.buttonUpdate.Size = new System.Drawing.Size(170, 32); this.buttonUpdate.TabIndex = 12; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; @@ -99,10 +99,10 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(778, 171); + this.buttonSetToFinish.Location = new System.Drawing.Point(778, 176); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; - this.buttonSetToFinish.Size = new System.Drawing.Size(170, 62); + this.buttonSetToFinish.Size = new System.Drawing.Size(170, 32); this.buttonSetToFinish.TabIndex = 11; this.buttonSetToFinish.Text = "Заказ выдан"; this.buttonSetToFinish.UseVisualStyleBackColor = true; @@ -110,10 +110,10 @@ // // buttonSetToDone // - this.buttonSetToDone.Location = new System.Drawing.Point(778, 179); + this.buttonSetToDone.Location = new System.Drawing.Point(778, 140); this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToDone.Name = "buttonSetToDone"; - this.buttonSetToDone.Size = new System.Drawing.Size(170, 62); + this.buttonSetToDone.Size = new System.Drawing.Size(170, 32); this.buttonSetToDone.TabIndex = 10; this.buttonSetToDone.Text = "Заказ готов"; this.buttonSetToDone.UseVisualStyleBackColor = true; @@ -124,7 +124,7 @@ this.buttonSetToWork.Location = new System.Drawing.Point(778, 104); this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToWork.Name = "buttonSetToWork"; - this.buttonSetToWork.Size = new System.Drawing.Size(170, 62); + this.buttonSetToWork.Size = new System.Drawing.Size(170, 32); this.buttonSetToWork.TabIndex = 9; this.buttonSetToWork.Text = "Отдать на выполнение"; this.buttonSetToWork.UseVisualStyleBackColor = true; @@ -132,10 +132,10 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(778, 38); + this.buttonCreateOrder.Location = new System.Drawing.Point(778, 68); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(170, 62); + this.buttonCreateOrder.Size = new System.Drawing.Size(170, 32); this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; @@ -150,15 +150,15 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(755, 426); + this.dataGridView.Size = new System.Drawing.Size(755, 358); this.dataGridView.TabIndex = 7; // // buttonAddSushiInShop // - this.buttonAddSushiInShop.Location = new System.Drawing.Point(778, 302); + this.buttonAddSushiInShop.Location = new System.Drawing.Point(778, 248); this.buttonAddSushiInShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonAddSushiInShop.Name = "buttonAddSushiInShop"; - this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 62); + this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 32); this.buttonAddSushiInShop.TabIndex = 13; this.buttonAddSushiInShop.Text = "Добавить суши в магазин"; this.buttonAddSushiInShop.UseVisualStyleBackColor = true; @@ -166,10 +166,10 @@ // // buttonSellSushi // - this.buttonSellSushi.Location = new System.Drawing.Point(778, 367); + this.buttonSellSushi.Location = new System.Drawing.Point(778, 284); this.buttonSellSushi.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSellSushi.Name = "buttonSellSushi"; - this.buttonSellSushi.Size = new System.Drawing.Size(170, 62); + this.buttonSellSushi.Size = new System.Drawing.Size(170, 32); this.buttonSellSushi.TabIndex = 14; this.buttonSellSushi.Text = "Продать суши"; this.buttonSellSushi.UseVisualStyleBackColor = true; @@ -179,7 +179,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(975, 450); + this.ClientSize = new System.Drawing.Size(974, 382); this.Controls.Add(this.buttonSellSushi); this.Controls.Add(this.buttonAddSushiInShop); this.Controls.Add(this.buttonUpdate); diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index 16156ed..13761bc 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -171,35 +171,33 @@ namespace SushiBarBusinessLogic.BusinessLogics { throw new ArgumentException("Количество суши должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddSushi. ShopName:{ShopName}. Id:{Id}", model.SushiName, model.Id); + var freePlaces = _shopStorage.GetFullList() + .Select(x => x.MaxCountSushi - x.ListSushi + .Select(p => p.Value.Item2).Sum()).Sum() - count; + if (freePlaces < 0) + { + _logger.LogInformation("AddSushi. Не удалось добавить изделия в магазины, они переполнены."); + return false; + } foreach (var shop in _shopStorage.GetFullList()) { - int free = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum(); - if (free < count) + var temp = Math.Min(count, shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum()); + if (temp <= 0) { - if (!AddSushiInShop(new() { Id = shop.Id }, model, free)) - { - _logger.LogWarning("AddSushi operation failed."); - return false; - } - count -= free; + continue; } - else + if (!AddSushiInShop(new() { Id = shop.Id }, model, temp)) { - if (!AddSushiInShop(new() { Id = shop.Id }, model, count)) - { - _logger.LogWarning("AddSushiInShop operation failed."); - return false; - } - count = 0; + _logger.LogWarning("При добавлении суши в магазины произошла ошибка"); + return false; } + count -= temp; if (count == 0) { return true; } } - _logger.LogWarning("AddSushi operation failed."); - return false; + return true; } public bool SellSushi(ISushiModel model, int count) diff --git a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs index 0e1161f..d8d5302 100644 --- a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs @@ -90,7 +90,7 @@ namespace SushiBarFileImplement.Implements int countInCurrentShop = shop.ListSushi[model.Id].Item2; if (countInCurrentShop <= count) { - shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, 0); + shop.ListSushi.Remove(model.Id); count -= countInCurrentShop; } else -- 2.25.1 From 75e4c71d5defdc5137207b46b2ece54109d98c4d Mon Sep 17 00:00:00 2001 From: dasha Date: Thu, 9 Mar 2023 13:13:48 +0400 Subject: [PATCH 11/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA=20=D0=BF=D1=80=D0=BE=D1=88=D0=BB=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBarContracts/StoragesContracts/IShopStorage.cs | 1 - SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs | 9 +-------- SushiBar/SushiBarListImplement/Implements/ShopStorage.cs | 5 ----- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs index 0028fe5..d2b3b6e 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -13,7 +13,6 @@ namespace SushiBarContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool IsEnoughSushi(ISushiModel model, int count); bool SellSushi(ISushiModel model, int count); } } diff --git a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs index d8d5302..18ecd1d 100644 --- a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs @@ -72,16 +72,9 @@ namespace SushiBarFileImplement.Implements return null; } - public bool IsEnoughSushi(ISushiModel model, int count) - { - int temp = source.Shops - .Select(x => x.ListSushi.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum(); - return temp >= count; - } - public bool SellSushi(ISushiModel model, int count) { - if (!IsEnoughSushi(model, count)) + if (source.Shops.Select(x => x.ListSushi.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < count) { return false; } diff --git a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs index f7c55c9..1f85f14 100644 --- a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs @@ -100,11 +100,6 @@ namespace SushiBarListImplement.Implements return null; } - public bool IsEnoughSushi(ISushiModel model, int count) - { - throw new NotImplementedException(); - } - public bool SellSushi(ISushiModel model, int count) { throw new NotImplementedException(); -- 2.25.1 From 48552db0b2351e814ff23285b3c4f5cbf5f70f75 Mon Sep 17 00:00:00 2001 From: dasha Date: Thu, 9 Mar 2023 13:13:48 +0400 Subject: [PATCH 12/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA=20=D0=BF=D1=80=D0=BE=D1=88=D0=BB=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index 13761bc..d9d86c3 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -171,33 +171,42 @@ namespace SushiBarBusinessLogic.BusinessLogics { throw new ArgumentException("Количество суши должно быть больше 0", nameof(count)); } - var freePlaces = _shopStorage.GetFullList() + var freeCount = _shopStorage.GetFullList() .Select(x => x.MaxCountSushi - x.ListSushi .Select(p => p.Value.Item2).Sum()).Sum() - count; - if (freePlaces < 0) + if (freeCount < 0) { _logger.LogInformation("AddSushi. Не удалось добавить изделия в магазины, они переполнены."); return false; } foreach (var shop in _shopStorage.GetFullList()) { - var temp = Math.Min(count, shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum()); - if (temp <= 0) + int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum(); + if (countFree < count) { - continue; + if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree)) + { + _logger.LogWarning("AddSushiInShop operation failed."); + return false; + } + count -= countFree; } - if (!AddSushiInShop(new() { Id = shop.Id }, model, temp)) + else { - _logger.LogWarning("При добавлении суши в магазины произошла ошибка"); - return false; + if (!AddSushiInShop(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddSushiInShop operation failed."); + return false; + } + count = 0; } - count -= temp; if (count == 0) { return true; } } - return true; + _logger.LogWarning("AddSushi operation failed."); + return false; } public bool SellSushi(ISushiModel model, int count) -- 2.25.1 From ad9256c5a63a153f807ba9f1ccfb983a9cbb3025 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Mar 2023 02:21:39 +0400 Subject: [PATCH 13/21] =?UTF-8?q?=D0=A2=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index d9d86c3..2b16c02 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -205,8 +205,7 @@ namespace SushiBarBusinessLogic.BusinessLogics return true; } } - _logger.LogWarning("AddSushi operation failed."); - return false; + return true; } public bool SellSushi(ISushiModel model, int count) -- 2.25.1 From 2e7b0aacaa829c02ebc2ff7246c067dcb29669f2 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 18 Mar 2023 20:21:30 +0400 Subject: [PATCH 14/21] =?UTF-8?q?=D0=A4=D0=BE=D0=BB=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index 2b16c02..a31b18b 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -205,7 +205,7 @@ namespace SushiBarBusinessLogic.BusinessLogics return true; } } - return true; + return false; } public bool SellSushi(ISushiModel model, int count) -- 2.25.1 From 586c0905ed81f537d102cb4ebee5612979d6ba64 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 18 Mar 2023 20:21:30 +0400 Subject: [PATCH 15/21] =?UTF-8?q?=D0=A4=D0=BE=D0=BB=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 139f769..158680b 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -100,7 +100,7 @@ namespace SushiBarBusinessLogic.BusinessLogics } if (!_shopLogic.AddSushi(sushi, viewModel.Count)) { - throw new Exception($"AddSushis operation failed. Shop is full."); + throw new Exception($"AddSushi operation failed. Shop is full."); } } else -- 2.25.1 From 50c0cdc17eb75b703eac7a8a10dfdb1fb78577ae Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:15:43 +0400 Subject: [PATCH 16/21] =?UTF-8?q?=D0=A8=D1=82=D1=83=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoragesContracts/ISushiStorage.cs | 1 - .../SushiBarFileImplement/Implements/SushiStorage.cs | 12 ++++-------- .../SushiBarListImplement/Implements/SushiStorage.cs | 5 ----- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs index f968fb1..38370ea 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -13,7 +13,6 @@ namespace SushiBarContracts.StoragesContracts SushiViewModel? Insert(SushiBindingModel model); SushiViewModel? Update(SushiBindingModel model); SushiViewModel? Delete(SushiBindingModel model); - bool HasSushi(ISushiModel model, int needCount); bool SellSushi(ISushiModel model, int count); } } diff --git a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs index 04399ba..522b360 100644 --- a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs @@ -72,17 +72,13 @@ namespace SushiBarFileImplement.Implements } return null; } - public bool HasSushi(ISushiModel sushi, int needCount) - { - var temp = source.Shops - .Select(x => x.ListSushi - .FirstOrDefault(x => x.Key == sushi.Id).Value.Item2).Sum(); - return temp >= needCount; - } public bool SellSushi(ISushiModel model, int count) { - if (!HasSushi(model, count)) + var temp = source.Shops + .Select(x => x.ListSushi + .FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum(); + if (temp < count) { return false; } diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index a57a5f8..a2bd782 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -100,11 +100,6 @@ namespace SushiBarListImplement.Implements return null; } - public bool HasSushi(ISushiModel model, int needCount) - { - throw new NotImplementedException(); - } - public bool SellSushi(ISushiModel model, int count) { throw new NotImplementedException(); -- 2.25.1 From f997e6fc06f103f6d68778f4bacb1d48cd18ff18 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:20:57 +0400 Subject: [PATCH 17/21] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBarFileImplement/Implements/OrderStorage.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index 0dbe30a..7d4b062 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -41,14 +41,9 @@ namespace SushiBarFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var sushi in source.ListSushi) - { - if (sushi.Id == order.SushiId) - { - viewModel.SushiName = sushi.SushiName; - break; - } - } + var sushi = source.ListSushi.FirstOrDefault(x => x.Id == order.SushiId); + if (sushi == null) return null; + viewModel.SushiName = sushi.SushiName; return viewModel; } public OrderViewModel? Insert(OrderBindingModel model) -- 2.25.1 From 90dd93ef7ad6dfc41e85181cb0a648f5048cd646 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:20:57 +0400 Subject: [PATCH 18/21] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index 7d4b062..032b8d3 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -42,8 +42,7 @@ namespace SushiBarFileImplement.Implements { var viewModel = order.GetViewModel; var sushi = source.ListSushi.FirstOrDefault(x => x.Id == order.SushiId); - if (sushi == null) return null; - viewModel.SushiName = sushi.SushiName; + if (sushi != null) viewModel.SushiName = sushi.SushiName; return viewModel; } public OrderViewModel? Insert(OrderBindingModel model) -- 2.25.1 From eb48ee2c52b236723fd4d8d9142cca8e96144cf8 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:35:15 +0400 Subject: [PATCH 19/21] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoragesContracts/ISushiStorage.cs | 2 -- .../Implements/SushiStorage.cs | 31 ------------------- 2 files changed, 33 deletions(-) diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs index 38370ea..ff49391 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -1,7 +1,6 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; namespace SushiBarContracts.StoragesContracts { @@ -13,6 +12,5 @@ namespace SushiBarContracts.StoragesContracts SushiViewModel? Insert(SushiBindingModel model); SushiViewModel? Update(SushiBindingModel model); SushiViewModel? Delete(SushiBindingModel model); - bool SellSushi(ISushiModel model, int count); } } diff --git a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs index 522b360..e5c4cab 100644 --- a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs @@ -72,36 +72,5 @@ namespace SushiBarFileImplement.Implements } return null; } - - public bool SellSushi(ISushiModel model, int count) - { - var temp = source.Shops - .Select(x => x.ListSushi - .FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum(); - if (temp < count) - { - return false; - } - - foreach (var shop in source.Shops.Where(x => x.ListSushi.ContainsKey(model.Id))) - { - if (shop.ListSushi[model.Id].Item2 < count) - { - shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, 0); - count -= shop.ListSushi[model.Id].Item2; - } - else - { - shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, - shop.ListSushi[model.Id].Item2 - count); - count -= count; - } - if (count <= 0) - { - return true; - } - } - return true; - } } } -- 2.25.1 From f1f1d11272b28c249567380aab3765488c6e11b1 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:35:15 +0400 Subject: [PATCH 20/21] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarListImplement/Implements/SushiStorage.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index a2bd782..750821d 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -99,10 +99,5 @@ namespace SushiBarListImplement.Implements } return null; } - - public bool SellSushi(ISushiModel model, int count) - { - throw new NotImplementedException(); - } } } \ No newline at end of file -- 2.25.1 From f6e1a161e06e043378866d455470ff497e422527 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:35:15 +0400 Subject: [PATCH 21/21] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarListImplement/Implements/SushiStorage.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index 750821d..d2878ca 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -2,7 +2,6 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; using SushiBarListImplement.Models; namespace SushiBarListImplement.Implements -- 2.25.1