From dbd3e7b5ef726b861e6a959ab3e3a48de86ee93c Mon Sep 17 00:00:00 2001 From: the Date: Wed, 17 May 2023 17:28:31 +0400 Subject: [PATCH] component crud --- .../BusinessLogics/ReportLogic.cs | 58 +++++++++--------- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- .../OfficePackage/HelperModels/Pdfinfo.cs | 2 +- .../Controllers/HomeController.cs | 54 ++++++++++++++++- .../Views/Home/Component.cshtml | 3 + .../Views/Home/EditComponent.cshtml | 59 +++++++++++++++++++ .../Controllers/ComponentController.cs | 30 +++++++++- 7 files changed, 174 insertions(+), 34 deletions(-) create mode 100644 ComputerShopProvider/ComputerShopClientApp/Views/Home/EditComponent.cshtml diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs index 33f2617..7f3f226 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -9,37 +9,37 @@ using System.Threading.Tasks; namespace ComputerShopBusinessLogic.BusinessLogics { - public class ReportLogic : IReportLogic - { - private readonly IBlankStorage _blankStorage; - private readonly IDocumentStorage _documentStorage; - private readonly IOrderStorage _orderStorage; - private readonly AbstractSaveToExcel _saveToExcel; - private readonly AbstractSaveToWord _saveToWord; - private readonly AbstractSaveToPdf _saveToPdf; - public List GetPurchaseReceiving() - { - throw new NotImplementedException(); - } + //public class ReportLogic : IReportLogic + //{ + // private readonly IBlankStorage _blankStorage; + // private readonly IDocumentStorage _documentStorage; + // private readonly IOrderStorage _orderStorage; + // private readonly AbstractSaveToExcel _saveToExcel; + // private readonly AbstractSaveToWord _saveToWord; + // private readonly AbstractSaveToPdf _saveToPdf; + // public List GetPurchaseReceiving() + // { + // throw new NotImplementedException(); + // } - public List GetPurchaseSupply() - { - throw new NotImplementedException(); - } + // public List GetPurchaseSupply() + // { + // throw new NotImplementedException(); + // } - public void SaveOrdersToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } + // public void SaveOrdersToPdfFile(ReportBindingModel model) + // { + // throw new NotImplementedException(); + // } - public void SavePackagesToWordFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } + // public void SavePackagesToWordFile(ReportBindingModel model) + // { + // throw new NotImplementedException(); + // } - public void SaveProductComponentToExcelFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - } + // public void SaveProductComponentToExcelFile(ReportBindingModel model) + // { + // throw new NotImplementedException(); + // } + //} } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 46bb54f..d9b0b15 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -11,6 +11,6 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List DocumentBlanks { get; set; } = new(); + //public List DocumentBlanks { get; set; } = new(); } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/Pdfinfo.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/Pdfinfo.cs index 9c6d6d5..d35d999 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/Pdfinfo.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/Pdfinfo.cs @@ -13,6 +13,6 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } - public List Orders { get; set; } = new(); + //public List Orders { get; set; } = new(); } } diff --git a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs index fa9b5d3..4c57e82 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs +++ b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs @@ -187,7 +187,7 @@ namespace ComputerShopClientApp.Controllers ViewBag.Components = APIClient.GetRequest>($"api/main/getcomponentlist?clientId={APIClient.Client.Id}"); return View(); } - [HttpDelete] + [HttpPost] public void DeleteComponent(int component) { if (APIClient.Client == null) @@ -198,7 +198,7 @@ namespace ComputerShopClientApp.Controllers { Id = component }); - Response.Redirect("Index"); + Response.Redirect("Component"); } [HttpGet] @@ -345,5 +345,55 @@ namespace ComputerShopClientApp.Controllers var comp = APIClient.GetRequest($"api/main/getcomponent?componentId={component}"); return count * (comp?.Cost ?? 1); } + + public IActionResult EditComponent() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Components = APIClient.GetRequest>($"api/component/getcomponentlist?clientId={APIClient.Client.Id}"); + return View(); + } + + [HttpPost] + public void EditComponent(int component, string componentName, int price) + { + if (APIClient.Client == null) + { + throw new Exception("Необходима авторизация"); + } + if (string.IsNullOrEmpty(componentName)) + { + throw new Exception("Название не может быть пустым"); + } + if (price < 0) + { + throw new Exception("Цена не может быть меньше нуля"); + } + APIClient.PostRequest("api/component/editcomponent", new ComponentBindingModel + { + Id = component, + ComponentName = componentName, + Cost = price, + ClientId = APIClient.Client.Id + }); + Response.Redirect("Assembly"); + } + + [HttpGet] + public ComponentViewModel? GetComponent(int componentId) + { + if (APIClient.Client == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIClient.GetRequest($"api/component/getcomponent?componentId={componentId}"); + if (result == null) + { + return default; + } + return result; + } } } \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml index eb71419..507f0c9 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml @@ -22,6 +22,9 @@

Создать комплектующее

+

+ Изменить комплектующее +

Удалить комплектующее

diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/EditComponent.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/EditComponent.cshtml new file mode 100644 index 0000000..69a4eef --- /dev/null +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/EditComponent.cshtml @@ -0,0 +1,59 @@ +@using ComputerShopContracts.ViewModels; +@using ComputerShopDataModels.Models; + +@{ + ViewData["Title"] = "EditComponent"; +} + +
+
+ +
+ +
+
+
+ + +
+
+ + +
+
+
+
+
+
+ +@section Scripts + { + +} \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs index eea994d..2ae4631 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs @@ -47,7 +47,7 @@ namespace ComputerShopRestApi.Controllers throw; } } - [HttpDelete] + [HttpPost] public void DeleteComponent(ComponentBindingModel model) { try @@ -60,5 +60,33 @@ namespace ComputerShopRestApi.Controllers throw; } } + + [HttpPost] + public void EditComponent(ComponentBindingModel model) + { + try + { + _component.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка изменения компонента"); + throw; + } + } + + [HttpGet] + public ComponentViewModel? GetComponent(int componentId) + { + try + { + return _component.ReadElement(new ComponentSearchModel { Id = componentId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента по id={Id}", componentId); + throw; + } + } } }