From 284cab6b4492fa3b960177d7dd015f534a5f8cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B0=D1=82=20=D0=97=D0=B0=D1=80=D0=B3?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Sun, 14 May 2023 22:04:12 +0400 Subject: [PATCH] Implementers --- .../PizzeriaBusinessLogic/ImplementerLogic.cs | 128 +++++++++ Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs | 30 +- .../PizzeriaBusinessLogic/WorkModeling.cs | 149 ++++++++++ .../BindingModels/ImplementerBindingModel.cs | 22 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 24 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 13 + .../SearchModels/ImplementerSearchModel.cs | 18 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StorageContracts/IImplementerStorage.cs | 26 ++ .../ViewModels/ImplementerViewModel.cs | 27 ++ .../ViewModels/OrderViewModel.cs | 14 +- .../Models/IImplementerModel.cs | 16 ++ .../PizzeriaDataModels/Models/IOrderModel.cs | 1 + .../Implements/ImplementerStorage.cs | 84 ++++++ .../Implements/OrderStorage.cs | 26 +- ...14173304_ImplementersMigration.Designer.cs | 257 ++++++++++++++++++ .../20230514173304_ImplementersMigration.cs | 67 +++++ .../PizzeriaDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 70 +++++ .../PizzeriaDatabaseImplement/Models/Order.cs | 14 +- .../PizzeriaDatabase.cs | 1 + .../DataFileSingleton.cs | 4 + .../Implements/ImplementerStorage.cs | 92 +++++++ .../Implements/OrderStorage.cs | 18 +- .../Models/Implementer.cs | 85 ++++++ .../PizzeriaFileImplement/Models/Order.cs | 7 + .../DataListSingleton.cs | 1 + .../Implements/ImplementerStorage.cs | 114 ++++++++ .../Implements/OrderStorage.cs | 24 +- .../Models/Implementer.cs | 57 ++++ .../PizzeriaListImplement/Models/Order.cs | 7 + .../Controllers/ImplementerController.cs | 104 +++++++ Pizzeria/PizzeriaRestApi/Program.cs | 3 + .../PizzeriaView/FormCreateOrder.Designer.cs | 42 ++- Pizzeria/PizzeriaView/FormCreateOrder.cs | 34 ++- .../PizzeriaView/FormImplementer.Designer.cs | 167 ++++++++++++ Pizzeria/PizzeriaView/FormImplementer.cs | 99 +++++++ Pizzeria/PizzeriaView/FormImplementer.resx | 60 ++++ .../PizzeriaView/FormImplementers.Designer.cs | 130 +++++++++ Pizzeria/PizzeriaView/FormImplementers.cs | 112 ++++++++ Pizzeria/PizzeriaView/FormImplementers.resx | 60 ++++ Pizzeria/PizzeriaView/FormMain.Designer.cs | 84 +++--- Pizzeria/PizzeriaView/FormMain.cs | 70 ++--- Pizzeria/PizzeriaView/Program.cs | 6 + 46 files changed, 2275 insertions(+), 142 deletions(-) create mode 100644 Pizzeria/PizzeriaBusinessLogic/ImplementerLogic.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/WorkModeling.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/StorageContracts/IImplementerStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IImplementerModel.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.Designer.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs create mode 100644 Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs create mode 100644 Pizzeria/PizzeriaFileImplement/Models/Implementer.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/ImplementerStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Implementer.cs create mode 100644 Pizzeria/PizzeriaRestApi/Controllers/ImplementerController.cs create mode 100644 Pizzeria/PizzeriaView/FormImplementer.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormImplementer.cs create mode 100644 Pizzeria/PizzeriaView/FormImplementer.resx create mode 100644 Pizzeria/PizzeriaView/FormImplementers.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormImplementers.cs create mode 100644 Pizzeria/PizzeriaView/FormImplementers.resx diff --git a/Pizzeria/PizzeriaBusinessLogic/ImplementerLogic.cs b/Pizzeria/PizzeriaBusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..3edf3f1 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/ImplementerLogic.cs @@ -0,0 +1,128 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж должен быть больше 0", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentNullException("Квалификация должна быть положительной", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}.Password:{Password}.WorkExperience:{WorkExperience}.Qualification:{Qualification}.Id: { Id}", + model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs index 7f173dc..e946b8b 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs @@ -17,6 +17,7 @@ namespace PizzeriaBusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object _locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; @@ -24,7 +25,8 @@ namespace PizzeriaBusinessLogic } public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + _logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { @@ -34,6 +36,24 @@ namespace PizzeriaBusinessLogic _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientId: {ClientId}. ImplementerId: {ImplementerId}. Status: {Status}. DateFrom: {DateFrom}. DateTo: {DateTo}. Id: {Id}", + model.ClientId, model.ImplementerId, model.Status, model.DateFrom, model.DateTo, 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) { CheckModel(model); @@ -49,7 +69,10 @@ namespace PizzeriaBusinessLogic } public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (_locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) { @@ -97,6 +120,9 @@ namespace PizzeriaBusinessLogic } model.DateCreate = element.DateCreate; model.PizzaId = element.PizzaId; + model.ClientId = element.ClientId; + if (!model.ImplementerId.HasValue) + model.ImplementerId = element.ImplementerId; model.DateImplement = element.DateImplement; model.Status = element.Status; model.Count = element.Count; diff --git a/Pizzeria/PizzeriaBusinessLogic/WorkModeling.cs b/Pizzeria/PizzeriaBusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..6874307 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/WorkModeling.cs @@ -0,0 +1,149 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic +{ + 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.Принят }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + /// + /// Иммитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ImplementerBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..d5a6e45 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.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; } + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs index 8664e57..3f98abf 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -12,6 +12,7 @@ namespace PizzeriaContracts.BindingModels public int Id { get; set; } public int ClientId { get; set; } public int PizzaId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IImplementerLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..b6855e1 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs index f95ecfa..9dff69b 100644 --- a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace PizzeriaContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IWorkProcess.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..7a04c31 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ImplementerSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..420c4f8 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,18 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs index 0ec719c..649e5e9 100644 --- a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs +++ b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using PizzeriaDataModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace PizzeriaContracts.SearchModels public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public OrderStatus? Status { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IImplementerStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IImplementerStorage.cs new file mode 100644 index 0000000..4137886 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.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); + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..8f5e29c --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.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; } + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index de806a5..6227699 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -12,21 +12,33 @@ namespace PizzeriaContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int ClientId { get; set; } [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + public string? ClientFIO { get; set; } = string.Empty; + public int PizzaId { get; set; } + [DisplayName("Изделие")] public string PizzaName { get; set; } = string.Empty; + + public int? ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string? ImplementerFIO { get; set; } = null; + [DisplayName("Количество")] public int Count { get; set; } + [DisplayName("Сумма")] public double Sum { get; set; } + [DisplayName("Статус")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } } diff --git a/Pizzeria/PizzeriaDataModels/Models/IImplementerModel.cs b/Pizzeria/PizzeriaDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..9c19d0f --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs index da2ca3c..7e5ea2c 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -10,6 +10,7 @@ namespace PizzeriaDataModels { int ClientId { get; } int PizzaId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/ImplementerStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..333cc5f --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new PizzeriaDatabase(); + var implementer = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (implementer != null) + { + context.Implementers.Remove(implementer); + context.SaveChanges(); + return implementer.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + using var context = new PizzeriaDatabase(); + return context.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && (!string.IsNullOrEmpty(model.Password) ? x.Password == model.Password : true)) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new PizzeriaDatabase(); + return context.Implementers.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new PizzeriaDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new PizzeriaDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new PizzeriaDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs index 1c1682a..bf78f04 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs @@ -5,6 +5,7 @@ using PizzeriaContracts.ViewModels; using PizzeriaDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; + namespace PizzeriaDatabaseImplement.Implements { public class OrderStorage : IOrderStorage @@ -12,31 +13,34 @@ namespace PizzeriaDatabaseImplement.Implements public List GetFullList() { using var context = new PizzeriaDatabase(); - return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Include(y => y.Implementer).Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) { using var context = new PizzeriaDatabase(); - if (model.DateFrom.HasValue) + if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) { - return context.Orders.Include(x => x.Pizza).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); + return new(); } - if (model.ClientId.HasValue) - { - return context.Orders.Include(x => x.Pizza).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); - } - return context.Orders.Include(x => x.Pizza).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Include(x => x.Implementer).Where(x => + (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) || + (model.ClientId.HasValue && x.ClientId == model.ClientId) || + (model.Status.HasValue && x.Status == model.Status)) + .Select(x => x.GetViewModel).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return new(); } using var context = new PizzeriaDatabase(); - return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status)) + ?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) @@ -62,7 +66,7 @@ namespace PizzeriaDatabaseImplement.Implements { return null; } - order.Update(model); + order.Update(context, model); context.SaveChanges(); return order.GetViewModel; } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.Designer.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.Designer.cs new file mode 100644 index 0000000..58ce229 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PizzeriaDatabaseImplement; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + [DbContext(typeof(PizzeriaDatabase))] + [Migration("20230514173304_ImplementersMigration")] + partial class ImplementersMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PizzeriaDatabaseImplement.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("PizzeriaDatabaseImplement.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("PizzeriaDatabaseImplement.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("PizzeriaDatabaseImplement.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("PizzaId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PizzaId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PizzaName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Pizzas"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PizzaId"); + + b.ToTable("PizzaComponents"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Client", "Client") + .WithMany("ClientOrders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PizzeriaDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany("Orders") + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Pizza"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Component", "Component") + .WithMany("PizzaComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany("Components") + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Pizza"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b => + { + b.Navigation("ClientOrders"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => + { + b.Navigation("PizzaComponents"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.cs new file mode 100644 index 0000000..cd1319a --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230514173304_ImplementersMigration.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + /// + public partial class ImplementersMigration : 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/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs index 85a6e87..8d0402e 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace PizzeriaDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PizzeriaDatabaseImplement.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("PizzeriaDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace PizzeriaDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("PizzaId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace PizzeriaDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("PizzaId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace PizzeriaDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PizzeriaDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") .WithMany("Orders") .HasForeignKey("PizzaId") @@ -167,6 +203,8 @@ namespace PizzeriaDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Pizza"); }); @@ -199,6 +237,11 @@ namespace PizzeriaDatabaseImplement.Migrations b.Navigation("PizzaComponents"); }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b => { b.Navigation("Components"); diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..3e5b372 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,70 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + [Required] + public string ImplementerFIO { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public int WorkExperience { get; set; } + + [Required] + public int Qualification { get; set; } + + [ForeignKey("ImplementerId")] + public virtual List Order { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs index 28327f3..da47c3d 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs @@ -1,4 +1,5 @@ -using PizzeriaContracts.BindingModels; +using DocumentFormat.OpenXml.InkML; +using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; using PizzeriaDataModels; using System; @@ -22,6 +23,9 @@ namespace PizzeriaDatabaseImplement.Models public int PizzaId { get; private set; } public virtual Pizza Pizza { get; set; } = new(); + public int? ImplementerId { get; private set; } + + public virtual Implementer? Implementer { get; set; } = new(); [Required] public int Count { get; private set; } @@ -46,6 +50,8 @@ namespace PizzeriaDatabaseImplement.Models Client = context.Clients.First(x => model.ClientId == x.Id), PizzaId = model.PizzaId, Pizza = context.Pizzas.First(x => x.Id == model.PizzaId), + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -54,7 +60,7 @@ namespace PizzeriaDatabaseImplement.Models }; } - public void Update(OrderBindingModel? model) + public void Update(PizzeriaDatabase context, OrderBindingModel? model) { if (model == null) { @@ -62,6 +68,8 @@ namespace PizzeriaDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null; } public OrderViewModel GetViewModel => new() @@ -71,6 +79,8 @@ namespace PizzeriaDatabaseImplement.Models ClientFIO = Client.ClientFIO, PizzaId = PizzaId, PizzaName = Pizza.PizzaName, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, Count = Count, Sum = Sum, Status = Status, diff --git a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs index e9e02df..b16f311 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs @@ -15,6 +15,7 @@ namespace PizzeriaDatabaseImplement base.OnConfiguring(optionsBuilder); } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } public virtual DbSet Components { set; get; } public virtual DbSet Pizzas { set; get; } public virtual DbSet PizzaComponents { set; get; } diff --git a/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs b/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs index 1a8591c..0f38edb 100644 --- a/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs +++ b/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs @@ -10,10 +10,12 @@ namespace PizzeriaFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PizzaFileName = "Pizza.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Pizzas { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -26,12 +28,14 @@ namespace PizzeriaFileImplement public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs b/Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..538e0f2 --- /dev/null +++ b/Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,92 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaFileImplement.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 (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return null; + } + return source.Implementers + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && + !string.IsNullOrEmpty(model.Password) && x.Password == model.Password)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs index 453253d..3c21a87 100644 --- a/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs @@ -16,19 +16,24 @@ namespace PizzeriaFileImplement.Implements public List GetFullList() => source.Orders.Select(x => AttachOthersNames(x.GetViewModel)).ToList(); public List GetFilteredList(OrderSearchModel model) { - if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue) + if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) { return new(); } - return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => AttachOthersNames(x.GetViewModel)).ToList(); + return source.Orders.Where(x => (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) || + (model.ClientId.HasValue && x.ClientId == model.ClientId) || + (model.Status.HasValue && x.Status == model.Status)).Select(x => AttachOthersNames(x.GetViewModel)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return new(); } - return AttachOthersNames(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); + return AttachOthersNames(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || + (model.ClientId.HasValue && x.Id == model.ClientId) || + (model.ImplementerId.HasValue && x.Id == model.ImplementerId && x.Status == model.Status))? + .GetViewModel); } public OrderViewModel? Insert(OrderBindingModel model) { @@ -70,12 +75,17 @@ namespace PizzeriaFileImplement.Implements { return null; } + var implementerFIO = source.Implementers.FirstOrDefault(x => model.ImplementerId == x.Id)?.ImplementerFIO; var clientFIO = source.Clients.FirstOrDefault(x => model.ClientId == x.Id)?.ClientFIO; var pizza = source.Pizzas.FirstOrDefault(x => x.Id == model.PizzaId); if (clientFIO != null) { model.ClientFIO = clientFIO; } + if (implementerFIO != null) + { + model.ImplementerFIO = implementerFIO; + } if (pizza != null) { model.PizzaName = pizza.PizzaName; diff --git a/Pizzeria/PizzeriaFileImplement/Models/Implementer.cs b/Pizzeria/PizzeriaFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..939f9e7 --- /dev/null +++ b/Pizzeria/PizzeriaFileImplement/Models/Implementer.cs @@ -0,0 +1,85 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PizzeriaFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("Cost")!.Value), + Qualification = Convert.ToInt32(element.Element("Cost")!.Value) + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification)); + } +} diff --git a/Pizzeria/PizzeriaFileImplement/Models/Order.cs b/Pizzeria/PizzeriaFileImplement/Models/Order.cs index fc406dc..adf7287 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Order.cs @@ -10,6 +10,7 @@ namespace PizzeriaFileImplement.Models public int Id { get; private set; } public int ClientId { get; private set; } public int PizzaId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -26,6 +27,7 @@ namespace PizzeriaFileImplement.Models Id = model.Id, ClientId = model.ClientId, PizzaId = model.PizzaId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -45,6 +47,7 @@ namespace PizzeriaFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), ClientId= Convert.ToInt32(element.Attribute("ClientId")!.Value), PizzaId = Convert.ToInt32(element.Element("PizzaId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), @@ -59,6 +62,7 @@ namespace PizzeriaFileImplement.Models { return; } + ImplementerId = model.ImplementerId; Status = model.Status; if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; } @@ -67,6 +71,7 @@ namespace PizzeriaFileImplement.Models Id = Id, ClientId = ClientId, PizzaId = PizzaId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -78,10 +83,12 @@ namespace PizzeriaFileImplement.Models new XAttribute("Id", Id), new XElement("ClientId",ClientId.ToString()), new XElement("PizzaId", PizzaId.ToString()), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString())); + } } diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs index cb6a75e..55be7db 100644 --- a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -14,6 +14,7 @@ namespace PizzeriaListImplement public List Orders { get; set; } public List Pizzas { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); diff --git a/Pizzeria/PizzeriaListImplement/Implements/ImplementerStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..55dd0fc --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,114 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return null; + } + foreach (var implementer in _source.Implementers) + { + if ((model.Id.HasValue && implementer.Id == model.Id) || + (!string.IsNullOrEmpty(model.ImplementerFIO) && implementer.ImplementerFIO == model.ImplementerFIO && + !string.IsNullOrEmpty(model.Password) && implementer.Password == model.Password)) + { + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + + 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; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs index eb8b441..bc86b15 100644 --- a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -30,14 +30,15 @@ namespace PizzeriaListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue) + if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) { return result; } foreach (var order in _source.Orders) { if ((model.DateFrom.HasValue && model.DateTo.HasValue && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) || - (model.ClientId.HasValue && order.ClientId == model.ClientId)) + (model.ClientId.HasValue && order.ClientId == model.ClientId) || + (model.Status.HasValue && order.Status == model.Status)) { result.Add(AttachOthersNames(order.GetViewModel)); } @@ -47,13 +48,14 @@ namespace PizzeriaListImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return null; } foreach (var order in _source.Orders) { - if (model.Id.HasValue && order.Id == model.Id) + if ((model.Id.HasValue && order.Id == model.Id) || + (model.ImplementerId.HasValue && order.Id == model.ImplementerId && order.Status == model.Status)) { return AttachOthersNames(order.GetViewModel); } @@ -106,11 +108,19 @@ namespace PizzeriaListImplement.Implements } private OrderViewModel AttachOthersNames(OrderViewModel model) { - foreach (var order in _source.Clients) + foreach (var implementer in _source.Implementers) { - if (model.ClientId == order.Id) + if (model.ImplementerId == implementer.Id) { - model.ClientFIO = order.ClientFIO; + model.ImplementerFIO = implementer.ImplementerFIO; + break; + } + } + foreach (var client in _source.Clients) + { + if (model.ClientId == client.Id) + { + model.ClientFIO = client.ClientFIO; break; } } diff --git a/Pizzeria/PizzeriaListImplement/Models/Implementer.cs b/Pizzeria/PizzeriaListImplement/Models/Implementer.cs new file mode 100644 index 0000000..170bfe2 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Implementer.cs @@ -0,0 +1,57 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; private set; } = string.Empty; + public int WorkExperience { get; private set; } + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs index 553c08a..73a6073 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -4,6 +4,7 @@ using PizzeriaDataModels; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -14,6 +15,7 @@ namespace PizzeriaListImplement.Models public int Id { get; private set; } public int ClientId { get; private set; } public int PizzaId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -30,6 +32,7 @@ namespace PizzeriaListImplement.Models Id = model.Id, ClientId = model.ClientId, PizzaId = model.PizzaId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -44,6 +47,8 @@ namespace PizzeriaListImplement.Models return; } Status = model.Status; + ImplementerId = model.ImplementerId; + DateImplement = model.DateImplement; if (model.DateImplement.HasValue) DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() @@ -51,11 +56,13 @@ namespace PizzeriaListImplement.Models Id = Id, ClientId = ClientId, PizzaId = PizzaId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, }; + } } diff --git a/Pizzeria/PizzeriaRestApi/Controllers/ImplementerController.cs b/Pizzeria/PizzeriaRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..6241937 --- /dev/null +++ b/Pizzeria/PizzeriaRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,104 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels; + +namespace PizzeriaRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, + ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + throw; + } + } + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", + model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с№{ Id}", model.Id); + throw; + } + } + } + +} diff --git a/Pizzeria/PizzeriaRestApi/Program.cs b/Pizzeria/PizzeriaRestApi/Program.cs index 007ae25..5304781 100644 --- a/Pizzeria/PizzeriaRestApi/Program.cs +++ b/Pizzeria/PizzeriaRestApi/Program.cs @@ -2,6 +2,7 @@ using Microsoft.OpenApi.Models; using PizzeriaBusinessLogic; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.StoragesContracts; using PizzeriaDatabaseImplement.Implements; var builder = WebApplication.CreateBuilder(args); @@ -14,10 +15,12 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/Pizzeria/PizzeriaView/FormCreateOrder.Designer.cs b/Pizzeria/PizzeriaView/FormCreateOrder.Designer.cs index 788c6ab..5de4a20 100644 --- a/Pizzeria/PizzeriaView/FormCreateOrder.Designer.cs +++ b/Pizzeria/PizzeriaView/FormCreateOrder.Designer.cs @@ -36,12 +36,14 @@ this.textBoxSum = new System.Windows.Forms.TextBox(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); + this.comboBoxClient = new System.Windows.Forms.ComboBox(); + this.labelClient = new System.Windows.Forms.Label(); this.SuspendLayout(); // // labelPizza // this.labelPizza.AutoSize = true; - this.labelPizza.Location = new System.Drawing.Point(10, 11); + this.labelPizza.Location = new System.Drawing.Point(7, 68); this.labelPizza.Name = "labelPizza"; this.labelPizza.Size = new System.Drawing.Size(43, 15); this.labelPizza.TabIndex = 0; @@ -50,7 +52,7 @@ // comboBoxPizza // this.comboBoxPizza.FormattingEnabled = true; - this.comboBoxPizza.Location = new System.Drawing.Point(101, 9); + this.comboBoxPizza.Location = new System.Drawing.Point(98, 66); this.comboBoxPizza.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.comboBoxPizza.Name = "comboBoxPizza"; this.comboBoxPizza.Size = new System.Drawing.Size(314, 23); @@ -60,7 +62,7 @@ // labelCount // this.labelCount.AutoSize = true; - this.labelCount.Location = new System.Drawing.Point(10, 37); + this.labelCount.Location = new System.Drawing.Point(7, 94); this.labelCount.Name = "labelCount"; this.labelCount.Size = new System.Drawing.Size(78, 15); this.labelCount.TabIndex = 2; @@ -68,7 +70,7 @@ // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(101, 34); + this.textBoxCount.Location = new System.Drawing.Point(98, 91); this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxCount.Name = "textBoxCount"; this.textBoxCount.Size = new System.Drawing.Size(314, 23); @@ -78,7 +80,7 @@ // labelSum // this.labelSum.AutoSize = true; - this.labelSum.Location = new System.Drawing.Point(10, 60); + this.labelSum.Location = new System.Drawing.Point(7, 117); this.labelSum.Name = "labelSum"; this.labelSum.Size = new System.Drawing.Size(51, 15); this.labelSum.TabIndex = 4; @@ -86,7 +88,7 @@ // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(101, 60); + this.textBoxSum.Location = new System.Drawing.Point(98, 117); this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxSum.Name = "textBoxSum"; this.textBoxSum.ReadOnly = true; @@ -95,7 +97,7 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(295, 85); + this.buttonCancel.Location = new System.Drawing.Point(292, 142); this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(96, 24); @@ -106,7 +108,7 @@ // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(193, 85); + this.buttonSave.Location = new System.Drawing.Point(190, 142); this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(96, 24); @@ -115,11 +117,31 @@ this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // + // comboBoxClient + // + this.comboBoxClient.FormattingEnabled = true; + this.comboBoxClient.Location = new System.Drawing.Point(98, 39); + this.comboBoxClient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxClient.Name = "comboBoxClient"; + this.comboBoxClient.Size = new System.Drawing.Size(314, 23); + this.comboBoxClient.TabIndex = 8; + // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(7, 42); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(46, 15); + this.labelClient.TabIndex = 9; + this.labelClient.Text = "Клиент"; + // // FormCreateOrder // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(424, 118); + this.ClientSize = new System.Drawing.Size(424, 189); + this.Controls.Add(this.labelClient); + this.Controls.Add(this.comboBoxClient); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.textBoxSum); @@ -147,5 +169,7 @@ private TextBox textBoxSum; private Button buttonCancel; private Button buttonSave; + private ComboBox comboBoxClient; + private Label labelClient; } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormCreateOrder.cs b/Pizzeria/PizzeriaView/FormCreateOrder.cs index 1acb535..8edcaa3 100644 --- a/Pizzeria/PizzeriaView/FormCreateOrder.cs +++ b/Pizzeria/PizzeriaView/FormCreateOrder.cs @@ -23,36 +23,48 @@ namespace PizzeriaView private readonly ILogger _logger; private readonly IPizzaLogic _logicP; private readonly IOrderLogic _logicO; - private List? _list; - public FormCreateOrder(ILogger logger, IPizzaLogic logicP, IOrderLogic logicO) + private readonly IClientLogic _logicC; + private List? _listPizzas; + private List? _listClients; + public FormCreateOrder(ILogger logger, IPizzaLogic logicP, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicP = logicP; _logicO = logicO; + _logicC = logicC; } private void FormCreateOrder_Load(object sender, EventArgs e) { - _list = _logicP.ReadList(null); - if (_list != null) + _listPizzas = _logicP.ReadList(null); + if (_listPizzas != null) { comboBoxPizza.DisplayMember = "PizzaName"; comboBoxPizza.ValueMember = "Id"; - comboBoxPizza.DataSource = _list; + comboBoxPizza.DataSource = _listPizzas; comboBoxPizza.SelectedItem = null; _logger.LogInformation("Загрузка пиццы для заказа"); } + _listClients = _logicC.ReadList(null); + if (_listClients != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = _listClients; + comboBoxClient.SelectedItem = null; + _logger.LogInformation("Загрузка клиентов для заказа"); + } } private void CalcSum() { - if (comboBoxPizza.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + if (comboBoxPizza.SelectedValue != null && comboBoxClient.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) { try { - int id = Convert.ToInt32(comboBoxPizza.SelectedValue); + int idPizza = Convert.ToInt32(comboBoxPizza.SelectedValue); var Pizza = _logicP.ReadElement(new PizzaSearchModel { - Id = id + Id = idPizza }); int count = Convert.ToInt32(textBoxCount.Text); textBoxSum.Text = Math.Round(count * (Pizza?.Price ?? 0), 2).ToString(); @@ -85,11 +97,17 @@ namespace PizzeriaView MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Создание заказа"); try { var operationResult = _logicO.CreateOrder(new OrderBindingModel { + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) diff --git a/Pizzeria/PizzeriaView/FormImplementer.Designer.cs b/Pizzeria/PizzeriaView/FormImplementer.Designer.cs new file mode 100644 index 0000000..3653547 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormImplementer.Designer.cs @@ -0,0 +1,167 @@ +namespace PizzeriaView +{ + 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.textBoxFIO = new System.Windows.Forms.TextBox(); + this.labelFIO = new System.Windows.Forms.Label(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.labelPassword = new System.Windows.Forms.Label(); + this.labelWorkExperience = new System.Windows.Forms.Label(); + this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.labelQualification = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + this.SuspendLayout(); + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(157, 12); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(382, 27); + this.textBoxFIO.TabIndex = 3; + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(12, 15); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(139, 20); + this.labelFIO.TabIndex = 2; + this.labelFIO.Text = "ФИО исполнителя:"; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(157, 50); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(205, 27); + this.textBoxPassword.TabIndex = 5; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(12, 53); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(65, 20); + this.labelPassword.TabIndex = 4; + this.labelPassword.Text = "Пароль:"; + // + // labelWorkExperience + // + this.labelWorkExperience.AutoSize = true; + this.labelWorkExperience.Location = new System.Drawing.Point(12, 99); + this.labelWorkExperience.Name = "labelWorkExperience"; + this.labelWorkExperience.Size = new System.Drawing.Size(105, 20); + this.labelWorkExperience.TabIndex = 6; + this.labelWorkExperience.Text = "Опыт работы:"; + // + // numericUpDownWorkExperience + // + this.numericUpDownWorkExperience.Location = new System.Drawing.Point(157, 97); + this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + this.numericUpDownWorkExperience.Size = new System.Drawing.Size(124, 27); + this.numericUpDownWorkExperience.TabIndex = 8; + // + // numericUpDownQualification + // + this.numericUpDownQualification.Location = new System.Drawing.Point(157, 142); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(124, 27); + this.numericUpDownQualification.TabIndex = 10; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(12, 144); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(114, 20); + this.labelQualification.TabIndex = 9; + this.labelQualification.Text = "Квалификация:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(422, 203); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(136, 40); + this.buttonCancel.TabIndex = 12; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(265, 203); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(130, 40); + this.buttonSave.TabIndex = 11; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(570, 255); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.numericUpDownWorkExperience); + this.Controls.Add(this.labelWorkExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxFIO; + private Label labelFIO; + private TextBox textBoxPassword; + private Label labelPassword; + private Label labelWorkExperience; + private NumericUpDown numericUpDownWorkExperience; + private NumericUpDown numericUpDownQualification; + private Label labelQualification; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormImplementer.cs b/Pizzeria/PizzeriaView/FormImplementer.cs new file mode 100644 index 0000000..8a4e3ee --- /dev/null +++ b/Pizzeria/PizzeriaView/FormImplementer.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.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 PizzeriaView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownWorkExperience.Value = view.WorkExperience; + numericUpDownQualification.Value = view.Qualification; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = (int)numericUpDownWorkExperience.Value, + Qualification = (int)numericUpDownQualification.Value + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при создании или обновлении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Pizzeria/PizzeriaView/FormImplementer.resx b/Pizzeria/PizzeriaView/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/PizzeriaView/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/Pizzeria/PizzeriaView/FormImplementers.Designer.cs b/Pizzeria/PizzeriaView/FormImplementers.Designer.cs new file mode 100644 index 0000000..6f744d9 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormImplementers.Designer.cs @@ -0,0 +1,130 @@ +namespace PizzeriaView +{ + 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.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 2; + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormImplementers.cs b/Pizzeria/PizzeriaView/FormImplementers.cs new file mode 100644 index 0000000..bcf3035 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormImplementers.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using Pizzeria; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +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 PizzeriaView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic implementerLogic) + { + InitializeComponent(); + _logger = logger; + _logic = implementerLogic; + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Pizzeria/PizzeriaView/FormImplementers.resx b/Pizzeria/PizzeriaView/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/PizzeriaView/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/Pizzeria/PizzeriaView/FormMain.Designer.cs b/Pizzeria/PizzeriaView/FormMain.Designer.cs index e817c36..0934b14 100644 --- a/Pizzeria/PizzeriaView/FormMain.Designer.cs +++ b/Pizzeria/PizzeriaView/FormMain.Designer.cs @@ -32,17 +32,17 @@ this.bookToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ingridientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pizzasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ингредиентыПоПиццамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -52,11 +52,12 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.bookToolStripMenuItem, - this.отчётыToolStripMenuItem}); + this.отчётыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); - this.menuStrip1.Size = new System.Drawing.Size(1149, 24); + this.menuStrip1.Size = new System.Drawing.Size(1284, 24); this.menuStrip1.TabIndex = 0; this.menuStrip1.Text = "menuStrip1"; // @@ -65,7 +66,8 @@ this.bookToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ingridientsToolStripMenuItem, this.pizzasToolStripMenuItem, - this.clientsToolStripMenuItem}); + this.clientsToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.bookToolStripMenuItem.Name = "bookToolStripMenuItem"; this.bookToolStripMenuItem.Size = new System.Drawing.Size(87, 20); this.bookToolStripMenuItem.Text = "Справочник"; @@ -73,17 +75,31 @@ // ingridientsToolStripMenuItem // this.ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem"; - this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.ingridientsToolStripMenuItem.Text = "Ингредиенты"; this.ingridientsToolStripMenuItem.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click); // // pizzasToolStripMenuItem // this.pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem"; - this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.pizzasToolStripMenuItem.Text = "Пиццы"; this.pizzasToolStripMenuItem.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click); // + // clientsToolStripMenuItem + // + this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + this.clientsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.clientsToolStripMenuItem.Text = "Клиенты"; + this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); + // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.employersToolStripMenuItem_Click); + // // отчётыToolStripMenuItem // this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -115,6 +131,13 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.startWorkToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.AllowUserToAddRows = false; @@ -126,12 +149,12 @@ this.dataGridView.ReadOnly = true; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(855, 286); + this.dataGridView.Size = new System.Drawing.Size(1002, 350); this.dataGridView.TabIndex = 1; // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(898, 53); + this.buttonCreateOrder.Location = new System.Drawing.Point(1035, 84); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(216, 22); @@ -140,31 +163,9 @@ this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(898, 92); - this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(216, 22); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(898, 129); - this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(216, 22); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(898, 169); + this.buttonIssuedOrder.Location = new System.Drawing.Point(1035, 135); this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonIssuedOrder.Size = new System.Drawing.Size(216, 22); @@ -175,7 +176,7 @@ // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(898, 210); + this.buttonRef.Location = new System.Drawing.Point(1035, 183); this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonRef.Name = "buttonRef"; this.buttonRef.Size = new System.Drawing.Size(216, 22); @@ -184,22 +185,13 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // clientsToolStripMenuItem - // - this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.clientsToolStripMenuItem.Text = "Клиенты"; - 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(1149, 319); + this.ClientSize = new System.Drawing.Size(1284, 424); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); @@ -224,8 +216,6 @@ private ToolStripMenuItem pizzasToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; private ToolStripMenuItem отчётыToolStripMenuItem; @@ -233,5 +223,7 @@ private ToolStripMenuItem ингредиентыПоПиццамToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormMain.cs b/Pizzeria/PizzeriaView/FormMain.cs index 60a2e69..02b10e3 100644 --- a/Pizzeria/PizzeriaView/FormMain.cs +++ b/Pizzeria/PizzeriaView/FormMain.cs @@ -19,12 +19,14 @@ namespace PizzeriaView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) { @@ -40,6 +42,7 @@ namespace PizzeriaView dataGridView.DataSource = list; dataGridView.Columns["PizzaId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; dataGridView.Columns["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } @@ -51,6 +54,20 @@ namespace PizzeriaView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void employersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void startWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormClients)); @@ -84,56 +101,7 @@ namespace PizzeriaView LoadData(); } } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'",id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) diff --git a/Pizzeria/PizzeriaView/Program.cs b/Pizzeria/PizzeriaView/Program.cs index ca4a6c8..5228919 100644 --- a/Pizzeria/PizzeriaView/Program.cs +++ b/Pizzeria/PizzeriaView/Program.cs @@ -10,6 +10,7 @@ using PizzeriaContracts.StorageContracts; using PizzeriaDatabaseImplement.Implements; using System; using Pizzeria; +using PizzeriaContracts.StoragesContracts; namespace PizzeriaView { @@ -41,15 +42,18 @@ namespace PizzeriaView 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(); services.AddTransient(); services.AddTransient(); @@ -64,6 +68,8 @@ namespace PizzeriaView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file