diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..8aaec56 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,129 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update 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; + } + + 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("Квалификация исполнителя должен быть больше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. Id: {Id}. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Qualification: {Qualification}. " + + "WorkExperience: {WorkExperience}", model.Id, model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже существует"); + } + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs index f0ae979..5442ed9 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -19,6 +19,8 @@ namespace ComputersShopBusinessLogic.BusinessLogics private readonly IOrderStorage _orderStorage; + static readonly object locker = new(); + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; @@ -55,9 +57,29 @@ namespace ComputersShopBusinessLogic.BusinessLogics return list; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id: {Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) @@ -82,11 +104,15 @@ namespace ComputersShopBusinessLogic.BusinessLogics } if (model.ComputerId <= 0) { - throw new ArgumentNullException("Некорректный идентификатор выпечки", nameof(model.ComputerId)); + throw new ArgumentNullException("Некорректный идентификатор мороженого", nameof(model.ComputerId)); + } + if (model.ClientId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор клиента", nameof(model.ClientId)); } if (model.Count <= 0) { - throw new ArgumentNullException("В заказе должно быть хотя бы одна выпечка", nameof(model.Count)); + throw new ArgumentNullException("В заказе должно быть хотя бы одно мороженое", nameof(model.Count)); } if (model.Sum <= 0) { @@ -111,11 +137,11 @@ namespace ComputersShopBusinessLogic.BusinessLogics newStatus, order.Status); return false; } - model.ComputerId = order.ComputerId; - model.Count = order.Count; - model.Sum = order.Sum; - model.DateCreate = order.DateCreate; model.Status = newStatus; + if (order.ImplementerId.HasValue) + { + model.ImplementerId = order.ImplementerId; + } if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..39b9bd6 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,149 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + 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/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..24112fb --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs index aba8baf..8f4f96e 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace ComputersShopContracts.BindingModels public int Id { get; set; } public int ComputerId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..a4a3027 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs index 8c8da36..10618f2 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..de716cc --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..f13292a --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs index 1ec4607..65e7ee5 100644 --- a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs +++ b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using ComputersShopDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,9 +10,11 @@ namespace ComputersShopContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } + public int? ImplementerId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..ed5e3bc --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..030ad35 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.ViewModels +{ + public class ImplementerViewModel + { + 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/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs index 512548d..7039e3a 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -22,6 +22,10 @@ namespace ComputersShopContracts.ViewModels [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs b/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..9b61546 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + + } +} diff --git a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs index 1844485..ff59acd 100644 --- a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs +++ b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs @@ -11,6 +11,7 @@ namespace ComputersShopDataModels.Models { int ComputerId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs b/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs index 8d6b161..7c59ee5 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs @@ -15,7 +15,7 @@ namespace ComputersShopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-1DE5E8N\SQLEXPRESS;Initial Catalog=ComputersShopDatabaseFull; + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-1DE5E8N\SQLEXPRESS;Initial Catalog=ComputersShopDatabaseFull2; Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); @@ -25,5 +25,6 @@ namespace ComputersShopDatabaseImplement public virtual DbSet ComputerComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..27ce687 --- /dev/null +++ b/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,91 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new ComputersShopDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new ComputersShopDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new ComputersShopDatabase(); + return context.Implementers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new ComputersShopDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new ComputersShopDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new ComputersShopDatabase(); + var element = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs index b030970..d9e4c73 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs @@ -20,6 +20,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -32,6 +33,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -41,6 +43,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -50,16 +53,37 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return context.Orders + .Include(x => x.Computer) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Status != null) + { + return context.Orders + .Include(x => x.Computer) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -67,7 +91,11 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) + .Include(x => x.Implementer) + .FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } @@ -84,6 +112,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == newOrder.Id) ?.GetViewModel; } @@ -101,6 +130,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } @@ -114,6 +144,7 @@ namespace ComputersShopDatabaseImplement.Implements var deletedElement = context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; context.Orders.Remove(element); diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.Designer.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.Designer.cs deleted file mode 100644 index 1ac4371..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.Designer.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -using System; -using ComputersShopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace ComputersShopDatabaseImplement.Migrations -{ - [DbContext(typeof(ComputersShopDatabase))] - [Migration("20240326105531_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.17") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("ComputersShopDatabaseImplement.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("ComputersShopDatabaseImplement.Models.Computer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComputerName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Computers"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("ComputerId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ComputerId"); - - b.ToTable("ComputerComponents"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComputerId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ComputerId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b => - { - b.HasOne("ComputersShopDatabaseImplement.Models.Component", "Component") - .WithMany("ComputerComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer") - .WithMany("Components") - .HasForeignKey("ComputerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Computer"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => - { - b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer") - .WithMany("Orders") - .HasForeignKey("ComputerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Computer"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Component", b => - { - b.Navigation("ComputerComponents"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Computer", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240423102214_ClientAddition.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240423102214_ClientAddition.cs deleted file mode 100644 index fbbf10f..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240423102214_ClientAddition.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ComputersShopDatabaseImplement.Migrations -{ - /// - public partial class ClientAddition : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240423102214_ClientAddition.Designer.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240505073421_InitialCreate.Designer.cs similarity index 79% rename from ComputersShop/ComputersShopDatabaseImplement/Migrations/20240423102214_ClientAddition.Designer.cs rename to ComputersShop/ComputersShopDatabaseImplement/Migrations/20240505073421_InitialCreate.Designer.cs index c76c97d..fe87e4b 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240423102214_ClientAddition.Designer.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240505073421_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ComputersShopDatabaseImplement.Migrations { [DbContext(typeof(ComputersShopDatabase))] - [Migration("20240423102214_ClientAddition")] - partial class ClientAddition + [Migration("20240505073421_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -116,6 +116,33 @@ namespace ComputersShopDatabaseImplement.Migrations b.ToTable("ComputerComponents"); }); + modelBuilder.Entity("ComputersShopDatabaseImplement.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("ComputersShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -124,7 +151,7 @@ namespace ComputersShopDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("ComputerId") @@ -139,6 +166,9 @@ namespace ComputersShopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -151,6 +181,8 @@ namespace ComputersShopDatabaseImplement.Migrations b.HasIndex("ComputerId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -175,9 +207,11 @@ namespace ComputersShopDatabaseImplement.Migrations modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => { - b.HasOne("ComputersShopDatabaseImplement.Models.Client", null) + b.HasOne("ComputersShopDatabaseImplement.Models.Client", "Client") .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer") .WithMany("Orders") @@ -185,7 +219,15 @@ namespace ComputersShopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ComputersShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + b.Navigation("Computer"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Client", b => @@ -204,6 +246,11 @@ namespace ComputersShopDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240505073421_InitialCreate.cs similarity index 65% rename from ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.cs rename to ComputersShop/ComputersShopDatabaseImplement/Migrations/20240505073421_InitialCreate.cs index 77f25f2..87cfccc 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240505073421_InitialCreate.cs @@ -11,6 +11,21 @@ namespace ComputersShopDatabaseImplement.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Components", columns: table => new @@ -39,6 +54,22 @@ namespace ComputersShopDatabaseImplement.Migrations table.PrimaryKey("PK_Computers", x => x.Id); }); + 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.CreateTable( name: "ComputerComponents", columns: table => new @@ -73,6 +104,8 @@ namespace ComputersShopDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ComputerId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), Status = table.Column(type: "int", nullable: false), @@ -82,12 +115,23 @@ namespace ComputersShopDatabaseImplement.Migrations constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Orders_Computers_ComputerId", column: x => x.ComputerId, principalTable: "Computers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); }); migrationBuilder.CreateIndex( @@ -100,10 +144,20 @@ namespace ComputersShopDatabaseImplement.Migrations table: "ComputerComponents", column: "ComputerId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ComputerId", table: "Orders", column: "ComputerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); } /// @@ -118,8 +172,14 @@ namespace ComputersShopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Components"); + migrationBuilder.DropTable( + name: "Clients"); + migrationBuilder.DropTable( name: "Computers"); + + migrationBuilder.DropTable( + name: "Implementers"); } } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs index 58a6280..f4e6de2 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs @@ -113,6 +113,33 @@ namespace ComputersShopDatabaseImplement.Migrations b.ToTable("ComputerComponents"); }); + modelBuilder.Entity("ComputersShopDatabaseImplement.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("ComputersShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -121,7 +148,7 @@ namespace ComputersShopDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("ComputerId") @@ -136,6 +163,9 @@ namespace ComputersShopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -148,6 +178,8 @@ namespace ComputersShopDatabaseImplement.Migrations b.HasIndex("ComputerId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -172,9 +204,11 @@ namespace ComputersShopDatabaseImplement.Migrations modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => { - b.HasOne("ComputersShopDatabaseImplement.Models.Client", null) + b.HasOne("ComputersShopDatabaseImplement.Models.Client", "Client") .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer") .WithMany("Orders") @@ -182,7 +216,15 @@ namespace ComputersShopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ComputersShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + b.Navigation("Computer"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Client", b => @@ -201,6 +243,11 @@ namespace ComputersShopDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..740d726 --- /dev/null +++ b/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,82 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +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; +using ComputersShopDataModels.Models; + +namespace ComputersShopDatabaseImplement.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 Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public static Implementer Create(ImplementerViewModel model) + { + return new Implementer + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs index 90276d1..772c1ca 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs @@ -12,33 +12,48 @@ namespace ComputersShopDatabaseImplement.Models { public class Order { - public int Id { get; private set; } + public int Id { get; set; } + [Required] - public int ComputerId { get; private set; } + public int ComputerId { get; set; } + [Required] public int ClientId { get; set; } + + public int? ImplementerId { get; private set; } + [Required] - public int Count { get; private set; } + public int Count { get; set; } + [Required] - public double Sum { get; private set; } + public double Sum { get; set; } + [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public OrderStatus Status { get; set; } + [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } - public virtual Computer Computer { get; private set; } + public DateTime DateCreate { get; set; } + + public DateTime? DateImplement { get; set; } + + public virtual Computer Computer { get; set; } + public virtual Client Client { get; set; } + + public virtual Implementer? Implementer { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) { return null; } - return new Order + return new Order() { Id = model.Id, ComputerId = model.ComputerId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -46,6 +61,7 @@ namespace ComputersShopDatabaseImplement.Models DateImplement = model.DateImplement }; } + public void Update(OrderBindingModel? model) { if (model == null) @@ -54,19 +70,23 @@ namespace ComputersShopDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } + public OrderViewModel GetViewModel => new() { Id = Id, ComputerId = ComputerId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ComputerName = Computer.ComputerName, - ClientFIO = Client.ClientFIO + ComputerName = Computer.ComputerName ?? string.Empty, + ClientFIO = Client.ClientFIO ?? string.Empty, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty }; } } diff --git a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs index afc9963..4adfa6c 100644 --- a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs +++ b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs @@ -12,14 +12,27 @@ namespace ComputersShopFileImplement internal class DataFileSingleton { private static DataFileSingleton? instance; - public readonly string ComponentFileName = "Component.xml"; - public readonly string OrderFileName = "Order.xml"; - public readonly string ComputerFileName = "Computer.xml"; - public readonly string ClientFileName = "Client.xml"; + + private readonly string ComponentFileName = "Component.xml"; + + private readonly string OrderFileName = "Order.xml"; + + private readonly string ComputerFileName = "Computer.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 Computers { get; private set; } + public List Clients { get; private set; } + + public List Implementers { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -28,23 +41,27 @@ namespace ComputersShopFileImplement } return instance; } - public void SaveComponents() => SaveData(Components, ComponentFileName, - "Components", x => x.GetXElement); - public void SaveComputers() => SaveData(Computers, ComputerFileName, - "Computers", 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 SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + + public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", 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)!)!; Computers = LoadData(ComputerFileName, "Computer", x => Computer.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) + + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) { @@ -52,8 +69,8 @@ namespace ComputersShopFileImplement } return new List(); } - private static void SaveData(List data, string filename, - string xmlNodeName, Func selectFunction) + + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) { if (data != null) { diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..2da91b7 --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,93 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopFileImplement.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 (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + return source.Implementers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + + 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/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs index cec4c1d..7f7045c 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs @@ -50,21 +50,34 @@ namespace ComputersShopFileImplement.Implements .Select(x => AddInfo(x.GetViewModel)) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } + else if (model.Status != null) + { + return source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - return AddInfo(order.GetViewModel); + var order = source.Orders.FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id); + return order?.GetViewModel != null ? AddInfo(order.GetViewModel) : null; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs b/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..8ae5a5c --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs @@ -0,0 +1,77 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ComputersShopFileImplement.Models +{ + public class Implementer : 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; } + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification) + ); + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Models/Order.cs b/ComputersShop/ComputersShopFileImplement/Models/Order.cs index 3c42567..bc9e5b0 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Order.cs @@ -16,10 +16,11 @@ namespace ComputersShopFileImplement.Models public int Id { get; private set; } public int ComputerId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -31,11 +32,13 @@ namespace ComputersShopFileImplement.Models { Id = model.Id, ComputerId = model.ComputerId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement, + DateImplement = model.DateImplement }; } public static Order? Create(XElement element) @@ -44,23 +47,18 @@ namespace ComputersShopFileImplement.Models { return null; } - var id = Convert.ToInt32(element.Attribute("Id")!.Value); - var computerId = Convert.ToInt32(element.Element("ComputerId")!.Value); - var sum = Convert.ToDouble(element.Element("Sum")!.Value); - var count = Convert.ToInt32(element.Element("Count")!.Value); - var status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value); - var dateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value); - var dateImplement = DateTime.Now; - return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value), - Sum = Convert.ToDouble(element.Element("Sum")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.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), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null + : Convert.ToDateTime(element.Element("DateImplement")!.Value) }; } public void Update(OrderBindingModel? model) @@ -71,26 +69,29 @@ namespace ComputersShopFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { Id = Id, ComputerId = ComputerId, - Sum = Sum, + ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, + Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement, + DateImplement = DateImplement }; - public XElement GetXElement => new( - "Order", - new XAttribute("Id", Id), - new XElement("ComputerId", ComputerId.ToString()), - 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()) - ); + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ComputerId", ComputerId), + new XElement("ClientId", ClientId), + 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/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index d79d2e7..0e283a4 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -10,17 +10,26 @@ namespace AbstractShopListImplement public class DataListSingleton { private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Computers { get; set; } + public List Clients { get; set; } + + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Computers = new List(); Clients = new List(); + Implementers = new List(); } + public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..243a122 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,109 @@ +using AbstractShopListImplement; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.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 (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + foreach (var implementer in _source.Implementers) + { + if ((!string.IsNullOrEmpty(model.ImplementerFIO) && implementer.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + || (model.Id.HasValue && implementer.Id == model.Id)) + { + 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/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs index 3f19dab..e068a51 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -15,12 +15,10 @@ namespace ComputersShopListImplement.Implements public class OrderStorage : IOrderStorage { private readonly DataListSingleton _source; - public OrderStorage() { _source = DataListSingleton.GetInstance(); } - public List GetFullList() { var result = new List(); @@ -30,7 +28,6 @@ namespace ComputersShopListImplement.Implements } return result; } - public List GetFilteredList(OrderSearchModel model) { var result = new List(); @@ -64,12 +61,31 @@ namespace ComputersShopListImplement.Implements } } } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } return result; } - public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -79,10 +95,17 @@ namespace ComputersShopListImplement.Implements { return AddInfo(order.GetViewModel); } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return AddInfo(order.GetViewModel); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return AddInfo(order.GetViewModel); + } } return null; } - public OrderViewModel? Insert(OrderBindingModel model) { model.Id = 1; @@ -101,7 +124,6 @@ namespace ComputersShopListImplement.Implements _source.Orders.Add(newOrder); return AddInfo(newOrder.GetViewModel); } - public OrderViewModel? Update(OrderBindingModel model) { foreach (var order in _source.Orders) @@ -114,7 +136,6 @@ namespace ComputersShopListImplement.Implements } return null; } - public OrderViewModel? Delete(OrderBindingModel model) { for (int i = 0; i < _source.Orders.Count; ++i) @@ -128,10 +149,9 @@ namespace ComputersShopListImplement.Implements } return null; } - private OrderViewModel AddInfo(OrderViewModel model) { - var selectedComputer = _source.Computers.Find(computer => computer.Id == model.ComputerId); + var selectedComputer = _source.Computers.Find(iceCream => iceCream.Id == model.ComputerId); if (selectedComputer != null) { model.ComputerName = selectedComputer.ComputerName; diff --git a/ComputersShop/ComputersShopListImplement/Models/Implementer.cs b/ComputersShop/ComputersShopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..44f6bbd --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Implementer.cs @@ -0,0 +1,55 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.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/ComputersShop/ComputersShopListImplement/Models/Order.cs b/ComputersShop/ComputersShopListImplement/Models/Order.cs index d2c1cdc..eb017b8 100644 --- a/ComputersShop/ComputersShopListImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopListImplement/Models/Order.cs @@ -15,12 +15,12 @@ namespace ComputersShopListImplement.Models public int Id { get; private set; } public int ComputerId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } - public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -31,11 +31,13 @@ namespace ComputersShopListImplement.Models { Id = model.Id, ComputerId = model.ComputerId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement, + DateImplement = model.DateImplement }; } public void Update(OrderBindingModel? model) @@ -46,16 +48,19 @@ namespace ComputersShopListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { Id = Id, ComputerId = ComputerId, + ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement, + DateImplement = DateImplement }; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs b/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..08d289d --- /dev/null +++ b/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,105 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; + + +namespace ComputersShopRestApi.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/ComputersShop/ComputersShopRestApi/Program.cs b/ComputersShop/ComputersShopRestApi/Program.cs index fb4bbd5..c2556ff 100644 --- a/ComputersShop/ComputersShopRestApi/Program.cs +++ b/ComputersShop/ComputersShopRestApi/Program.cs @@ -10,10 +10,12 @@ builder.Logging.SetMinimumLevel(LogLevel.Trace); 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(); diff --git a/ComputersShop/ComputersShopView/FormImplementer.Designer.cs b/ComputersShop/ComputersShopView/FormImplementer.Designer.cs new file mode 100644 index 0000000..d987922 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementer.Designer.cs @@ -0,0 +1,163 @@ +namespace ComputersShopView +{ + 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.labelFIO = new System.Windows.Forms.Label(); + this.labelPassword = new System.Windows.Forms.Label(); + this.labelWorkExperience = new System.Windows.Forms.Label(); + this.labelQualification = new System.Windows.Forms.Label(); + this.textBoxQualification = new System.Windows.Forms.TextBox(); + this.textBoxWorkExperience = new System.Windows.Forms.TextBox(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(16, 49); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(45, 20); + this.labelFIO.TabIndex = 0; + this.labelFIO.Text = "ФИО:"; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(16, 97); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(65, 20); + this.labelPassword.TabIndex = 1; + this.labelPassword.Text = "Пароль:"; + // + // labelWorkExperience + // + this.labelWorkExperience.AutoSize = true; + this.labelWorkExperience.Location = new System.Drawing.Point(16, 150); + this.labelWorkExperience.Name = "labelWorkExperience"; + this.labelWorkExperience.Size = new System.Drawing.Size(102, 20); + this.labelWorkExperience.TabIndex = 2; + this.labelWorkExperience.Text = "Стаж работы:"; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(16, 201); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(114, 20); + this.labelQualification.TabIndex = 3; + this.labelQualification.Text = "Квалификация:"; + // + // textBoxQualification + // + this.textBoxQualification.Location = new System.Drawing.Point(155, 194); + this.textBoxQualification.Name = "textBoxQualification"; + this.textBoxQualification.Size = new System.Drawing.Size(285, 27); + this.textBoxQualification.TabIndex = 4; + // + // textBoxWorkExperience + // + this.textBoxWorkExperience.Location = new System.Drawing.Point(155, 143); + this.textBoxWorkExperience.Name = "textBoxWorkExperience"; + this.textBoxWorkExperience.Size = new System.Drawing.Size(285, 27); + this.textBoxWorkExperience.TabIndex = 5; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(155, 90); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(285, 27); + this.textBoxPassword.TabIndex = 6; + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(155, 42); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(285, 27); + this.textBoxFIO.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(205, 250); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(346, 250); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(454, 292); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxWorkExperience); + this.Controls.Add(this.textBoxQualification); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.labelWorkExperience); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFIO; + private Label labelPassword; + private Label labelWorkExperience; + private Label labelQualification; + private TextBox textBoxQualification; + private TextBox textBoxWorkExperience; + private TextBox textBoxPassword; + private TextBox textBoxFIO; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormImplementer.cs b/ComputersShop/ComputersShopView/FormImplementer.cs new file mode 100644 index 0000000..9733815 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementer.cs @@ -0,0 +1,112 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +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 ComputersShopView +{ + 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("Receiving implementer"); + var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + textBoxQualification.Text = view.Qualification.ToString(); + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Receiving implementer error"); + 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; + } + if (string.IsNullOrEmpty(textBoxWorkExperience.Text)) + { + MessageBox.Show("Заполните стаж работы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxQualification.Text)) + { + MessageBox.Show("Заполните квалификацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving implementer"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + 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, "Saving implementer error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormImplementer.resx b/ComputersShop/ComputersShopView/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/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/ComputersShop/ComputersShopView/FormImplementers.Designer.cs b/ComputersShop/ComputersShopView/FormImplementers.Designer.cs new file mode 100644 index 0000000..dcb4c14 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementers.Designer.cs @@ -0,0 +1,114 @@ +namespace ComputersShopView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(521, 454); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(536, 45); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(536, 106); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(94, 29); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(536, 160); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(536, 215); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 4; + this.buttonUpd.Text = "Обновить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(646, 450); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormImplementers.cs b/ComputersShop/ComputersShopView/FormImplementers.cs new file mode 100644 index 0000000..4ee1647 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementers.cs @@ -0,0 +1,113 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 ComputersShopView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Implementers loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementers loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void 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("Deletion of implementer"); + try + { + if (!_logic.Delete(new ImplementerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementer deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormImplementers.resx b/ComputersShop/ComputersShopView/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/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/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index 4971d3b..c467ce2 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -33,10 +33,12 @@ this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -52,7 +54,8 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); + this.отчетыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1147, 28); @@ -64,7 +67,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.изделияToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -72,24 +76,31 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ИсполнителиToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -121,6 +132,13 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(114, 24); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.ЗапускРаботToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -226,5 +244,7 @@ private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index f1886b9..f98b112 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -19,13 +19,15 @@ namespace ComputersShopView 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; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) { @@ -43,6 +45,8 @@ namespace ComputersShopView dataGridView.Columns["ComputerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -161,8 +165,7 @@ namespace ComputersShopView { LoadData(); } - private void списокКомпонентовToolStripMenuItem_Click(object sender, EventArgs -e) + private void списокКомпонентовToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) @@ -202,6 +205,21 @@ e) form.ShowDialog(); } } + private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic + )) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + private void ИсполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index 0cf2e32..72ab2d3 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -40,12 +40,15 @@ namespace ComputersShopView 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(); @@ -61,6 +64,8 @@ namespace ComputersShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file