From 722ab5829cad94090f2abbecd0c1a6f2ed13186e Mon Sep 17 00:00:00 2001 From: dasha Date: Mon, 10 Apr 2023 21:11:09 +0400 Subject: [PATCH 01/10] implements --- SushiBar/SushiBar/Program.cs | 2 + .../BindingModels/ImplementerBindingModel.cs | 20 +++ .../IImplementerLogic.cs | 19 +++ .../SearchModels/ImplementerSearchModel.cs | 11 ++ .../StoragesContracts/IImplementerStorage.cs | 21 ++++ .../ViewModels/ImplementerViewModel.cs | 25 ++++ .../Models/IImplementerModel.cs | 13 ++ .../Implements/ImplementerStorage.cs | 93 ++++++++++++++ .../Models/Implementer.cs | 57 +++++++++ .../SushiBarDatabaseImplement/Models/Order.cs | 1 + .../SushiBarDatabase.cs | 2 + .../DataFileSingleton.cs | 4 + .../Implements/ImplementerStorage.cs | 81 +++++++++++++ .../Models/Implementer.cs | 76 ++++++++++++ .../DataListSingleton.cs | 4 +- .../Implements/ImplementerStorage.cs | 114 ++++++++++++++++++ .../Models/Implementer.cs | 58 +++++++++ 17 files changed, 600 insertions(+), 1 deletion(-) create mode 100644 SushiBar/SushiBarContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs create mode 100644 SushiBar/SushiBarDataModels/Models/IImplementerModel.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs create mode 100644 SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/Implementer.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Implementer.cs diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index f2c1558..d629d78 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -42,12 +42,14 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/SushiBar/SushiBarContracts/BindingModels/ImplementerBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..946ed73 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,20 @@ +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + /// + /// Исполнитель, выполняющий заказы + /// + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..0a6ec37 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/ImplementerSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..378179a --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace SushiBarContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..c8e3de4 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + + List GetFilteredList(ImplementerSearchModel model); + + ImplementerViewModel? GetElement(ImplementerSearchModel model); + + ImplementerViewModel? Insert(ImplementerBindingModel model); + + ImplementerViewModel? Update(ImplementerBindingModel model); + + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..943aa6d --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,25 @@ +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.ViewModels +{ + /// + /// Исполнитель, выполняющий заказы + /// + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/Models/IImplementerModel.cs b/SushiBar/SushiBarDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..c1061b5 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IImplementerModel.cs @@ -0,0 +1,13 @@ +namespace SushiBarDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..2a62128 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,93 @@ +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDatabaseImplement.Models; + +namespace SushiBarDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new SushiBarDatabase(); + var element = context.Implementers.Include(x => x.Orders).FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new SushiBarDatabase(); + if (model.Id.HasValue) + { + return context.Implementers + .Include(x => x.Orders) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + return context.Implementers.Include(x => x.Orders) + .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO)?.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new SushiBarDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SushiBarDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new SushiBarDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return context.Implementers + .Include(x => x.Orders) + .FirstOrDefault(x => x.Id == newImplementer.Id)?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new SushiBarDatabase(); + var implementer = context.Implementers.Include(x => x.Orders).FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..b63d057 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,57 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace SushiBarDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } + [Required] + public int Qualification { get; private set; } + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification, + }; + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index e8bae5c..661b3c8 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -12,6 +12,7 @@ namespace SushiBarDatabaseImplement.Models public int SushiId { get; set; } [Required] public int ClientId { get; set; } + public int? ImplementerId { get; private set; } [Required] public int Count { get; set; } [Required] diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 75c006c..c9b8aa1 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -23,5 +23,7 @@ namespace SushiBarDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + + public virtual DbSet Implementers { set; get; } } } diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index f7c957d..b4d7213 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -10,10 +10,12 @@ namespace SushiBarFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string SushiFileName = "Sushi.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Ingredients { get; private set; } public List Orders { get; private set; } public List ListSushi { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -28,12 +30,14 @@ namespace SushiBarFileImplement "ListSushi", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", 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)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..d5bd844 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,81 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; + +namespace SushiBarFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + return source.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/Implementer.cs b/SushiBar/SushiBarFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..0537bcd --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Implementer.cs @@ -0,0 +1,76 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification)); + } +} diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index fb1cbc8..2afc72e 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -9,12 +9,14 @@ namespace SushiBarListImplement public List Orders { get; set; } public List ListSushi { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Ingredients = new List(); Orders = new List(); ListSushi = new List(); - Clients = new List(); + Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..0c1699c --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,114 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + return implementer.GetViewModel; + } + } + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO == model.ImplementerFIO) + { + return implementer.GetViewModel; + } + } + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Implementer.cs b/SushiBar/SushiBarListImplement/Models/Implementer.cs new file mode 100644 index 0000000..6d87636 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Implementer.cs @@ -0,0 +1,58 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} -- 2.25.1 From 5cc65fd54793e22c4a0944694a4fe4bf6b091ab5 Mon Sep 17 00:00:00 2001 From: dasha Date: Mon, 10 Apr 2023 22:46:23 +0400 Subject: [PATCH 02/10] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormImplementer.Designer.cs | 178 ++++++++++++ SushiBar/SushiBar/FormImplementer.cs | 99 +++++++ SushiBar/SushiBar/FormImplementer.resx | 60 ++++ .../SushiBar/FormImplementers.Designer.cs | 122 +++++++++ SushiBar/SushiBar/FormImplementers.cs | 102 +++++++ SushiBar/SushiBar/FormImplementers.resx | 60 ++++ SushiBar/SushiBar/FormMain.Designer.cs | 72 +++-- SushiBar/SushiBar/FormMain.cs | 26 +- SushiBar/SushiBar/Program.cs | 3 + .../BusinessLogics/ImplementerLogic.cs | 119 ++++++++ .../BusinessLogics/OrderLogic.cs | 17 ++ .../BusinessLogics/WorkModeling.cs | 144 ++++++++++ .../BindingModels/OrderBindingModel.cs | 1 + .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 10 + .../SearchModels/OrderSearchModel.cs | 8 +- .../ViewModels/OrderViewModel.cs | 5 +- .../Implements/ImplementerStorage.cs | 5 + .../Implements/OrderStorage.cs | 62 +++-- ...410183555_ImplementerMigration.Designer.cs | 257 ++++++++++++++++++ .../20230410183555_ImplementerMigration.cs | 67 +++++ .../SushiBarDatabaseModelSnapshot.cs | 43 +++ .../SushiBarDatabaseImplement/Models/Order.cs | 5 + .../Implements/ImplementerStorage.cs | 14 +- .../Implements/ImplementerStorage.cs | 10 + .../Controllers/ImplementerController.cs | 106 ++++++++ SushiBar/SushiBarRestApi/Program.cs | 2 + 27 files changed, 1526 insertions(+), 72 deletions(-) create mode 100644 SushiBar/SushiBar/FormImplementer.Designer.cs create mode 100644 SushiBar/SushiBar/FormImplementer.cs create mode 100644 SushiBar/SushiBar/FormImplementer.resx create mode 100644 SushiBar/SushiBar/FormImplementers.Designer.cs create mode 100644 SushiBar/SushiBar/FormImplementers.cs create mode 100644 SushiBar/SushiBar/FormImplementers.resx create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.Designer.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.cs create mode 100644 SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs diff --git a/SushiBar/SushiBar/FormImplementer.Designer.cs b/SushiBar/SushiBar/FormImplementer.Designer.cs new file mode 100644 index 0000000..e5affa0 --- /dev/null +++ b/SushiBar/SushiBar/FormImplementer.Designer.cs @@ -0,0 +1,178 @@ +namespace SushiBarView +{ + partial class FormImplementer + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.textBoxFio = new System.Windows.Forms.TextBox(); + this.labelQualification = new System.Windows.Forms.Label(); + this.labelWorkExperience = new System.Windows.Forms.Label(); + this.labelPassword = new System.Windows.Forms.Label(); + this.labelFIO = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(190, 135); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(89, 33); + this.buttonSave.TabIndex = 19; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(285, 135); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(89, 33); + this.buttonCancel.TabIndex = 18; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // numericUpDownQualification + // + this.numericUpDownQualification.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownQualification.Location = new System.Drawing.Point(112, 98); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(262, 23); + this.numericUpDownQualification.TabIndex = 17; + // + // numericUpDownWorkExperience + // + this.numericUpDownWorkExperience.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownWorkExperience.Location = new System.Drawing.Point(112, 69); + this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + this.numericUpDownWorkExperience.Size = new System.Drawing.Size(262, 23); + this.numericUpDownWorkExperience.TabIndex = 16; + // + // textBoxPassword + // + this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxPassword.Location = new System.Drawing.Point(112, 41); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.PasswordChar = '*'; + this.textBoxPassword.Size = new System.Drawing.Size(262, 23); + this.textBoxPassword.TabIndex = 15; + // + // textBoxFio + // + this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxFio.Location = new System.Drawing.Point(112, 12); + this.textBoxFio.Name = "textBoxFio"; + this.textBoxFio.Size = new System.Drawing.Size(262, 23); + this.textBoxFio.TabIndex = 14; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(12, 98); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(88, 15); + this.labelQualification.TabIndex = 13; + this.labelQualification.Text = "Квалификация"; + // + // labelWorkExperience + // + this.labelWorkExperience.AutoSize = true; + this.labelWorkExperience.Location = new System.Drawing.Point(12, 71); + this.labelWorkExperience.Name = "labelWorkExperience"; + this.labelWorkExperience.Size = new System.Drawing.Size(35, 15); + this.labelWorkExperience.TabIndex = 12; + this.labelWorkExperience.Text = "Стаж"; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(12, 41); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(49, 15); + this.labelPassword.TabIndex = 11; + this.labelPassword.Text = "Пароль"; + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(12, 15); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(34, 15); + this.labelFIO.TabIndex = 10; + this.labelFIO.Text = "ФИО"; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(386, 180); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.numericUpDownWorkExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFio); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.labelWorkExperience); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private NumericUpDown numericUpDownQualification; + private NumericUpDown numericUpDownWorkExperience; + private TextBox textBoxPassword; + private TextBox textBoxFio; + private Label labelQualification; + private Label labelWorkExperience; + private Label labelPassword; + private Label labelFIO; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormImplementer.cs b/SushiBar/SushiBar/FormImplementer.cs new file mode 100644 index 0000000..56a62e4 --- /dev/null +++ b/SushiBar/SushiBar/FormImplementer.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; + +namespace SushiBarView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExperience.Value = view.WorkExperience; + } + } + 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(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExperience.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + 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/FormImplementer.resx b/SushiBar/SushiBar/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormImplementer.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/FormImplementers.Designer.cs b/SushiBar/SushiBar/FormImplementers.Designer.cs new file mode 100644 index 0000000..911475f --- /dev/null +++ b/SushiBar/SushiBar/FormImplementers.Designer.cs @@ -0,0 +1,122 @@ +namespace SushiBarView +{ + partial class FormImplementers + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 291); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(446, 163); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(446, 137); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(446, 111); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(446, 85); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(590, 291); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormImplementers.cs b/SushiBar/SushiBar/FormImplementers.cs new file mode 100644 index 0000000..a578d4b --- /dev/null +++ b/SushiBar/SushiBar/FormImplementers.cs @@ -0,0 +1,102 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBar/FormImplementers.resx b/SushiBar/SushiBar/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormImplementers.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/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index b2530d5..a017ded 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -33,14 +33,14 @@ this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.сушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокИнгредиентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ингредиентыПоСушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); - this.buttonSetToDone = new System.Windows.Forms.Button(); - this.buttonSetToWork = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.menuStrip.SuspendLayout(); @@ -51,7 +51,8 @@ // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); + this.отчетыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1086, 24); @@ -63,7 +64,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ингредиентыToolStripMenuItem, this.сушиToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -71,24 +73,31 @@ // ингредиентыToolStripMenuItem // this.ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; - this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.ингредиентыToolStripMenuItem.Text = "Ингредиенты"; this.ингредиентыToolStripMenuItem.Click += new System.EventHandler(this.IngredientsToolStripMenuItem_Click); // // сушиToolStripMenuItem // this.сушиToolStripMenuItem.Name = "сушиToolStripMenuItem"; - this.сушиToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.сушиToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.сушиToolStripMenuItem.Text = "Суши"; this.сушиToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -120,12 +129,19 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click); + // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(875, 318); + this.buttonUpdate.Location = new System.Drawing.Point(905, 253); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(199, 58); + this.buttonUpdate.Size = new System.Drawing.Size(169, 58); this.buttonUpdate.TabIndex = 12; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; @@ -133,43 +149,21 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(875, 256); + this.buttonSetToFinish.Location = new System.Drawing.Point(905, 182); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; - this.buttonSetToFinish.Size = new System.Drawing.Size(199, 58); + this.buttonSetToFinish.Size = new System.Drawing.Size(169, 58); this.buttonSetToFinish.TabIndex = 11; this.buttonSetToFinish.Text = "Заказ выдан"; this.buttonSetToFinish.UseVisualStyleBackColor = true; this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); // - // buttonSetToDone - // - this.buttonSetToDone.Location = new System.Drawing.Point(875, 194); - this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonSetToDone.Name = "buttonSetToDone"; - this.buttonSetToDone.Size = new System.Drawing.Size(199, 58); - this.buttonSetToDone.TabIndex = 10; - this.buttonSetToDone.Text = "Заказ готов"; - this.buttonSetToDone.UseVisualStyleBackColor = true; - this.buttonSetToDone.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // buttonSetToWork - // - this.buttonSetToWork.Location = new System.Drawing.Point(875, 132); - this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonSetToWork.Name = "buttonSetToWork"; - this.buttonSetToWork.Size = new System.Drawing.Size(199, 58); - this.buttonSetToWork.TabIndex = 9; - this.buttonSetToWork.Text = "Отдать на выполнение"; - this.buttonSetToWork.UseVisualStyleBackColor = true; - this.buttonSetToWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(875, 70); + this.buttonCreateOrder.Location = new System.Drawing.Point(905, 111); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(199, 58); + this.buttonCreateOrder.Size = new System.Drawing.Size(169, 58); this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; @@ -184,7 +178,7 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(854, 426); + this.dataGridView.Size = new System.Drawing.Size(899, 426); this.dataGridView.TabIndex = 7; // // FormMain @@ -194,8 +188,6 @@ this.ClientSize = new System.Drawing.Size(1086, 450); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); - this.Controls.Add(this.buttonSetToDone); - this.Controls.Add(this.buttonSetToWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip); @@ -219,8 +211,6 @@ private ToolStripMenuItem сушиToolStripMenuItem; private Button buttonUpdate; private Button buttonSetToFinish; - private Button buttonSetToDone; - private Button buttonSetToWork; private Button buttonCreateOrder; private DataGridView dataGridView; private ToolStripMenuItem отчетыToolStripMenuItem; @@ -228,5 +218,7 @@ private ToolStripMenuItem ингредиентыПоСушиToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 868216f..00f291c 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -9,12 +9,14 @@ namespace SushiBarView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) { @@ -31,6 +33,10 @@ namespace SushiBarView dataGridView.DataSource = list; dataGridView.Columns["SushiId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -181,5 +187,23 @@ namespace SushiBarView form.ShowDialog(); } } + + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(( + Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } \ No newline at end of file diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index d629d78..3f66517 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -50,6 +50,7 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -65,6 +66,8 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..fc85f4b --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,119 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Id:{Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}.Id:{Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("У исполнителя должно быть ФИО", nameof(model.ImplementerFIO)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("У исполнителя квалификация должна быть больше 0", nameof(model.Qualification)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("У исполнителя стаж должен быть больше 0", nameof(model.WorkExperience)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("У исполнителя должен быть пароль", nameof(model.Password)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}.Qualification:{Qualification}.WorkExperience:{WorkExperience} Id: {Id}", model.ImplementerFIO, model.Qualification, model.WorkExperience, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 3baee63..171f94e 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -115,5 +115,22 @@ namespace SushiBarBusinessLogic.BusinessLogics { return StatusUpdate(model, OrderStatus.Готов); } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..27176b4 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,144 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Принят }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + /// + /// Имитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + OrderStatus = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index e1ad383..7817eb5 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -7,6 +7,7 @@ namespace SushiBarContracts.BindingModels { public int SushiId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs index be0cb58..2d45204 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,6 +7,7 @@ namespace SushiBarContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..7b87056 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,10 @@ +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs index bd86dd5..5ef96ab 100644 --- a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,6 @@ -namespace SushiBarContracts.SearchModels +using SushiBarDataModels.Enums; + +namespace SushiBarContracts.SearchModels { public class OrderSearchModel { @@ -6,6 +8,10 @@ public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + + public OrderStatus? OrderStatus { get; set; } + public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index ac8beb0..c22a7a9 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -10,10 +10,13 @@ namespace SushiBarContracts.ViewModels public int Id { get; set; } public int SushiId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Суши")] public string SushiName { get; set; } = string.Empty; [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs index 2a62128..4e5165c 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs @@ -31,6 +31,11 @@ namespace SushiBarDatabaseImplement.Implements .Include(x => x.Orders) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + return context.Implementers.Include(x => x.Orders) + .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel; + } else if (!string.IsNullOrEmpty(model.ImplementerFIO)) { return context.Implementers.Include(x => x.Orders) diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index d4afe19..ab5eea7 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -15,6 +15,7 @@ namespace SushiBarDatabaseImplement.Implements var element = context.Orders .Include(x => x.Sushi) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { @@ -27,30 +28,36 @@ namespace SushiBarDatabaseImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return null; - } using var context = new SushiBarDatabase(); - return context.Orders - .Include(x => x.Sushi) - .Include(x => x.Client) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; + if (model.Id.HasValue) + { + return context.Orders + .Include(x => x.Sushi) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) + { + return context.Orders + .Include(x => x.Sushi) + .Include(x => x.Client).Include(x => x.Implementer) + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus) + ?.GetViewModel; + } + return null; } public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue) - { - return new(); - } + { + if (model == null) return new(); using var context = new SushiBarDatabase(); - if (model.DateFrom.HasValue) + if (model.DateFrom.HasValue && model.DateTo.HasValue) { return context.Orders .Include(x => x.Sushi) - .Include(x => x.Client) + .Include(x => x.Client).Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -58,16 +65,25 @@ namespace SushiBarDatabaseImplement.Implements else if (model.ClientId.HasValue) return context.Orders .Include(x => x.Sushi) - .Include(x => x.Client) + .Include(x => x.Client).Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); - return context.Orders - .Include(x => x.Sushi) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + else if (model.OrderStatus.HasValue) + return context.Orders + .Include(x => x.Sushi) + .Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.Status == model.OrderStatus) + .Select(x => x.GetViewModel) + .ToList(); + else if (model.Id.HasValue) + return context.Orders + .Include(x => x.Sushi) + .Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + return new(); } public List GetFullList() { diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.Designer.cs new file mode 100644 index 0000000..2c9fd9b --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SushiBarDatabaseImplement; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + [DbContext(typeof(SushiBarDatabase))] + [Migration("20230410183555_ImplementerMigration")] + partial class ImplementerMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("IngredientName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Ingredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("SushiId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SushiName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ListSushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("IngredientId") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IngredientId"); + + b.HasIndex("SushiId"); + + b.ToTable("SushiIngredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Orders") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Ingredient", "Ingredient") + .WithMany("SushiIngredients") + .HasForeignKey("IngredientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Ingredients") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ingredient"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => + { + b.Navigation("SushiIngredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Navigation("Ingredients"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.cs new file mode 100644 index 0000000..7782850 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410183555_ImplementerMigration.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + /// + public partial class ImplementerMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index 258fb61..72d343f 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -47,6 +47,33 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("Clients"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace SushiBarDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace SushiBarDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("SushiId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace SushiBarDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") .WithMany("Orders") .HasForeignKey("SushiId") @@ -167,6 +203,8 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Sushi"); }); @@ -194,6 +232,11 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Orders"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => { b.Navigation("SushiIngredients"); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index 661b3c8..0c8cd1c 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -25,6 +25,7 @@ namespace SushiBarDatabaseImplement.Models public int Id { get; set; } public Sushi Sushi { get; set; } public Client Client { get; set; } + public Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -36,6 +37,7 @@ namespace SushiBarDatabaseImplement.Models Id = model.Id, SushiId = model.SushiId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -52,13 +54,16 @@ namespace SushiBarDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { SushiId = SushiId, ClientId = ClientId, + ImplementerId = ImplementerId, ClientFIO = Client.ClientFIO, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, DateCreate = DateCreate, diff --git a/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs index d5bd844..8867f56 100644 --- a/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs @@ -27,13 +27,15 @@ namespace SushiBarFileImplement.Implements public ImplementerViewModel? GetElement(ImplementerSearchModel model) { - if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + if (!string.IsNullOrEmpty(model.ImplementerFIO) || model.Id.HasValue) { - return null; - } - return source.Implementers.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO) || - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return source.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + return source.Implementers.FirstOrDefault(x => + x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel; + return null; } public List GetFilteredList(ImplementerSearchModel model) diff --git a/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs index 0c1699c..c804d58 100644 --- a/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs @@ -39,6 +39,16 @@ namespace SushiBarListImplement.Implements } } } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO) && implementer.Password.Equals(model.Password)) + { + return implementer.GetViewModel; + } + } + } else if (!string.IsNullOrEmpty(model.ImplementerFIO)) { foreach (var implementer in _source.Implementers) diff --git a/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs b/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..f180fbf --- /dev/null +++ b/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,106 @@ +using Microsoft.AspNetCore.Mvc; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + //Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + //ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } + } + } +} diff --git a/SushiBar/SushiBarRestApi/Program.cs b/SushiBar/SushiBarRestApi/Program.cs index 73886b2..5d0c986 100644 --- a/SushiBar/SushiBarRestApi/Program.cs +++ b/SushiBar/SushiBarRestApi/Program.cs @@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -- 2.25.1 From f6be0179105f11d3b4c4d7f7d227d8f27f21667c Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 11 Apr 2023 00:07:47 +0400 Subject: [PATCH 03/10] list and db fixes --- .../Implements/OrderStorage.cs | 13 +++++++++++- .../Implements/OrderStorage.cs | 20 ++++++++++++++++++- .../Models/Implementer.cs | 5 ----- .../SushiBarListImplement/Models/Order.cs | 5 ++++- .../Controllers/ImplementerController.cs | 5 +++-- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index ab5eea7..7672d5e 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -38,7 +38,7 @@ namespace SushiBarDatabaseImplement.Implements .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } - if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) + else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) { return context.Orders .Include(x => x.Sushi) @@ -46,6 +46,14 @@ namespace SushiBarDatabaseImplement.Implements .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus) ?.GetViewModel; } + else if (model.ImplementerId.HasValue) + { + return context.Orders + .Include(x => x.Sushi) + .Include(x => x.Client).Include(x => x.Implementer) + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } return null; } @@ -91,6 +99,7 @@ namespace SushiBarDatabaseImplement.Implements return context.Orders .Include(x => x.Sushi) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -108,6 +117,7 @@ namespace SushiBarDatabaseImplement.Implements return context.Orders .Include(x => x.Sushi) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == newOrder.Id) ?.GetViewModel; } @@ -118,6 +128,7 @@ namespace SushiBarDatabaseImplement.Implements var order = context.Orders .Include(x => x.Sushi) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id); if (order == null) { diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs index 76ed27c..4718102 100644 --- a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -26,7 +26,7 @@ namespace SushiBarListImplement.Implements { var result = new List(); - if (model.DateFrom.HasValue) + if (model.DateFrom.HasValue && model.DateTo.HasValue) { foreach (var order in _source.Orders) { @@ -46,6 +46,16 @@ namespace SushiBarListImplement.Implements } } } + else if (model.OrderStatus.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Status == model.OrderStatus) + { + result.Add(GetViewModel(order)); + } + } + } else if (model.Id.HasValue) { foreach (var order in _source.Orders) @@ -92,6 +102,14 @@ namespace SushiBarListImplement.Implements break; } } + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == order.ImplementerId) + { + viewModel.ImplementerFIO = implementer.ImplementerFIO; + break; + } + } return viewModel; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/SushiBar/SushiBarListImplement/Models/Implementer.cs b/SushiBar/SushiBarListImplement/Models/Implementer.cs index 6d87636..4abc2e2 100644 --- a/SushiBar/SushiBarListImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarListImplement/Models/Implementer.cs @@ -1,11 +1,6 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SushiBarListImplement.Models { diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 74d1f03..90710ee 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -2,7 +2,6 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; -using System.Reflection; namespace SushiBarListImplement.Models { @@ -11,6 +10,7 @@ namespace SushiBarListImplement.Models public int Id { get; private set; } public int SushiId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -26,6 +26,7 @@ namespace SushiBarListImplement.Models { SushiId = model.SushiId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -41,12 +42,14 @@ namespace SushiBarListImplement.Models return; } Status = model.Status; + ImplementerId = model.ImplementerId; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { SushiId = SushiId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, DateCreate = DateCreate, diff --git a/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs b/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs index f180fbf..ebf3be2 100644 --- a/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs +++ b/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs @@ -3,6 +3,7 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; namespace SushiBarRestApi.Controllers { @@ -48,7 +49,7 @@ namespace SushiBarRestApi.Controllers { return _order.ReadList(new OrderSearchModel { - //Status = OrderStatus.Принят + OrderStatus = OrderStatus.Принят }); } catch (Exception ex) @@ -65,7 +66,7 @@ namespace SushiBarRestApi.Controllers { return _order.ReadElement(new OrderSearchModel { - //ImplementerId = implementerId + ImplementerId = implementerId }); } catch (Exception ex) -- 2.25.1 From 9e7b7de847d6f64378ba7080f6fabf996dd4c82f Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 11 Apr 2023 00:20:00 +0400 Subject: [PATCH 04/10] vrode vse --- .../Implements/OrderStorage.cs | 38 +++++++++++++++---- .../SushiBarFileImplement/Models/Order.cs | 6 +++ .../Models/Implementer.cs | 1 + 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index 1fd61f5..bf1ac96 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarFileImplement.Models; +using System.Linq; namespace SushiBarFileImplement.Implements { @@ -21,17 +22,22 @@ namespace SushiBarFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (model.DateFrom.HasValue) + if (model.DateFrom.HasValue && model.DateTo.HasValue) return source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => GetViewModel(x)) .ToList(); - if (model.ClientId.HasValue && !model.Id.HasValue) + else if (model.ClientId.HasValue && !model.Id.HasValue) return source.Orders .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); - if (model.Id.HasValue) + else if (model.OrderStatus.HasValue) + return source.Orders + .Where(x => x.Status == model.OrderStatus) + .Select(x => x.GetViewModel) + .ToList(); + else if (model.Id.HasValue) return source.Orders .Where(x => x.Id.Equals(model.Id)) .Select(x => GetViewModel(x)) @@ -41,14 +47,25 @@ namespace SushiBarFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (model.Id.HasValue) { - return null; + return source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } - - return source.Orders.FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus) + ?.GetViewModel; + } + else if (model.ImplementerId.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } + return null; } + private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; @@ -57,13 +74,18 @@ namespace SushiBarFileImplement.Implements .ListSushi.FirstOrDefault(x => x.Id == order.SushiId); var client = source .Clients.FirstOrDefault(x => x.Id == order.ClientId); + var implementer = source + .Implementers.FirstOrDefault(x => x.Id == order.ImplementerId); if (sushi != null) viewModel.SushiName = sushi.SushiName; if (client != null) viewModel.ClientFIO = client.ClientFIO; + if (implementer != null) + viewModel.ImplementerFIO = implementer.ImplementerFIO; return viewModel; } + public OrderViewModel? Insert(OrderBindingModel model) { model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index ffc3a7a..483ddac 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -10,6 +10,7 @@ namespace SushiBarFileImplement.Models { public int Id { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int SushiId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -27,6 +28,7 @@ namespace SushiBarFileImplement.Models Id = model.Id, SushiId = model.SushiId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -46,6 +48,7 @@ namespace SushiBarFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.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), @@ -62,12 +65,14 @@ namespace SushiBarFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { SushiId = SushiId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, DateCreate = DateCreate, @@ -80,6 +85,7 @@ namespace SushiBarFileImplement.Models new XAttribute("Id", Id), new XElement("SushiId", SushiId), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/SushiBar/SushiBarListImplement/Models/Implementer.cs b/SushiBar/SushiBarListImplement/Models/Implementer.cs index 4abc2e2..333ac5f 100644 --- a/SushiBar/SushiBarListImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarListImplement/Models/Implementer.cs @@ -15,6 +15,7 @@ namespace SushiBarListImplement.Models public int WorkExperience { get; private set; } public int Qualification { get; private set; } + public static Implementer? Create(ImplementerBindingModel? model) { if (model == null) -- 2.25.1 From 461e4aa2c9147b36a98874cf9f82e27a4166b9a7 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 11 Apr 2023 16:31:01 +0400 Subject: [PATCH 05/10] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs | 4 ++-- SushiBar/SushiBarDatabaseImplement/Models/Order.cs | 5 +++-- SushiBar/SushiBarFileImplement/Models/Order.cs | 3 ++- SushiBar/SushiBarListImplement/Models/Order.cs | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs index 27176b4..8f71021 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -76,6 +76,8 @@ namespace SushiBarBusinessLogic.BusinessLogics { Id = order.Id }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } // кто-то мог уже перехватить заказ, игнорируем ошибку catch (InvalidOperationException ex) @@ -88,8 +90,6 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger.LogError(ex, "Error while do work"); throw; } - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } }); } diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index 0c8cd1c..f15634f 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -53,8 +53,9 @@ namespace SushiBarDatabaseImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; - ImplementerId = model.ImplementerId; + DateImplement = model.DateImplement; + if (model.ImplementerId.HasValue) + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index 483ddac..a52d7fa 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -65,7 +65,8 @@ namespace SushiBarFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - ImplementerId = model.ImplementerId; + if (model.ImplementerId.HasValue) + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 90710ee..e6ef6ae 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -42,8 +42,9 @@ namespace SushiBarListImplement.Models return; } Status = model.Status; - ImplementerId = model.ImplementerId; - DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + if (model.ImplementerId.HasValue) + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { -- 2.25.1 From bb6c1345d1bec7a3e00dfc8881570bb9362fec86 Mon Sep 17 00:00:00 2001 From: dasha Date: Mon, 17 Apr 2023 18:37:05 +0400 Subject: [PATCH 06/10] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B2?= =?UTF-8?q?=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.Designer.cs | 57 +++++++++----------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 01efde5..3f73660 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -32,8 +32,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.сушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокИнгредиентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -61,7 +61,6 @@ this.запускРаботToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(974, 24); this.menuStrip.Size = new System.Drawing.Size(1086, 24); this.menuStrip.TabIndex = 0; this.menuStrip.Text = "menuStrip1"; @@ -72,8 +71,7 @@ this.ингредиентыToolStripMenuItem, this.сушиToolStripMenuItem, this.клиентыToolStripMenuItem, - this.shopsToolStripMenuItem}); - this.клиентыToolStripMenuItem, + this.shopsToolStripMenuItem, this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); @@ -93,13 +91,6 @@ this.сушиToolStripMenuItem.Text = "Суши"; this.сушиToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); // - // shopsToolStripMenuItem - // - this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; - this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.shopsToolStripMenuItem.Text = "Магазины"; - this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); - // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; @@ -107,6 +98,13 @@ this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); // + // shopsToolStripMenuItem + // + this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + this.shopsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.shopsToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // // исполнителиToolStripMenuItem // this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; @@ -178,14 +176,10 @@ // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(778, 212); - this.buttonUpdate.Location = new System.Drawing.Point(875, 318); - this.buttonUpdate.Location = new System.Drawing.Point(905, 253); + this.buttonUpdate.Location = new System.Drawing.Point(905, 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, 32); - this.buttonUpdate.Size = new System.Drawing.Size(199, 58); - this.buttonUpdate.Size = new System.Drawing.Size(169, 58); + this.buttonUpdate.Size = new System.Drawing.Size(169, 30); this.buttonUpdate.TabIndex = 12; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; @@ -193,14 +187,10 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(778, 176); - this.buttonSetToFinish.Location = new System.Drawing.Point(875, 256); - this.buttonSetToFinish.Location = new System.Drawing.Point(905, 182); + this.buttonSetToFinish.Location = new System.Drawing.Point(905, 175); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; - this.buttonSetToFinish.Size = new System.Drawing.Size(170, 32); - this.buttonSetToFinish.Size = new System.Drawing.Size(199, 58); - this.buttonSetToFinish.Size = new System.Drawing.Size(169, 58); + this.buttonSetToFinish.Size = new System.Drawing.Size(169, 33); this.buttonSetToFinish.TabIndex = 11; this.buttonSetToFinish.Text = "Заказ выдан"; this.buttonSetToFinish.UseVisualStyleBackColor = true; @@ -208,14 +198,10 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(778, 68); - this.buttonCreateOrder.Location = new System.Drawing.Point(875, 70); - this.buttonCreateOrder.Location = new System.Drawing.Point(905, 111); + this.buttonCreateOrder.Location = new System.Drawing.Point(905, 138); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(170, 32); - this.buttonCreateOrder.Size = new System.Drawing.Size(199, 58); - this.buttonCreateOrder.Size = new System.Drawing.Size(169, 58); + this.buttonCreateOrder.Size = new System.Drawing.Size(169, 33); this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; @@ -230,17 +216,15 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(755, 358); - this.dataGridView.Size = new System.Drawing.Size(854, 426); this.dataGridView.Size = new System.Drawing.Size(899, 426); this.dataGridView.TabIndex = 7; // // buttonAddSushiInShop // - this.buttonAddSushiInShop.Location = new System.Drawing.Point(778, 248); + this.buttonAddSushiInShop.Location = new System.Drawing.Point(905, 246); this.buttonAddSushiInShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonAddSushiInShop.Name = "buttonAddSushiInShop"; - this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 32); + this.buttonAddSushiInShop.Size = new System.Drawing.Size(169, 32); this.buttonAddSushiInShop.TabIndex = 13; this.buttonAddSushiInShop.Text = "Добавить суши в магазин"; this.buttonAddSushiInShop.UseVisualStyleBackColor = true; @@ -248,10 +232,10 @@ // // buttonSellSushi // - this.buttonSellSushi.Location = new System.Drawing.Point(778, 284); + this.buttonSellSushi.Location = new System.Drawing.Point(905, 282); this.buttonSellSushi.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSellSushi.Name = "buttonSellSushi"; - this.buttonSellSushi.Size = new System.Drawing.Size(170, 32); + this.buttonSellSushi.Size = new System.Drawing.Size(169, 32); this.buttonSellSushi.TabIndex = 14; this.buttonSellSushi.Text = "Продать суши"; this.buttonSellSushi.UseVisualStyleBackColor = true; @@ -261,10 +245,9 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(974, 382); + this.ClientSize = new System.Drawing.Size(1086, 450); this.Controls.Add(this.buttonSellSushi); this.Controls.Add(this.buttonAddSushiInShop); - this.ClientSize = new System.Drawing.Size(1086, 450); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); this.Controls.Add(this.buttonCreateOrder); -- 2.25.1 From c83a68d282c01e2bd5f2d3d147c1c78206c83de7 Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 19 Apr 2023 20:01:35 +0400 Subject: [PATCH 07/10] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 7 +-- .../BusinessLogics/ShopLogic.cs | 2 + .../BusinessLogics/WorkModeling.cs | 45 +++++++++++++++++++ .../SushiBarDataModels/Enums/OrderStatus.cs | 1 + 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 26d3f81..64ef1da 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -84,13 +84,13 @@ namespace SushiBarBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - if (viewModel.Status + 1 != newStatus) + if (viewModel.Status + 1 != newStatus && viewModel.Status != OrderStatus.Ожидание) { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Готов) + if (model.Status == OrderStatus.Готов || viewModel.Status == OrderStatus.Ожидание) { model.DateImplement = DateTime.Now; var sushi = _sushiStorage.GetElement(new() { Id = viewModel.SushiId }); @@ -100,7 +100,8 @@ namespace SushiBarBusinessLogic.BusinessLogics } if (!_shopLogic.AddSushi(sushi, viewModel.Count)) { - throw new Exception($"AddSushi operation failed. Shop is full."); + model.Status = OrderStatus.Ожидание; + _logger.LogWarning($"AddSushi operation failed. Shop is full."); } } else diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index a31b18b..c3f47d8 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -182,6 +182,8 @@ namespace SushiBarBusinessLogic.BusinessLogics foreach (var shop in _shopStorage.GetFullList()) { int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum(); + if (countFree <= 0) + continue; if (countFree < count) { if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree)) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs index 8f71021..55d8c49 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -54,6 +54,9 @@ namespace SushiBarBusinessLogic.BusinessLogics { return; } + + await RunOrderAfterWaiting(implementer); + await RunOrderInWork(implementer); await Task.Run(() => @@ -140,5 +143,47 @@ namespace SushiBarBusinessLogic.BusinessLogics throw; } } + + /// + /// Ищем заказ, который в ожидании + /// + /// + /// + private async Task RunOrderAfterWaiting(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var order = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + OrderStatus = OrderStatus.Ожидание + })); + if (order == null) + { + return; + } + // доделываем работу + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } } } diff --git a/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs index e7973ca..5f699dc 100644 --- a/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs +++ b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs @@ -7,5 +7,6 @@ Выполняется = 1, Готов = 2, Выдан = 3, + Ожидание = 4 } } -- 2.25.1 From a410427c9b1d292367089f2aeae79cfe7fe11fd3 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 22 Apr 2023 14:37:55 +0400 Subject: [PATCH 08/10] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D1=85=D0=BE=D1=82=D1=8C=20=D0=BD=D0=B5=20=D0=BE?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D1=8C=20=D0=BA=D1=80=D0=B0=D1=81=D0=B8=D0=B2?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 5 ++++- .../BusinessLogics/WorkModeling.cs | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 64ef1da..68a8a8f 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -92,7 +92,6 @@ namespace SushiBarBusinessLogic.BusinessLogics model.Status = newStatus; if (model.Status == OrderStatus.Готов || viewModel.Status == OrderStatus.Ожидание) { - model.DateImplement = DateTime.Now; var sushi = _sushiStorage.GetElement(new() { Id = viewModel.SushiId }); if (sushi == null) { @@ -103,6 +102,10 @@ namespace SushiBarBusinessLogic.BusinessLogics model.Status = OrderStatus.Ожидание; _logger.LogWarning($"AddSushi operation failed. Shop is full."); } + else + { + model.DateImplement = DateTime.Now; + } } else { diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs index 55d8c49..6f923af 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -30,10 +30,22 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Принят }); - if (orders == null || orders.Count == 0) + List? orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Принят }); + List? ordersInWork = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Выполняется }); + List? ordersInWaiting = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Ожидание }); + if (orders == null || ordersInWork == null || ordersInWaiting == null) { - _logger.LogWarning("DoWork. Orders is null or empty"); + _logger.LogWarning("DoWork. Orders are null"); + return; + } + else + { + orders.AddRange(ordersInWork); + orders.AddRange(ordersInWaiting); + } + if (orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders are empty"); return; } _logger.LogDebug("DoWork for {Count} orders", orders.Count); -- 2.25.1 From 1149a8fe889de846e4886d8d16bde36375b091df Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 25 Apr 2023 13:23:53 +0400 Subject: [PATCH 09/10] =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=B7=D0=B0=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/WorkModeling.cs | 43 +++++++++---------- .../SushiBarDatabase.cs | 2 +- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs index 6f923af..0d84547 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -30,24 +30,18 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger.LogWarning("DoWork. Implementers is null"); return; } - List? orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Принят }); - List? ordersInWork = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Выполняется }); - List? ordersInWaiting = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Ожидание }); - if (orders == null || ordersInWork == null || ordersInWaiting == null) + + var orders = _orderLogic.ReadList(new OrderSearchModel { - _logger.LogWarning("DoWork. Orders are null"); - return; - } - else - { - orders.AddRange(ordersInWork); - orders.AddRange(ordersInWaiting); - } - if (orders.Count == 0) - { - _logger.LogWarning("DoWork. Orders are empty"); + OrderStatus = OrderStatus.Принят + }); + + if (orders == null) + { + _logger.LogWarning("DoWork. Orders is null or empty"); return; } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); foreach (var implementer in implementers) { @@ -169,23 +163,26 @@ namespace SushiBarBusinessLogic.BusinessLogics } try { - var order = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + var orders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel { ImplementerId = implementer.Id, OrderStatus = OrderStatus.Ожидание })); - if (order == null) + if (orders == null) { return; } // доделываем работу - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); - _orderLogic.FinishOrder(new OrderBindingModel + foreach (var order in orders) { - Id = order.Id - }); - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } } catch (InvalidOperationException ex) { diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 56ac116..c66ea9b 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -10,7 +10,7 @@ namespace SushiBarDatabaseImplement if (optionsBuilder.IsConfigured == false) { // D8KMQQU comp JC256C6 nout - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-JC256C6\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } -- 2.25.1 From 26a38322ef1d5a2ca3f1a9576087e09589072956 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 25 Apr 2023 13:47:06 +0400 Subject: [PATCH 10/10] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=82=D1=83=D0=BF=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarDatabaseImplement/Models/Shop.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs b/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs index 54482fc..2f6072b 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs @@ -28,8 +28,18 @@ namespace SushiBarDatabaseImplement.Models { if (_shopSushi == null) { - _shopSushi = ListSushiFk - .ToDictionary(recPC => recPC.SushiId, recPC => (recPC.Sushi as ISushiModel, recPC.Count)); + _shopSushi = new(); + ListSushiFk.ForEach(x => + { + if (_shopSushi.ContainsKey(x.SushiId)) + { + _shopSushi[x.SushiId] = (x.Sushi as ISushiModel, _shopSushi[x.SushiId].Item2 + x.Count); + } + else + { + _shopSushi[x.SushiId] = (x.Sushi as ISushiModel, x.Count); + } + }); } return _shopSushi; } -- 2.25.1