From 003c54db7d493a00c7a82fd8a839d1d171adcf02 Mon Sep 17 00:00:00 2001 From: Viltskaa Date: Sun, 9 Apr 2023 23:25:46 +0400 Subject: [PATCH 1/4] Add implementer --- .../BindingModels/ImplementerBindingModel.cs | 12 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 13 +++ .../SearchModels/ImplementerSearchModel.cs | 10 ++ .../SearchModels/OrderSearchModel.cs | 1 + .../StoragesContracts/IImplementerStorage.cs | 15 +++ .../ViewModels/ImplementerViewModel.cs | 20 ++++ .../ViewModels/OrderViewModel.cs | 4 + .../Implements/ImplementerStorage.cs | 81 +++++++++++++ .../Models/Implementer.cs | 64 +++++++++++ .../SushiBarDatabaseImplement/Models/Order.cs | 9 +- .../SushiBarDatabase.cs | 1 + .../DataFileSingleton.cs | 11 +- .../Implements/ImplementerStorage.cs | 89 +++++++++++++++ .../Models/Implementer.cs | 77 +++++++++++++ .../SushiBarFileImplement/Models/Order.cs | 8 ++ .../Models/IImplementerModel.cs | 9 ++ .../DataListSingleton.cs | 3 + .../Implements/ImplementerStorage.cs | 106 ++++++++++++++++++ .../Models/Implementer.cs | 42 +++++++ 20 files changed, 572 insertions(+), 4 deletions(-) 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/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/SushiBarModels/Models/IImplementerModel.cs create mode 100644 SushiBar/SushibarListImplement/Implements/ImplementerStorage.cs create mode 100644 SushiBar/SushibarListImplement/Models/Implementer.cs diff --git a/SushiBar/SushiBarContracts/BindingModels/ImplementerBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..0266055 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,12 @@ +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/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index b222b27..43c71b8 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -8,6 +8,7 @@ namespace SushiBarContracts.BindingModels public int Id { get; set; } public int SushiId { get; set; } public int ClientId { get; set; } + public int ImplementerId { get; set; } public string ClientFio { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty; public int Count { get; set; } diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..d94baa4 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,13 @@ +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts; + +public interface IImplementerLogic +{ + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + bool Create(ImplementerSearchModel model); + bool Update(ImplementerSearchModel model); + bool Delete(ImplementerSearchModel 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..1ed6adf --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,10 @@ +namespace SushiBarContracts.SearchModels; + +public class ImplementerSearchModel +{ + public int? Id { get; set; } + public string? ImplementerFio { get; set; } + public string? Password { get; set; } + public int? WorkExperience { get; set; } + public int? Qualification { get; set; } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs index 862e85f..b1a1f0c 100644 --- a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -6,5 +6,6 @@ public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..191c2e8 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,15 @@ +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..20c5a96 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,20 @@ +using System.ComponentModel; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.ViewModels; + +public class ImplementerViewModel : IImplementerModel +{ + public int Id { get; init; } + + [DisplayName("Implementer FIO")] + public string ImplementerFio { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + [DisplayName("Work Experience")] + public int WorkExperience { get; set; } + + [DisplayName("Qualification")] + public int Qualification { get; set; } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index 427d445..2a55c2e 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -11,10 +11,14 @@ namespace SushiBarContracts.ViewModels public int SushiId { get; init; } public int ClientId { get; init; } + public int ImplementerId { get; set; } [DisplayName("Client FIO")] public string ClientFio { get; init; } = string.Empty; + [DisplayName("Implementer FIO")] + public string ImplementerFio { get; set; } = string.Empty; + [DisplayName("Name of Product")] public string SushiName { get; init; } = string.Empty; diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..330d8fd --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,81 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDatabaseImplement.Models; + +namespace SushiBarDatabaseImplement.Implements; + +public class ImplementerStorage : IImplementerStorage +{ + public List GetFullList() + { + using var context = new SushiBarDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel? model) + { + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new List { res } : new List(); + } + + if (model.ImplementerFio == null) return new List(); + using var context = new SushiBarDatabase(); + return context.Implementers + .Where(x => x.ImplementerFio.Equals(model.ImplementerFio)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel? model) + { + using var context = new SushiBarDatabase(); + if (model.Id.HasValue) + return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model is { ImplementerFio: { }, Password: { } }) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + return model.ImplementerFio != null ? + context.Implementers + .FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio))?.GetViewModel : + null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new SushiBarDatabase(); + var res = Implementer.Create(model); + if (res == null) return res?.GetViewModel; + context.Implementers.Add(res); + context.SaveChanges(); + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new SushiBarDatabase(); + var res = context.Implementers + .FirstOrDefault(x => x.Id == model.Id); + if (res == null) return res?.GetViewModel; + res.Update(model); + context.SaveChanges(); + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new SushiBarDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res == null) return res?.GetViewModel; + context.Implementers.Remove(res); + context.SaveChanges(); + return res?.GetViewModel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..72fa96e --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,64 @@ +using System.ComponentModel.DataAnnotations; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarDatabaseImplement.Models; + +public class Implementer : IImplementerModel +{ + public int Id { get; private init; } + [Required] public string ImplementerFio { get; private set; } = string.Empty; + [Required] 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(ImplementerViewModel model) + { + 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 + }; +} \ No newline at end of file diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index 0c5e74a..772e110 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace SushiBarDatabaseImplement.Models [Required] public int ClientId { get; private set; } + public int ImplementerId { get; private set; } public string SushiName { get; set; } = string.Empty; @@ -35,6 +36,8 @@ namespace SushiBarDatabaseImplement.Models public virtual Sushi Sushi { get; set; } public virtual Client Client { get; set; } + + public virtual Implementer? Implementer { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -49,6 +52,7 @@ namespace SushiBarDatabaseImplement.Models SushiId = model.SushiId, SushiName = model.SushiName, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -67,6 +71,7 @@ namespace SushiBarDatabaseImplement.Models SushiId = model.SushiId; SushiName = model.SushiName; ClientId = model.ClientId; + ImplementerId = model.ImplementerId; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -85,10 +90,12 @@ namespace SushiBarDatabaseImplement.Models Count = Count, DateCreate = DateCreate, DateImplement = DateImplement, + ImplementerId = ImplementerId, Sum = Sum, Status = Status, ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty, - SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty + SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty, + ImplementerFio = Implementer?.ImplementerFio ?? string.Empty }; } } } diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 9b7ed37..6af51fc 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -18,5 +18,6 @@ namespace SushiBarDatabaseImplement public virtual DbSet SushiComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { get; set; } } } diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index 4e670de..ea43f81 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ namespace SushiBarFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string SushiFileName = "Sushi.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Sushis { get; private set; } + public List Implementers { get; set; } public static DataFileSingleton GetInstance() { instance ??= new DataFileSingleton(); @@ -20,11 +22,14 @@ namespace SushiBarFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + private DataFileSingleton() { - Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; - Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; - Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.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..bf1d9c8 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,89 @@ +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 List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ImplementerSearchModel? model) + { + if (model == null) + { + return new List(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? + new List { res } : + new List(); + } + if (model.ImplementerFio != null) + { + return _source.Implementers + .Where(x => x.ImplementerFio.Equals(model.ImplementerFio)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new List(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel? model) + { + if (model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model is { ImplementerFio: { }, Password: { } }) + return _source.Implementers + .FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + return model.ImplementerFio != null ? + _source.Implementers + .FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio))?.GetViewModel : + null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? + _source.Implementers.Max(x => x.Id) + 1 : + 1; + var res = Implementer.Create(model); + if (res == null) return res?.GetViewModel; + _source.Implementers.Add(res); + _source.SaveImplementers(); + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res == null) return res?.GetViewModel; + res.Update(model); + _source.SaveImplementers(); + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res == null) return res?.GetViewModel; + _source.Implementers.Remove(res); + _source.SaveImplementers(); + return res?.GetViewModel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarFileImplement/Models/Implementer.cs b/SushiBar/SushiBarFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..282a53f --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Implementer.cs @@ -0,0 +1,77 @@ +using System.Xml.Linq; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +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(XElement? element) + { + if (element == null) + { + return null; + } + return new Implementer + { + ImplementerFio = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFio = model.ImplementerFio, + WorkExperience = model.WorkExperience, + }; + } + + + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFio = model.ImplementerFio; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFio = ImplementerFio, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFio), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); +} \ No newline at end of file diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index 51796bc..91213c5 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -12,6 +12,7 @@ namespace SushiBarFileImplement.Models public string SushiName { get; private set; } = string.Empty; public int SushiId { get; private set; } public int ClientId { get; } + public int ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Unknown; @@ -29,6 +30,7 @@ namespace SushiBarFileImplement.Models Id = model.Id, SushiId = model.SushiId, SushiName = model.SushiName, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -51,6 +53,7 @@ namespace SushiBarFileImplement.Models Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) }; @@ -67,6 +70,7 @@ namespace SushiBarFileImplement.Models } SushiId = model.SushiId; SushiName = model.SushiName; + ImplementerId = model.ImplementerId; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -78,6 +82,9 @@ namespace SushiBarFileImplement.Models Id = Id, SushiId = SushiId, SushiName = SushiName, + ImplementerFio = DataFileSingleton.GetInstance() + .Implementers + .FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFio ?? string.Empty, Count = Count, Sum = Sum, Status = Status, @@ -89,6 +96,7 @@ namespace SushiBarFileImplement.Models new XAttribute("Id", Id), new XElement("SushiName", SushiName), new XElement("SushiId", SushiId.ToString()), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/SushiBar/SushiBarModels/Models/IImplementerModel.cs b/SushiBar/SushiBarModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..8326da8 --- /dev/null +++ b/SushiBar/SushiBarModels/Models/IImplementerModel.cs @@ -0,0 +1,9 @@ +namespace SushiBarDataModels.Models; + +public interface IImplementerModel : IId +{ + string ImplementerFio { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } +} \ No newline at end of file diff --git a/SushiBar/SushibarListImplement/DataListSingleton.cs b/SushiBar/SushibarListImplement/DataListSingleton.cs index 2ec96c9..fe4b45b 100644 --- a/SushiBar/SushibarListImplement/DataListSingleton.cs +++ b/SushiBar/SushibarListImplement/DataListSingleton.cs @@ -8,11 +8,14 @@ namespace SushibarListImplement public List Components { get; set; } public List Orders { get; set; } public List Sushi { get; set; } + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Sushi = 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..2801d90 --- /dev/null +++ b/SushiBar/SushibarListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,106 @@ +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 (var i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id != model.Id) continue; + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + if (model.ImplementerFio != null && model.Password != null && + x.ImplementerFio.Equals(model.ImplementerFio) && x.Password.Equals(model.Password)) + return x.GetViewModel; + if (model.ImplementerFio != null && x.ImplementerFio.Equals(model.ImplementerFio)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? + new List { res } : + new List(); + } + + List result = new(); + if (model.ImplementerFio == null) return result; + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFio.Equals(model.ImplementerFio)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } +} \ No newline at end of file diff --git a/SushiBar/SushibarListImplement/Models/Implementer.cs b/SushiBar/SushibarListImplement/Models/Implementer.cs new file mode 100644 index 0000000..6b36a95 --- /dev/null +++ b/SushiBar/SushibarListImplement/Models/Implementer.cs @@ -0,0 +1,42 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushibarListImplement.Models; + +public class Implementer : IImplementerModel +{ + public int Id { get; set; } + public string ImplementerFio { get; set; } + public string Password { get; set; } + public int WorkExperience { get; set; } + public int Qualification { get; set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + return new Implementer + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFio = model.ImplementerFio, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + Password = model.Password; + Qualification = model.Qualification; + ImplementerFio = model.ImplementerFio; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFio = ImplementerFio, + }; +} \ No newline at end of file -- 2.25.1 From 055e45b19132a9895b65e113f51082e7d425f2d1 Mon Sep 17 00:00:00 2001 From: Viltskaa Date: Mon, 10 Apr 2023 13:35:57 +0400 Subject: [PATCH 2/4] second part lab work --- .../BusinessLogics/OrderLogic.cs | 17 +++ .../BusinessLogics/WorkModeling.cs | 127 ++++++++++++++++++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 6 + .../SearchModels/OrderSearchModel.cs | 5 +- .../Controllers/ImplementerController.cs | 102 ++++++++++++++ 6 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 0ba14c0..4f3b136 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -18,6 +18,23 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger = logger; _orderStorage = orderStorage; } + + 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; + } public bool CreateOrder(OrderBindingModel model) { diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..f325e4d --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,127 @@ +using DocumentFormat.OpenXml.Drawing.Charts; +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 { Status = OrderStatus.Accepted }); + 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) + { + 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) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new + OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Performed + })); + 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; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs index be0cb58..3898146 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -11,5 +11,6 @@ namespace SushiBarContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..b49e1ad --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,6 @@ +namespace SushiBarContracts.BusinessLogicsContracts; + +public interface IWorkProcess +{ + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs index b1a1f0c..dfa8020 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 { @@ -7,5 +9,6 @@ public DateTime? DateTo { get; set; } public int? ClientId { get; set; } public int? ImplementerId { get; set; } + public OrderStatus Status { get; set; } } } diff --git a/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs b/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..5841e24 --- /dev/null +++ b/SushiBar/SushiBarRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,102 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; + +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, "Error on auth"); + throw; + } + } + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Accepted + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on get new orders"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on get current order"); + throw; + } + } + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on take in work order with id {Id}", model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on ready order with id {Id}", model.Id); + throw; + } + } + +} \ No newline at end of file -- 2.25.1 From bbf06c417e313378ed8b67588a752d7179a52d09 Mon Sep 17 00:00:00 2001 From: Viltskaa Date: Mon, 10 Apr 2023 15:36:30 +0400 Subject: [PATCH 3/4] complete lab work --- SushiBar/SushiBar/FormCreateOrder.cs | 3 +- SushiBar/SushiBar/FormImplementer.Designer.cs | 167 ++++++++++++ SushiBar/SushiBar/FormImplementer.cs | 108 ++++++++ SushiBar/SushiBar/FormImplementer.resx | 60 +++++ .../SushiBar/FormImplementers.Designer.cs | 114 ++++++++ SushiBar/SushiBar/FormImplementers.cs | 108 ++++++++ SushiBar/SushiBar/FormImplementers.resx | 60 +++++ SushiBar/SushiBar/FormMain.Designer.cs | 60 +++-- SushiBar/SushiBar/FormMain.cs | 24 +- SushiBar/SushiBar/Program.cs | 5 + .../BusinessLogics/ImplementerLogic.cs | 123 +++++++++ .../BusinessLogics/OrderLogic.cs | 25 +- .../BusinessLogics/WorkModeling.cs | 35 ++- .../BindingModels/OrderBindingModel.cs | 2 +- .../IImplementerLogic.cs | 9 +- .../SearchModels/OrderSearchModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 2 +- .../Implements/OrderStorage.cs | 57 ++-- .../20230410100751_lab6.Designer.cs | 251 ++++++++++++++++++ .../Migrations/20230410100751_lab6.cs | 67 +++++ .../Migrations/SushiDatabaseModelSnapshot.cs | 38 +++ .../SushiBarDatabaseImplement/Models/Order.cs | 4 +- .../SushiBarFileImplement/Models/Order.cs | 2 +- 23 files changed, 1251 insertions(+), 75 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/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.Designer.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.cs diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs index 8292383..2938437 100644 --- a/SushiBar/SushiBar/FormCreateOrder.cs +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -95,7 +95,8 @@ namespace SushiBar ClientId = Convert.ToInt32(comboBoxClients.SelectedValue), SushiName = comboBoxSushi.Text, Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) + Sum = Convert.ToDouble(textBoxSum.Text), + ImplementerId = null }) ; if (!operationResult) { diff --git a/SushiBar/SushiBar/FormImplementer.Designer.cs b/SushiBar/SushiBar/FormImplementer.Designer.cs new file mode 100644 index 0000000..e7e596c --- /dev/null +++ b/SushiBar/SushiBar/FormImplementer.Designer.cs @@ -0,0 +1,167 @@ +namespace SushiBar +{ + 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.label1 = new System.Windows.Forms.Label(); + this.textBoxFio = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.numericUpDownExp = new System.Windows.Forms.NumericUpDown(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.numericUpDownQul = new System.Windows.Forms.NumericUpDown(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownExp)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQul)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(25, 15); + this.label1.TabIndex = 0; + this.label1.Text = "FIO"; + // + // textBoxFio + // + this.textBoxFio.Location = new System.Drawing.Point(43, 6); + this.textBoxFio.Name = "textBoxFio"; + this.textBoxFio.Size = new System.Drawing.Size(196, 23); + this.textBoxFio.TabIndex = 1; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 41); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(57, 15); + this.label2.TabIndex = 2; + this.label2.Text = "Password"; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(75, 38); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(164, 23); + this.textBoxPassword.TabIndex = 3; + // + // numericUpDownExp + // + this.numericUpDownExp.Location = new System.Drawing.Point(113, 67); + this.numericUpDownExp.Name = "numericUpDownExp"; + this.numericUpDownExp.Size = new System.Drawing.Size(126, 23); + this.numericUpDownExp.TabIndex = 4; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 69); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(95, 15); + this.label3.TabIndex = 5; + this.label3.Text = "Work Experience"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(12, 98); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(75, 15); + this.label4.TabIndex = 6; + this.label4.Text = "Qualification"; + // + // numericUpDownQul + // + this.numericUpDownQul.Location = new System.Drawing.Point(93, 96); + this.numericUpDownQul.Name = "numericUpDownQul"; + this.numericUpDownQul.Size = new System.Drawing.Size(146, 23); + this.numericUpDownQul.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(12, 126); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(114, 23); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Save"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(132, 126); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(107, 23); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(245, 157); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownQul); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.numericUpDownExp); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBoxFio); + this.Controls.Add(this.label1); + this.Name = "FormImplementer"; + this.Text = "FormImplementer"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownExp)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQul)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private TextBox textBoxFio; + private Label label2; + private TextBox textBoxPassword; + private NumericUpDown numericUpDownExp; + private Label label3; + private Label label4; + private NumericUpDown numericUpDownQul; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormImplementer.cs b/SushiBar/SushiBar/FormImplementer.cs new file mode 100644 index 0000000..26f6286 --- /dev/null +++ b/SushiBar/SushiBar/FormImplementer.cs @@ -0,0 +1,108 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBar +{ + 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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Fill password", "Error", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Fill fio", "Error", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFio = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQul.Value, + WorkExperience = (int)numericUpDownExp.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Error on saving. Additional info below"); + } + MessageBox.Show("Good", "Info", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on save"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Getting implementer"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.ImplementerFio; + textBoxPassword.Text = view.Password; + numericUpDownQul.Value = view.Qualification; + numericUpDownExp.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on getting implementer"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + } +} 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..1cd71ed --- /dev/null +++ b/SushiBar/SushiBar/FormImplementers.Designer.cs @@ -0,0 +1,114 @@ +namespace SushiBar +{ + 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonReload = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(648, 426); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(666, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(122, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Add"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(666, 41); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(122, 23); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Edit"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(666, 70); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(122, 23); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Delete"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonReload + // + this.buttonReload.Location = new System.Drawing.Point(666, 99); + this.buttonReload.Name = "buttonReload"; + this.buttonReload.Size = new System.Drawing.Size(122, 23); + this.buttonReload.TabIndex = 4; + this.buttonReload.Text = "Reload"; + this.buttonReload.UseVisualStyleBackColor = true; + this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonReload); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormImplementers"; + this.Text = "FormImplementers"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDelete; + private Button buttonReload; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormImplementers.cs b/SushiBar/SushiBar/FormImplementers.cs new file mode 100644 index 0000000..8c3d391 --- /dev/null +++ b/SushiBar/SushiBar/FormImplementers.cs @@ -0,0 +1,108 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBar +{ + 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 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 ButtonEdit_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 ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Delete record?", "Question", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deleting"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Error on delete. Addtional info below"); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on delete"); + MessageBox.Show(ex.Message, "Error", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonReload_Click(object sender, EventArgs e) + { + LoadData(); + } + + 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("Load implementers"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on load"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} 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 5da8606..1e0a78c 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -33,16 +33,18 @@ this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.implementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsOnSushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.startWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonSubmit = new System.Windows.Forms.Button(); this.buttonReady = new System.Windows.Forms.Button(); this.buttonIssue = new System.Windows.Forms.Button(); this.buttonReload = new System.Windows.Forms.Button(); - this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -53,17 +55,18 @@ this.dataGridView.Location = new System.Drawing.Point(12, 27); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(796, 411); + this.dataGridView.Size = new System.Drawing.Size(1277, 411); this.dataGridView.TabIndex = 0; // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.directoryToolStripMenuItem, - this.reportsToolStripMenuItem}); + this.reportsToolStripMenuItem, + this.startWorkToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(940, 24); + this.menuStrip1.Size = new System.Drawing.Size(1421, 24); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // @@ -72,7 +75,8 @@ this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.componentsToolStripMenuItem, this.sushiToolStripMenuItem, - this.clientsToolStripMenuItem}); + this.clientsToolStripMenuItem, + this.implementersToolStripMenuItem}); this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem"; this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20); this.directoryToolStripMenuItem.Text = "Directory"; @@ -80,17 +84,31 @@ // componentsToolStripMenuItem // this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(147, 22); this.componentsToolStripMenuItem.Text = "Components"; this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // // sushiToolStripMenuItem // this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; - this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.sushiToolStripMenuItem.Size = new System.Drawing.Size(147, 22); this.sushiToolStripMenuItem.Text = "Sushi"; this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); // + // clientsToolStripMenuItem + // + this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + this.clientsToolStripMenuItem.Size = new System.Drawing.Size(147, 22); + this.clientsToolStripMenuItem.Text = "Clients"; + this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); + // + // implementersToolStripMenuItem + // + this.implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + this.implementersToolStripMenuItem.Size = new System.Drawing.Size(147, 22); + this.implementersToolStripMenuItem.Text = "Implementers"; + this.implementersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click); + // // reportsToolStripMenuItem // this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -122,9 +140,16 @@ this.listOrdersToolStripMenuItem.Text = "List Orders"; this.listOrdersToolStripMenuItem.Click += new System.EventHandler(this.ListOrdersToolStripMenuItem_Click); // + // startWorkToolStripMenuItem + // + this.startWorkToolStripMenuItem.Name = "startWorkToolStripMenuItem"; + this.startWorkToolStripMenuItem.Size = new System.Drawing.Size(72, 20); + this.startWorkToolStripMenuItem.Text = "Start work"; + this.startWorkToolStripMenuItem.Click += new System.EventHandler(this.StartWorkToolStripMenuItem_Click); + // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(814, 27); + this.buttonCreateOrder.Location = new System.Drawing.Point(1295, 27); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(114, 23); this.buttonCreateOrder.TabIndex = 2; @@ -134,7 +159,7 @@ // // buttonSubmit // - this.buttonSubmit.Location = new System.Drawing.Point(814, 56); + this.buttonSubmit.Location = new System.Drawing.Point(1295, 56); this.buttonSubmit.Name = "buttonSubmit"; this.buttonSubmit.Size = new System.Drawing.Size(114, 23); this.buttonSubmit.TabIndex = 3; @@ -144,7 +169,7 @@ // // buttonReady // - this.buttonReady.Location = new System.Drawing.Point(814, 85); + this.buttonReady.Location = new System.Drawing.Point(1295, 85); this.buttonReady.Name = "buttonReady"; this.buttonReady.Size = new System.Drawing.Size(114, 23); this.buttonReady.TabIndex = 4; @@ -154,7 +179,7 @@ // // buttonIssue // - this.buttonIssue.Location = new System.Drawing.Point(814, 114); + this.buttonIssue.Location = new System.Drawing.Point(1295, 114); this.buttonIssue.Name = "buttonIssue"; this.buttonIssue.Size = new System.Drawing.Size(114, 23); this.buttonIssue.TabIndex = 5; @@ -164,7 +189,7 @@ // // buttonReload // - this.buttonReload.Location = new System.Drawing.Point(814, 143); + this.buttonReload.Location = new System.Drawing.Point(1295, 143); this.buttonReload.Name = "buttonReload"; this.buttonReload.Size = new System.Drawing.Size(114, 23); this.buttonReload.TabIndex = 6; @@ -172,18 +197,11 @@ this.buttonReload.UseVisualStyleBackColor = true; this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); // - // clientsToolStripMenuItem - // - this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.clientsToolStripMenuItem.Text = "Clients"; - this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(940, 450); + this.ClientSize = new System.Drawing.Size(1421, 450); this.Controls.Add(this.buttonReload); this.Controls.Add(this.buttonIssue); this.Controls.Add(this.buttonReady); @@ -220,5 +238,7 @@ private ToolStripMenuItem componentsOnSushiToolStripMenuItem; private ToolStripMenuItem listOrdersToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem startWorkToolStripMenuItem; + private ToolStripMenuItem implementersToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 86b194b..f1a2fb4 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -12,12 +12,18 @@ namespace SushiBar 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 LoadData() @@ -31,6 +37,7 @@ namespace SushiBar dataGridView.DataSource = list; dataGridView.Columns["SushiId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; dataGridView.Columns["ClientFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } } @@ -218,5 +225,20 @@ namespace SushiBar form.ShowDialog(); } } + + private void StartWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Process work is started", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 65222a9..7bff625 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -35,12 +35,15 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -55,6 +58,8 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..fd02071 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,123 @@ +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. FIO:{FIO}.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. FIO:{FIO}.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 (model.WorkExperience < 0) + { + throw new ArgumentException(nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException(nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException(nameof(model.ImplementerFio)); + } + if (string.IsNullOrEmpty(model.ImplementerFio)) + { + throw new ArgumentNullException(nameof(model.ImplementerFio)); + } + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFio); + 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 4f3b136..54bee68 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using DocumentFormat.OpenXml.EMMA; +using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; @@ -83,24 +84,34 @@ namespace SushiBarBusinessLogic.BusinessLogics private bool UpdateStatus(OrderBindingModel model, OrderStatus status) { - CheckModel(model); - var order = _orderStorage.GetElement(new OrderSearchModel() { Id = model.Id }); - if (model.Status + 1 != status) + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + + if (order.Status + 1 != status) { _logger.LogWarning("Status update operation failed"); return false; } model.Status = status; - model.DateImplement = order?.DateImplement; - if (model.Status == OrderStatus.Ready) + model.DateCreate = order.DateCreate; + if (model.DateImplement == null) + model.DateImplement = order.DateImplement; + if (order.ImplementerId.HasValue) + model.ImplementerId = order.ImplementerId; + if (model.Status == OrderStatus.Issued) { model.DateImplement = DateTime.Now; } + model.ClientId = order.ClientId; + model.SushiId = order.SushiId; + model.Sum = order.Sum; + model.Count = order.Count; if (_orderStorage.Update(model) == null) { - model.Status--; _logger.LogWarning("Update operation failed"); return false; } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs index f325e4d..a9a3f42 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -29,7 +29,8 @@ public class WorkModeling : IWorkProcess _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Accepted }); + + var orders = _orderLogic.ReadList(new OrderSearchModel { Status = new() { OrderStatus.Accepted, OrderStatus.Performed } }); if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); @@ -49,7 +50,7 @@ public class WorkModeling : IWorkProcess { return; } - await RunOrderInWork(implementer); + await RunOrderInWork(implementer, orders); await Task.Run(() => { foreach (var order in orders) @@ -62,8 +63,7 @@ public class WorkModeling : IWorkProcess Id = order.Id, ImplementerId = implementer.Id }); - Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, - 1000) * order.Count); + 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 { @@ -84,40 +84,37 @@ public class WorkModeling : IWorkProcess }); } - private async Task RunOrderInWork(ImplementerViewModel implementer) + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) { - if (_orderLogic == null) + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) { return; } try { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new - OrderSearchModel - { - ImplementerId = implementer.Id, - Status = OrderStatus.Performed - })); + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Performed)); 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 + + _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.DeliveryOrder(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"); diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index 43c71b8..24884a1 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -8,7 +8,7 @@ namespace SushiBarContracts.BindingModels public int Id { get; set; } public int SushiId { get; set; } public int ClientId { get; set; } - public int ImplementerId { get; set; } + public int? ImplementerId { get; set; } public string ClientFio { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty; public int Count { get; set; } diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs index d94baa4..be7047e 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.SearchModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; namespace SushiBarContracts.BusinessLogicsContracts; @@ -7,7 +8,7 @@ public interface IImplementerLogic { List? ReadList(ImplementerSearchModel? model); ImplementerViewModel? ReadElement(ImplementerSearchModel model); - bool Create(ImplementerSearchModel model); - bool Update(ImplementerSearchModel model); - bool Delete(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/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs index dfa8020..1380aac 100644 --- a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -9,6 +9,6 @@ namespace SushiBarContracts.SearchModels public DateTime? DateTo { get; set; } public int? ClientId { get; set; } public int? ImplementerId { get; set; } - public OrderStatus Status { get; set; } + public List Status { get; set; } } } diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index 2a55c2e..5a0d8e7 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -11,7 +11,7 @@ namespace SushiBarContracts.ViewModels public int SushiId { get; init; } public int ClientId { get; init; } - public int ImplementerId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Client FIO")] public string ClientFio { get; init; } = string.Empty; diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index 1772725..ec2ff33 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -4,6 +4,7 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDatabaseImplement.Models; +using SushiBarDataModels.Enums; namespace SushiBarDatabaseImplement.Implements { @@ -33,30 +34,52 @@ namespace SushiBarDatabaseImplement.Implements using var context = new SushiBarDatabase(); return context.Orders - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Status == null || model.Status != null && model.Status.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id + ) + ?.GetViewModel; } public List GetFilteredList(OrderSearchModel? model) { - if (model is null) - return new List(); - - using var context = new SushiBarDatabase(); - if (model.ClientId.HasValue) + if (model.Id.HasValue) { - return context.Orders - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); + var result = GetElement(model); + return result != null ? new() { result } : new(); } - return context.Orders - .Include(x => x.Sushi) - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + using var context = new SushiBarDatabase(); + IQueryable? queryWhere = null; + + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + queryWhere = context.Orders + .Where(x => model.DateFrom <= x.DateCreate.Date && + x.DateCreate.Date <= model.DateTo); + } + else if (model.Status != null) + { + queryWhere = context.Orders + .Where(x => model.Status.Contains(x.Status)); + } + else if (model.ClientId.HasValue) + { + queryWhere = context.Orders + .Where(x => x.ClientId == model.ClientId); + } + else + { + return new(); + } + return queryWhere + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.Designer.cs new file mode 100644 index 0000000..88a6326 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.Designer.cs @@ -0,0 +1,251 @@ +// +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("20230410100751_lab6")] + partial class lab6 + { + /// + 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.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + 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.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.Property("SushiName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + 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("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("SushiId"); + + b.ToTable("SushiComponents"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") + .WithMany() + .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.SushiComponent", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component") + .WithMany("SushiComponent") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Components") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => + { + b.Navigation("SushiComponent"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.cs new file mode 100644 index 0000000..4bde589 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + /// + public partial class lab6 : 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/SushiDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiDatabaseModelSnapshot.cs index 71843f6..5b4af9c 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("Components"); }); + 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.Order", 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"); @@ -104,6 +134,8 @@ namespace SushiBarDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("SushiId"); b.ToTable("Orders"); @@ -163,6 +195,10 @@ namespace SushiBarDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") + .WithMany() + .HasForeignKey("ImplementerId"); + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") .WithMany("Orders") .HasForeignKey("SushiId") @@ -171,6 +207,8 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Sushi"); }); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index 772e110..ed432af 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -15,7 +15,7 @@ namespace SushiBarDatabaseImplement.Models [Required] public int ClientId { get; private set; } - public int ImplementerId { get; private set; } + public int? ImplementerId { get; private set; } = null; public string SushiName { get; set; } = string.Empty; @@ -95,7 +95,7 @@ namespace SushiBarDatabaseImplement.Models Status = Status, ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty, SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty, - ImplementerFio = Implementer?.ImplementerFio ?? string.Empty + ImplementerFio = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFio ?? string.Empty, }; } } } diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index 91213c5..0217513 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -12,7 +12,7 @@ namespace SushiBarFileImplement.Models public string SushiName { get; private set; } = string.Empty; public int SushiId { get; private set; } public int ClientId { get; } - public int ImplementerId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Unknown; -- 2.25.1 From 90526748c53070c03bd9d109c44c57f8f7a6d4bc Mon Sep 17 00:00:00 2001 From: Viltskaa Date: Tue, 11 Apr 2023 08:52:16 +0400 Subject: [PATCH 4/4] complete lab --- .../SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs index a9a3f42..b861cba 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs @@ -63,12 +63,13 @@ public class WorkModeling : IWorkProcess Id = order.Id, ImplementerId = implementer.Id }); - Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + Thread.Sleep(implementer.WorkExperience * _rnd.Next(10, 100) * order.Count); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); - _orderLogic.FinishOrder(new OrderBindingModel + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = order.Id }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } catch (InvalidOperationException ex) { @@ -79,7 +80,6 @@ public class WorkModeling : IWorkProcess _logger.LogError(ex, "Error while do work"); throw; } - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } }); } -- 2.25.1