diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..a10ac5e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,115 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopBusinessLogic.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. Id: {Id}", 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. Id: {Id}", 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 (model.WorkExperience <= 0) + { + throw new ArgumentException("Опыт работы не должен быть меньше единицы", nameof(model.WorkExperience)); + } + if (model.Qualification <= 0) + { + throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Заполните пароль исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Заполните ФИО исполнителя", nameof(model.ImplementerFIO)); + } + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким значением ФИО уже есть"); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 007c1c7..c17cb9a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -29,7 +29,23 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogInformation("Readlist. Count: {Count}", list.Count); return list; } - public bool SetNewStatus(OrderBindingModel model, OrderStatus newstatus) + 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 SetNewStatus(OrderBindingModel model, OrderStatus newstatus) { CheckModel(model, false); OrderViewModel? vm = _orderStorage.GetElement(new() diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..a36c211 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,13 @@ +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + public string ImplementerFIO { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index f428f9b..5a551ac 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -13,5 +13,6 @@ namespace BlacksmithWorkshopContracts.BindingModels public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } public int ClientId { get; set; } + public int ImplementerId { get; set; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..6a8a152 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,15 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs index b228496..60e6e98 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,6 +7,7 @@ namespace BlacksmithWorkshopContracts.BusinessLogicContracts 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/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..b1931c2 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,9 @@ +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs index ba03a28..5614a1b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,6 @@ -namespace BlacksmithWorkshopContracts.SearchModels +using BlacksmithWorkshopDataModels.Enums; + +namespace BlacksmithWorkshopContracts.SearchModels { public class OrderSearchModel { @@ -6,5 +8,7 @@ public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public OrderStatus? Status { get; set; } + public int? ImplementerId { get; set; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..81f633f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..4a9acfd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + [DisplayName("Имя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + [DisplayName("Опыт")] + public int WorkExperience { get; set; } + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 70bebf2..ac393fa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -24,5 +24,8 @@ namespace BlacksmithWorkshopContracts.ViewModels public DateTime? DateImplement { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; - } + public int ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..5ea4b4f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,10 @@ +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index 99d9e5c..dc0fec0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -11,5 +11,6 @@ namespace BlacksmithWorkshopDataModels.Models OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } + int ImplementerId { get; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs index 430af4d..fe27582 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs @@ -25,5 +25,6 @@ namespace BlacksmithWorkshopDatabaseImplement public virtual DbSet ManufactureComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..7c34e75 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,87 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new BlacksmithWorkshopDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new BlacksmithWorkshopDatabase(); + if (model.Id.HasValue) + { + return context.Implementers + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + return context.Implementers + .Where(x => x.ImplementerFIO == model.ImplementerFIO) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (!model.Id.HasValue && (string.IsNullOrEmpty(model.ImplementerFIO) || string.IsNullOrEmpty(model.Password))) + { + return new(); + } + using var context = new BlacksmithWorkshopDatabase(); + if (model.Id.HasValue)//Сначала ищем по Id + { + return context.Implementers + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + return context.Implementers//Затем по логину и паролю + .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + 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 BlacksmithWorkshopDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + context.Implementers.Remove(implementer); + context.SaveChanges(); + return implementer.GetViewModel; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs index d6e4e38..4cf493e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs @@ -14,6 +14,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements using var context = new BlacksmithWorkshopDatabase(); List orderList = context.Orders .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); foreach (var order in orderList) @@ -37,7 +38,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements orderList = context.Orders .Where(x => x.Id == model.Id) .Include(x => x.Client) - .Select(x => x.GetViewModel) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) .ToList(); } else if (model.DateFrom.HasValue && model.DateTo.HasValue) //если у модели нет Id, ищем по датам @@ -45,17 +47,28 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements orderList = context.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } - else if (model.ClientId.HasValue) + else if (model.ClientId.HasValue)//далее ищем по клиенту { orderList = context.Orders .Where(x => x.ClientId == model.ClientId) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } + else if (model.Status.HasValue)//далее ищем по статусу + { + orderList = context.Orders + .Where(x => x.Status == model.Status) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); + } foreach (var order in orderList) { string manufactureName = context.Manufactures @@ -66,13 +79,22 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } using var context = new BlacksmithWorkshopDatabase(); - return context.Orders - .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.Id.HasValue)//Сначала ищем по Id + { + return context.Orders + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + if (model.ImplementerId.HasValue) + { + return context.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel; + } + return null; } public OrderViewModel? Insert(OrderBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..ea3eaba --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs @@ -0,0 +1,58 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } + [Required] + public int Qualification { get; private set; } + //Привязываем исполнителя к заказам один ко многим + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs index ae4020f..2b7ddfe 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs @@ -24,6 +24,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public int ClientId { get; private set; } [Required] public virtual Client? Client { get; private set; } + [Required] + public int ImplementerId { get; private set; } + public virtual Implementer? Implementer { get; private set; } public static Order? Create(OrderBindingModel model) { if (model == null) @@ -39,7 +42,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId + ClientId = model.ClientId, + ImplementerId = model.ImplementerId }; } public static Order Create(OrderViewModel model) @@ -77,7 +81,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models DateCreate = DateCreate, DateImplement = DateImplement, ClientId = ClientId, - ClientFIO = Client?.ClientFIO ?? string.Empty - }; + ClientFIO = Client?.ClientFIO ?? string.Empty, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty + }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index e2e542c..b7e4192 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -16,6 +16,8 @@ namespace BlacksmithWorkshopFileImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } public int ClientId { get; private set; } + //TODO + public int ImplementerId => throw new NotImplementedException(); public static Order? Create(OrderBindingModel? model) { if (model == null) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 2550c97..b53582a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -16,6 +16,8 @@ namespace BlacksmithWorkshopListImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } public int ClientId { get; private set; } + //TODO + public int ImplementerId => throw new NotImplementedException(); public static Order? Create(OrderBindingModel? model) { if (model == null) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ImplementerController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ImplementerController.cs new file mode 100644 index 0000000..f0c8a86 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ImplementerController.cs @@ -0,0 +1,101 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; + +namespace BlacksmithWorkshopRestAPI.Controllers +{ + 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; + } + } + + } +}