diff --git a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs index d2ed72a..58a47bd 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs +++ b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs @@ -32,6 +32,14 @@ namespace ComputerShopClientApp.Controllers } return View(APIClient.GetRequest>($"api/component/getcomponentlist")); } + public IActionResult Assembly() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/assembly/getassemblylist")); + } [HttpGet] public IActionResult Privacy() @@ -171,7 +179,37 @@ namespace ComputerShopClientApp.Controllers Response.Redirect("Index"); } - + [HttpGet] + public IActionResult CreateAssembly() + { + ViewBag.Components = APIClient.GetRequest>("api/component/getcomponentlist"); + ViewBag.CurrentComponents = new List(); + return View(); + } + + [HttpPost] + public void CreateAssembly(string name, int sum) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (sum <= 0) + { + throw new Exception("Сумма должна быть больше 0"); + } + //APIClient.PostRequest("api/assembly/createassembly", new AssemblyBindingModel + //{ + // ClientId = APIClient.Client.Id, + // AssemblyName = name, + // Price = 0, + // AssemblyComponents = new() + //}); + System.Diagnostics.Debug.WriteLine("it might work"); + Response.Redirect("Index"); + } + + [HttpPost] public double Calc(int count, int component) diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/Assembly.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Assembly.cshtml new file mode 100644 index 0000000..cb31371 --- /dev/null +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Assembly.cshtml @@ -0,0 +1,57 @@ +@using ComputerShopContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Assembly"; +} + +
+

Сборки

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать сборку +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Сборка + + Цена +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.AssemblyName) + + @Html.DisplayFor(modelItem => item.Price) +
+ } +
\ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/CreateAssembly.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/CreateAssembly.cshtml new file mode 100644 index 0000000..26a977f --- /dev/null +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/CreateAssembly.cshtml @@ -0,0 +1,71 @@ +@using ComputerShopContracts.ViewModels + +@{ + ViewData["Title"] = "CreateAssembly"; +} +
+

Создание сборки

+
+
+
+
Компонент:
+
+ +
+
+
+
Количество:
+
+
+
+
Сумма:
+
+
+
+
+
+
+
+
+
+
+
+ +
+

Список компонентов

+
+
+ @{ + + + + + + + + + + @foreach (var item in (ViewBag.CurrentComponents as IEnumerable)) + { + + + + + + } + +
+ Номер + + Компонент + + Цена +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.ComponentName) + + @Html.DisplayFor(modelItem => item.Cost) +
+ } +
\ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml index 103f5c7..cb605b6 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml @@ -25,6 +25,9 @@ + diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/AssemblyBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/AssemblyBindingModel.cs index 500b2c8..1a09b89 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/AssemblyBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/AssemblyBindingModel.cs @@ -12,6 +12,7 @@ namespace ComputerShopContracts.BindingModels public int Id { get; set; } public string AssemblyName { get; set; } = string.Empty; public double Price { get; set; } + public int ClientId { get; set; } public Dictionary AssemblyComponents { get; diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs index ea2a108..f170a52 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs @@ -20,5 +20,9 @@ namespace ComputerShopContracts.ViewModels get; set; } = new(); + public int ClientId { get; set; } + + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs index eebe45f..ed102e8 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs @@ -19,8 +19,9 @@ namespace ComputerShopDatabaseImplement.Models public string AssemblyName { get; set; } = string.Empty; [Required] public double Price { get; set; } - private Dictionary? _assemblyComponents = - null; + [Required] + public int ClientId { get; private set; } + private Dictionary? _assemblyComponents = null; [NotMapped] public Dictionary AssemblyComponents { @@ -39,6 +40,7 @@ namespace ComputerShopDatabaseImplement.Models public virtual List Components { get; set; } = new(); [ForeignKey("AssemblyId")] public virtual List Orders { get; set; } = new(); + public virtual Client Client { get; set; } public static Assembly Create(ComputerShopDatabase context, AssemblyBindingModel model) { return new Assembly() @@ -46,6 +48,7 @@ namespace ComputerShopDatabaseImplement.Models Id = model.Id, AssemblyName = model.AssemblyName, Price = model.Price, + ClientId = model.ClientId, Components = model.AssemblyComponents.Select(x => new AssemblyComponent { @@ -64,12 +67,12 @@ namespace ComputerShopDatabaseImplement.Models Id = Id, AssemblyName = AssemblyName, Price = Price, - AssemblyComponents = AssemblyComponents + AssemblyComponents = AssemblyComponents, + ClientId = ClientId }; public void UpdateComponents(ComputerShopDatabase context, AssemblyBindingModel model) { - var assemblyComponents = context.AssemblyComponents.Where(rec => - rec.Id == model.Id).ToList(); + var assemblyComponents = context.AssemblyComponents.Where(rec => rec.Id == model.Id).ToList(); if (assemblyComponents != null && assemblyComponents.Count > 0) { // удалили те, которых нет в модели context.AssemblyComponents.RemoveRange(assemblyComponents.Where(rec diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/AssemblyController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/AssemblyController.cs new file mode 100644 index 0000000..f3d37ef --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/AssemblyController.cs @@ -0,0 +1,61 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class AssemblyController : Controller + { + private readonly ILogger _logger; + private readonly IAssemblyLogic _assembly; + private readonly IComponentLogic _component; + public AssemblyController(ILogger logger, IAssemblyLogic assembly, IComponentLogic component) + { + _logger = logger; + _assembly = assembly; + _component = component; + } + [HttpGet] + public List? GetAssemblyList() + { + try + { + return _assembly.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка сборок"); + throw; + } + } + [HttpGet] + public List? GetComponentList() + { + try + { + return _component.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка компонентов"); + throw; + } + } + [HttpPost] + public void CreateAssembly(AssemblyBindingModel model) + { + try + { + _assembly.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания сборки"); + throw; + } + } + } +} diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs index 341dd54..2b2d379 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs @@ -12,7 +12,7 @@ namespace ComputerShopRestApi.Controllers { private readonly ILogger _logger; private readonly IComponentLogic _component; - public ComponentController(ILogger logger, IComponentLogic component) + public ComponentController(ILogger logger, IComponentLogic component) { _logger = logger; _component = component; diff --git a/ComputerShopProvider/ComputerShopRestApi/Program.cs b/ComputerShopProvider/ComputerShopRestApi/Program.cs index e538d6c..8a35396 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Program.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Program.cs @@ -14,9 +14,12 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle