From f84dc1ad42c3dcd382731d5f94e8a3ace417aaa1 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Mon, 3 Apr 2023 17:46:11 +0400 Subject: [PATCH] lab 6 --- .../DataFileSingleton.cs | 14 +- .../Implementer.cs | 82 ++++++++++++ .../ImplementerStorage.cs | 90 +++++++++++++ .../Order.cs | 24 ++-- .../OrderStorage.cs | 29 +++- .../BusinessLogic/ImplementerLogic.cs | 124 ++++++++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 20 +++ .../BindingModels/OrderBindingModel.cs | 3 +- .../IImplementerLogic.cs | 19 +++ .../BusinessLogicsContracts/IOrderLogic.cs | 3 +- .../SearchModels/ImplementerSearchModel.cs | 11 ++ .../SearchModels/OrderSearchModel.cs | 8 +- .../StoragesContracts/IImplementerStorage.cs | 21 +++ .../ViewModels/ImplementerViewModel.cs | 25 ++++ .../ViewModels/OrderViewModel.cs | 7 +- .../IImplementerModel.cs | 10 ++ .../IOrderModel.cs | 3 +- .../Implementer.cs | 60 +++++++++ .../ImplementerStorage.cs | 90 +++++++++++++ .../Order.cs | 22 +++- .../OrderStorage.cs | 81 +++++++----- .../SoftwareInstallationDatabase.cs | 3 +- .../DataListSingleton.cs | 8 +- .../Implementer.cs | 55 ++++++++ .../ImplementerStorage.cs | 114 ++++++++++++++++ .../Order.cs | 16 ++- .../OrderStorage.cs | 21 ++- .../Controllers/ImplementerController.cs | 107 +++++++++++++++ 28 files changed, 993 insertions(+), 77 deletions(-) create mode 100644 SoftwareInstallation/SoftWareInstallationFileImplement/Implementer.cs create mode 100644 SoftwareInstallation/SoftWareInstallationFileImplement/ImplementerStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ImplementerLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/IImplementerModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implementer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDatabaseImplement/ImplementerStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/Implementer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/ImplementerStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs index cb8a1ce..c8fafc4 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs @@ -10,12 +10,14 @@ namespace SoftwareInstallationFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PackageFileName = "Package.xml"; private readonly string ClientFileName = "Client.xml"; - public List Components { get; private set; } + private readonly string ImplementerFileName = "Implementer.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Packages { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } - public static DataFileSingleton GetInstance() + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -27,15 +29,17 @@ namespace SoftwareInstallationFileImplement public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement); - private DataFileSingleton() + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; - } - private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) { diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/Implementer.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/Implementer.cs new file mode 100644 index 0000000..a565848 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/Implementer.cs @@ -0,0 +1,82 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/ImplementerStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/ImplementerStorage.cs new file mode 100644 index 0000000..666d4a1 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/ImplementerStorage.cs @@ -0,0 +1,90 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; + +namespace SoftwareInstallationFileImplement +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) + return _source.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + if (model.ImplementerFIO != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs index 6aa2a01..f6414ef 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs @@ -12,7 +12,9 @@ namespace SoftwareInstallationFileImplement.Models public int ClientId { get; set; } - public int Count { get; private set; } + public int? ImplementerId { get; set; } + + public int Count { get; private set; } public double Sum { get; private set; } @@ -39,7 +41,8 @@ namespace SoftwareInstallationFileImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - Id = model.Id, + ImplementerId = model.ImplementerId, + Id = model.Id, }; } @@ -59,7 +62,8 @@ namespace SoftwareInstallationFileImplement.Models PackageId = Convert.ToInt32(element.Element("PackageId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), + DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement), }; } @@ -71,9 +75,11 @@ namespace SoftwareInstallationFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - } + //ToDo + ImplementerId = model.ImplementerId; + } - public OrderViewModel GetViewModel => new() + public OrderViewModel GetViewModel => new() { PackageName = DataFileSingleton.GetInstance().Packages.FirstOrDefault(x => x.Id == PackageId)?.PackageName ?? string.Empty, ClientFIO = DataFileSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, @@ -84,7 +90,8 @@ namespace SoftwareInstallationFileImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - Id = Id, + ImplementerId = ImplementerId, + Id = Id, }; public XElement GetXElement => new("Order", new XAttribute("Id", Id), @@ -94,7 +101,8 @@ namespace SoftwareInstallationFileImplement.Models new XElement("Sum", Sum.ToString()), new XElement("Status", (int)Status), new XElement("DateCreate", DateCreate), - new XElement("DateImplement", DateImplement) - ); + new XElement("DateImplement", DateImplement), + new XElement("ImplementerId", ImplementerId) + ); } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs index 3f64066..0ed354f 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs @@ -26,12 +26,20 @@ namespace SoftwareInstallationFileImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return null; - } - return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; - } + if (model.ImplementerId.HasValue && model.Statusses != null) + { + return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && model.Statusses.Contains(x.Status))?.GetViewModel; + } + if (model.ImplementerId.HasValue) + { + return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel; + } + if (!model.Id.HasValue) + { + return null; + } + return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } public List GetFilteredList(OrderSearchModel model) { if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по айдишнику, значит ищем по диапазону дат @@ -48,7 +56,14 @@ namespace SoftwareInstallationFileImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - var result = GetElement(model); + if (!model.Id.HasValue && model.Statusses != null) + { + return _source.Orders + .Where(x => model.Statusses.Contains(x.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } + var result = GetElement(model); return result != null ? new() { result } : new(); } public List GetFullList() diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ImplementerLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..4e0af59 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,124 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationBusinessLogic +{ + 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/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..7a6f0bc --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,20 @@ +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs index 757b268..5483aaf 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs @@ -8,7 +8,8 @@ namespace SoftwareInstallationContracts.BindingModels public int Id { get; set; } public int PackageId { get; set; } public int ClientId { get; set; } - public int Count { get; set; } + public int? ImplementerId { get; set; } + public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..73afab9 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs index 49c13ab..498a3e8 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,7 +7,8 @@ namespace SoftwareInstallationContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); - bool CreateOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..1607f8a --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace SoftwareInstallationContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs index 8b645da..81f9015 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,6 @@ -namespace SoftwareInstallationContracts.SearchModels +using SoftwareInstallationDataModels.Enums; + +namespace SoftwareInstallationContracts.SearchModels { public class OrderSearchModel { @@ -6,5 +8,7 @@ public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } - } + public int? ImplementerId { get; set; } + public List? Statusses { get; set; } + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..5bba6a8 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..6675473 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,25 @@ +using SoftwareInstallationDataModels.Models; +using System.ComponentModel; + +namespace SoftwareInstallationContracts.ViewModels +{ + /// + /// Исполнитель, выполняющий заказы + /// + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs index 092ad83..89db922 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -11,9 +11,12 @@ namespace SoftwareInstallationContracts.ViewModels public int Id { get; set; } public int PackageId { get; set; } public int ClientId { get; set; } - [DisplayName("Фамилия клиента")] + public int? ImplementerId { get; set; } + [DisplayName("Фамилия клиента")] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Изделие")] + [DisplayName("Фамилия исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Изделие")] public string PackageName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IImplementerModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IImplementerModel.cs new file mode 100644 index 0000000..52af76c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IImplementerModel.cs @@ -0,0 +1,10 @@ +namespace SoftwareInstallationDataModels.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/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs index 2eb9b8e..d4a7a73 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs @@ -6,7 +6,8 @@ namespace SoftwareInstallationDataModels.Models { int PackageId { get; } int Count { get; } - double Sum { get; } + int? ImplementerId { get; } + double Sum { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implementer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implementer.cs new file mode 100644 index 0000000..022de2a --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implementer.cs @@ -0,0 +1,60 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SoftwareInstallationDatabaseImplement.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; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/ImplementerStorage.cs new file mode 100644 index 0000000..cedd5f5 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/ImplementerStorage.cs @@ -0,0 +1,90 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDatabaseImplement.Models; + +namespace SoftwareInstallationDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new SoftwareInstallationDatabase(); + if (model.Id.HasValue) + return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + if (model.ImplementerFIO != null) + return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально) + { + using var context = new SoftwareInstallationDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new SoftwareInstallationDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDatabase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs index efcf9a0..fdff054 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs @@ -15,8 +15,10 @@ namespace SoftwareInstallationDatabaseImplement.Models [Required] public int ClientId { get; private set; } + + public int? ImplementerId { get; private set; } - [Required] + [Required] public int Count { get; private set; } [Required] @@ -34,7 +36,9 @@ namespace SoftwareInstallationDatabaseImplement.Models public Client Client { get; private set; } - public static Order? Create(OrderBindingModel? model) + public Implementer? Implementer { get; private set; } + + public static Order? Create(OrderBindingModel? model) { if (model == null) { @@ -48,7 +52,8 @@ namespace SoftwareInstallationDatabaseImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId, + DateImplement = model.DateImplement, Id = model.Id, }; } @@ -65,7 +70,8 @@ namespace SoftwareInstallationDatabaseImplement.Models Status = model.Status; DateCreate = model.DateCreate; DateImplement = model.DateImplement; - Id = model.Id; + ImplementerId = model.ImplementerId; + Id = model.Id; } public OrderViewModel GetViewModel { @@ -77,15 +83,17 @@ namespace SoftwareInstallationDatabaseImplement.Models PackageName = Package?.PackageName ?? string.Empty, ClientId = ClientId, ClientFIO = Client?.ClientFIO ?? string.Empty, - PackageId = PackageId, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, + PackageId = PackageId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - Id = Id, + ImplementerId = ImplementerId, + Id = Id, }; } } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs index 5ce6049..ef0c0e6 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs @@ -12,7 +12,10 @@ namespace SoftwareInstallationDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new SoftwareInstallationDatabase(); - var element = context.Orders.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); + var element = context.Orders + .Include(x => x.Implementer) + .Include(x => x.Client) + .FirstOrDefault(x => x.Id == model.Id); if (element != null) { context.Orders.Remove(element); @@ -29,46 +32,56 @@ namespace SoftwareInstallationDatabaseImplement.Implements { return null; } - return context.Orders - .Include(x => x.Client) - .Include(x => x.Package) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; - } + return context.Orders + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Statusses == null || model.Statusses != null && model.Statusses.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.Id.HasValue) - { - var result = GetElement(model); - return result != null ? new() { result } : new(); - } - using var context = new SoftwareInstallationDatabase(); - if (model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по айдишнику, значит ищем по диапазону дат - { - return context.Orders - .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo) - .Include(x => x.Client) - .Include(x => x.Package) + if (model.Id.HasValue) + { + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + + using var context = new SoftwareInstallationDatabase(); + 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.Statusses != null) + { + queryWhere = context.Orders.Where(x => model.Statusses.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(); - } - if (model.ClientId.HasValue) - { - return context.Orders - .Where(x => x.Client.Id == model.ClientId) - .Include(x => x.Client) - .Include(x => x.Package) - .Select(x => x.GetViewModel) - .ToList(); - } - return new(); - } + .ToList(); + } public List GetFullList() { using var context = new SoftwareInstallationDatabase(); return context.Orders .Include(x => x.Client) + .Include(x => x.Implementer) .Include(x => x.Package) .Select(x => x.GetViewModel) .ToList(); @@ -90,7 +103,11 @@ namespace SoftwareInstallationDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { using var context = new SoftwareInstallationDatabase(); - var order = context.Orders.Include(x => x.Client).Include(x => x.Package).FirstOrDefault(x => x.Id == model.Id); + var order = context.Orders + .Include(x => x.Client) + .Include(x => x.Implementer) + .Include(x => x.Package) + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs index 1f2d556..16c2e57 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs @@ -24,5 +24,6 @@ namespace SoftwareInstallationDatabaseImplement public virtual DbSet PackageComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } - } + public virtual DbSet Implementers { set; get; } + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs index 54e2975..17e887c 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs @@ -9,14 +9,16 @@ namespace SoftwareInstallationListImplement public List Orders { get; set; } public List Packages { get; set; } public List Clients { get; set; } - private DataListSingleton() + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Packages = new List(); Clients = new List(); - } - public static DataListSingleton GetInstance() + Implementers = new List(); + } + public static DataListSingleton GetInstance() { if (_instance == null) { diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implementer.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implementer.cs new file mode 100644 index 0000000..120ce0c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implementer.cs @@ -0,0 +1,55 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationListImplement +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/ImplementerStorage.cs new file mode 100644 index 0000000..edab5be --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/ImplementerStorage.cs @@ -0,0 +1,114 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using System.Collections.Generic; + +namespace SoftwareInstallationListImplement +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var 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 == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + // На случай если при расширении проекта фио не будет уникальным + // (по заданию оно уникально) + List result = new(); + if (model.ImplementerFIO != null) + { + 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; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs index b0a7dea..d5f1a38 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs @@ -11,7 +11,9 @@ namespace SoftwareInstallationListImplement.Models public int ClientId { get; private set; } - public int Count { get; private set; } + public int? ImplementerId { get; private set; } + + public int Count { get; private set; } public double Sum { get; private set; } @@ -38,7 +40,8 @@ namespace SoftwareInstallationListImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - Id = model.Id, + ImplementerId = model.ImplementerId, + Id = model.Id, }; } @@ -51,13 +54,16 @@ namespace SoftwareInstallationListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - } + ImplementerId = model.ImplementerId; + } - public OrderViewModel GetViewModel => new() + public OrderViewModel GetViewModel => new() { PackageId = PackageId, ClientId = ClientId, - Count = Count, + ImplementerId = ImplementerId, + ImplementerFIO = DataListSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, + Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs index 838ca5f..91b4b27 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs @@ -38,7 +38,16 @@ namespace SoftwareInstallationListImplement.Implements { return order.GetViewModel; } - } + else if (model.ImplementerId.HasValue && model.Statusses != null && + order.ImplementerId == model.ImplementerId && model.Statusses.Contains(order.Status)) + { + return GetViewModel(order); + } + else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId) + { + return GetViewModel(order); + } + } return null; } public List GetFilteredList(OrderSearchModel model) @@ -59,7 +68,15 @@ namespace SoftwareInstallationListImplement.Implements { result.Add(GetViewModel(order)); } - } + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + else if (model.Statusses != null && model.Statusses.Contains(order.Status)) + { + result.Add(GetViewModel(order)); + } + } return result; } public List GetFullList() diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..0c4fe2e --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace SoftwareInstallationRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Statusses = new() { OrderStatus.Принят } + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } + } + } +} \ No newline at end of file