From 4121d5ec1c145cf0d3491b65d743c6ff18d66303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Mon, 15 May 2023 22:33:12 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=81=D0=B1=D0=BE=D1=80=D0=BE=D0=BA=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BD=D0=B0=D0=B8=D1=86=D0=B5=20=D0=B8=20=D0=B8?= =?UTF-8?q?=D1=85=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5,=20?= =?UTF-8?q?=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=8B=20=D0=B8=20=D0=B8?= =?UTF-8?q?=D1=85=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89?= =?UTF-8?q?=D0=B5=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Storekeeper/ComponentLogic.cs | 2 +- .../BusinessLogics/Worker/BuildLogic.cs | 4 - .../IComponentLogic.cs | 2 +- .../ViewModels/ComponentViewModel.cs | 2 +- .../Models/IComponentModel.cs | 1 + .../HardwareShopDatabase.cs | 2 +- .../Implements/Worker/BuildStorage.cs | 4 +- .../Controllers/BuildController.cs | 82 +++++++++++++---- .../Controllers/CommentController.cs | 54 +---------- .../Controllers/PurchaseController.cs | 58 ++---------- .../Controllers/WorkerReport.cs | 56 ++---------- .../Controllers/HomeController.cs | 57 ++++++++++-- .../Views/Home/Builds.cshtml | 90 ++++++++++++++----- 13 files changed, 209 insertions(+), 205 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ComponentLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ComponentLogic.cs index e24794f..1aea2f8 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ComponentLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ComponentLogic.cs @@ -1,5 +1,5 @@ using HardwareShopContracts.BindingModels; -using HardwareShopContracts.BuisnessLogicsContracts; +using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.SearchModels; using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.ViewModels; diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs index 60ad2c5..ad91c1c 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs @@ -96,10 +96,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts { throw new ArgumentNullException("Нет названия сборки", nameof(model.BuildName)); } - if (model.Price <= 0) - { - throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price)); - } if (model.UserId < 0) { throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.UserId)); diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IComponentLogic.cs index 1c0c35a..59316ef 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -2,7 +2,7 @@ using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; -namespace HardwareShopContracts.BuisnessLogicsContracts +namespace HardwareShopContracts.BusinessLogicsContracts { public interface IComponentLogic { diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ComponentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ComponentViewModel.cs index 9fba828..40f9860 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/ComponentViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/ComponentViewModel.cs @@ -10,7 +10,7 @@ namespace HardwareShopContracts.ViewModels public string ComponentName { get; set; } = string.Empty; [DisplayName("Стоимость")] public double Cost { get; set; } - [DisplayName("Дата приобретения")] + [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; public int UserId { get; set; } public Dictionary ComponentBuilds diff --git a/HardwareShop/HardwareShopDataModels/Models/IComponentModel.cs b/HardwareShop/HardwareShopDataModels/Models/IComponentModel.cs index fa02c95..4bcd72f 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IComponentModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IComponentModel.cs @@ -5,6 +5,7 @@ string ComponentName { get; } double Cost { get; } int UserId { get; } + DateTime DateCreate { get; } Dictionary ComponentBuilds { get; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs index ba1c28d..4246e31 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs @@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store;Username=postgres;Password=1234"); + optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store4;Username=postgres;Password=1234"); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs index 33fa8e3..2d4f1a8 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs @@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return context.Builds .Include(x => x.Purchases) .ThenInclude(x => x.Purchase) - .Include(x => x.BuildName.Contains(model.BuildName)) + .Where(x => x.BuildName.Contains(model.BuildName)) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -40,7 +40,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return context.Builds .Include(x => x.Purchases) .ThenInclude(x => x.Purchase) - .Include(x => x.UserId == model.UserId) + .Where(x => x.UserId == model.UserId) .ToList() .Select(x => x.GetViewModel) .ToList(); diff --git a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs index d430e4c..9a70f32 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs @@ -1,63 +1,81 @@ -using HardwareShopContracts.BindingModels; +using HardwareShopBusinessLogic.BusinessLogics.Storekeeper; +using HardwareShopContracts.BindingModels; using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Models.Worker; +using HardwareShopDataModels.Models; using Microsoft.AspNetCore.Mvc; +using System.ComponentModel; namespace HardwareShopRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] - public class UserController : Controller + public class BuildController : Controller { private readonly ILogger _logger; + private readonly IBuildLogic _buildLogic; + private readonly IComponentLogic _componentLogic; - private readonly IUserLogic _logic; - - public UserController(IUserLogic logic, ILogger logger) + public BuildController(IBuildLogic buildLogic, IComponentLogic componentLogic, ILogger logger) { _logger = logger; - _logic = logic; + _buildLogic = buildLogic; + _componentLogic = componentLogic; } [HttpGet] - public UserViewModel? Login(string email, string password) + public List? GetBuilds(int userId) { try { - return _logic.ReadElement(new UserSearchModel + return _buildLogic.ReadList(new BuildSearchModel { - Email = email, - Password = password + UserId = userId }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка входа в систему"); + _logger.LogError(ex, "Ошибка получения списка сборок"); throw; } } - [HttpPost] - public void Register(UserBindingModel model) + [HttpGet] + public BuildViewModel? GetBuild(int id) { try - { - _logic.Create(model); + { + return _buildLogic.ReadElement(new() { Id = id }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка регистрации"); + _logger.LogError(ex, "Ошибка сборки"); throw; } } [HttpPost] - public void UpdateData(UserBindingModel model) + public void Create(BuildBindingModel model) { try { - _logic.Update(model); + _buildLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сборки"); + throw; + } + } + + [HttpPost] + public void Update(BuildBindingModel model) + { + try + { + _buildLogic.Update(model); } catch (Exception ex) { @@ -65,5 +83,33 @@ namespace HardwareShopRestApi.Controllers throw; } } + + [HttpPost] + public void DeleteShop(BuildBindingModel model) + { + try + { + _buildLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления сборки"); + throw; + } + } + + [HttpPost] + public void AddDishInShop(ComponentBindingModel model) + { + try + { + _componentLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка компонента в сборку"); + throw; + } + } } } diff --git a/HardwareShop/HardwareShopRestApi/Controllers/CommentController.cs b/HardwareShop/HardwareShopRestApi/Controllers/CommentController.cs index d430e4c..9b1361f 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/CommentController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/CommentController.cs @@ -8,62 +8,16 @@ namespace HardwareShopRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] - public class UserController : Controller + public class CommentController : Controller { private readonly ILogger _logger; - private readonly IUserLogic _logic; + private readonly ICommentLogic _commentLogic; - public UserController(IUserLogic logic, ILogger logger) + public CommentController(ICommentLogic commentLogic, ILogger logger) { _logger = logger; - _logic = logic; - } - - [HttpGet] - public UserViewModel? Login(string email, string password) - { - try - { - return _logic.ReadElement(new UserSearchModel - { - Email = email, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } - - [HttpPost] - public void Register(UserBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } - - [HttpPost] - public void UpdateData(UserBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } + _commentLogic = commentLogic; } } } diff --git a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs index d430e4c..4796eeb 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs @@ -2,68 +2,26 @@ using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; +using HardwareShopRestApi.Controllers; using Microsoft.AspNetCore.Mvc; +using System.Xml.Linq; namespace HardwareShopRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] - public class UserController : Controller + public class PurchaseController : Controller { private readonly ILogger _logger; - private readonly IUserLogic _logic; + private readonly IPurchaseLogic _purchaseLogic; - public UserController(IUserLogic logic, ILogger logger) + public PurchaseController(IPurchaseLogic purchaseLogic, ILogger logger) { _logger = logger; - _logic = logic; - } - - [HttpGet] - public UserViewModel? Login(string email, string password) - { - try - { - return _logic.ReadElement(new UserSearchModel - { - Email = email, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } - - [HttpPost] - public void Register(UserBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } - - [HttpPost] - public void UpdateData(UserBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } + _purchaseLogic = purchaseLogic; } } } + + diff --git a/HardwareShop/HardwareShopRestApi/Controllers/WorkerReport.cs b/HardwareShop/HardwareShopRestApi/Controllers/WorkerReport.cs index d430e4c..dbbf344 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/WorkerReport.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/WorkerReport.cs @@ -8,62 +8,16 @@ namespace HardwareShopRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] - public class UserController : Controller + public class WorkerReport : Controller { private readonly ILogger _logger; - private readonly IUserLogic _logic; + private readonly IWorkerReportLogic _workerReportLogic; - public UserController(IUserLogic logic, ILogger logger) + public WorkerReport(IWorkerReportLogic workerReportLogic, ILogger logger) { _logger = logger; - _logic = logic; - } - - [HttpGet] - public UserViewModel? Login(string email, string password) - { - try - { - return _logic.ReadElement(new UserSearchModel - { - Email = email, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } - - [HttpPost] - public void Register(UserBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } - - [HttpPost] - public void UpdateData(UserBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } + _workerReportLogic = workerReportLogic; } } -} +} \ No newline at end of file diff --git a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs index 354ecc3..647baad 100644 --- a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs +++ b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Models; using HardwareShopDataModels.Enums; using HardwareShopWorkerApp.Models; using Microsoft.AspNetCore.Mvc; @@ -41,8 +42,12 @@ namespace HardwareShopWorkerApp.Controllers public IActionResult Index() { - return View(); - } + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } public IActionResult Privacy() { @@ -75,7 +80,45 @@ namespace HardwareShopWorkerApp.Controllers Response.Redirect("MainWorker"); } - public IActionResult MainWorker() + [HttpPost] + public void CreateBuild(string name) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception($"Имя магазина не должно быть пустым"); + } + APIClient.PostRequest("api/build/create", new BuildBindingModel + { + BuildName = name, + UserId = APIClient.User.Id + }); + Response.Redirect("Builds"); + } + + [HttpPost] + public void UpdateBuild(string name) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception($"Имя магазина не должно быть пустым"); + } + APIClient.PostRequest("api/build/update", new BuildBindingModel + { + BuildName = name, + UserId = APIClient.User.Id + }); + Response.Redirect("Builds"); + } + + public IActionResult MainWorker() { return View(); } @@ -117,8 +160,12 @@ namespace HardwareShopWorkerApp.Controllers [HttpGet] public IActionResult Builds() { - return View(); - } + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/build/getbuilds?userId={APIClient.User.Id}")); + } [HttpPost] public void Builds(int id) diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml index 5940109..a8f1deb 100644 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml @@ -1,9 +1,17 @@ -@{ +@using HardwareShopContracts.ViewModels +@model List +@{ ViewData["Title"] = "Builds"; Layout = "~/Views/Shared/_LayoutWorker.cshtml"; } -
+
+ @{ + if (Model == null) + { +

Введите пароль

+ return; + }

Сборки

@@ -24,35 +32,75 @@ - - + @foreach (var item in Model) + { + + + @Html.DisplayFor(modelItem => item.Id) + + + @Html.DisplayFor(modelItem => item.Price) + + + @Html.DisplayFor(modelItem => item.BuildName) + + + } + + +
- +
- - \ No newline at end of file