DozorovaA.A 2023-05-20 10:48:39 +04:00
commit e96c1a10e7
8 changed files with 74 additions and 19 deletions

View File

@ -50,15 +50,16 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id); _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element; return element;
} }
public bool Create(SetBindingModel model) public SetViewModel? Create(SetBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_SetStorage.Insert(model) == null) var set = _SetStorage.Insert(model);
if (set == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return null;
} }
return true; return set;
} }
public bool Update(SetBindingModel model) public bool Update(SetBindingModel model)
{ {

View File

@ -14,7 +14,7 @@ namespace FurnitureAssemblyContracts.BusinessLogicContracts
{ {
List<SetViewModel>? ReadList(SetSearchModel? model); List<SetViewModel>? ReadList(SetSearchModel? model);
SetViewModel? ReadElement(SetSearchModel model); SetViewModel? ReadElement(SetSearchModel model);
bool Create(SetBindingModel model); SetViewModel? Create(SetBindingModel model);
bool Update(SetBindingModel model); bool Update(SetBindingModel model);
bool AddFurnitureModuleInSet(SetSearchModel model, IFurnitureModuleModel furnitureModule, int count); bool AddFurnitureModuleInSet(SetSearchModel model, IFurnitureModuleModel furnitureModule, int count);
bool Delete(SetBindingModel model); bool Delete(SetBindingModel model);

View File

@ -108,11 +108,11 @@ namespace FurnitureAssemblyRestApi.Controllers
} }
} }
[HttpPost] [HttpPost]
public void AddSet(SetBindingModel model) public SetViewModel? AddSet(SetBindingModel model)
{ {
try try
{ {
_set.Create(model); return _set.Create(model);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -11,6 +11,7 @@ using System.Web.Helpers;
using System.Reflection; using System.Reflection;
using FurnitureAssemblyBusinessLogic.BusinessLogics; using FurnitureAssemblyBusinessLogic.BusinessLogics;
using FurnitureAssemblyContracts.BusinessLogicContracts; using FurnitureAssemblyContracts.BusinessLogicContracts;
using FurnitureAssemblyDatabaseImplement.Models;
namespace FurnitureAssemblyWorkerClientApp.Controllers namespace FurnitureAssemblyWorkerClientApp.Controllers
{ {
@ -132,10 +133,10 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers
[HttpGet] [HttpGet]
public IActionResult CreateSet() public IActionResult CreateSet()
{ {
return View(); return View((APIClient.GetRequest<List<FurnitureModuleViewModel>>($"api/furnituremodule/getfurnituremodulelistbyuser?userId={APIClient.User.Id}")));
} }
[HttpPost] [HttpPost]
public void CreateSet(string name, double cost) public void CreateSet(string name, double cost, int[] furnitureModuleIds, int[] counts)
{ {
if (APIClient.User == null) if (APIClient.User == null)
{ {
@ -149,12 +150,23 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers
{ {
throw new Exception("Стоимость гарнитура не корректна"); throw new Exception("Стоимость гарнитура не корректна");
} }
APIClient.PostRequest("api/set/addset", new SetBindingModel var set = APIClient.PostRequest("api/set/addset", new SetBindingModel
{ {
Name = name, Name = name,
Cost = cost, Cost = cost,
UserId = APIClient.User.Id UserId = APIClient.User.Id
}); });
if (furnitureModuleIds != null && furnitureModuleIds.Length > 0 && counts != null && furnitureModuleIds.Length == counts.Length)
{
for (int i = 0; i < counts.Length; i++)
{
APIClient.PostRequest("api/set/addfurnituremoduleinset", Tuple.Create(
new SetSearchModel() { Id = set.Id },
new FurnitureModuleViewModel() { Id = furnitureModuleIds[i] },
counts[i]
));
}
}
Response.Redirect("Sets"); Response.Redirect("Sets");
} }
[HttpGet] [HttpGet]

View File

@ -4,6 +4,7 @@ namespace FurnitureAssemblyWorkerClientApp.Models
{ {
public string? RequestId { get; set; } public string? RequestId { get; set; }
public int? Code { get; set; } public int? Code { get; set; }
public string? Content { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
} }
} }

View File

@ -23,12 +23,12 @@ builder.Services.AddControllersWithViews();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration); APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
//{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
//} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();

View File

@ -1,6 +1,8 @@
@{ @using FurnitureAssemblyContracts.ViewModels;
@{
ViewData["Title"] = "Создание гарнитура"; ViewData["Title"] = "Создание гарнитура";
} }
@model List<FurnitureModuleViewModel>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Создание гарнитура</h2> <h2 class="display-4">Создание гарнитура</h2>
</div> </div>
@ -13,6 +15,49 @@
<div class="col-4">Стоимость:</div> <div class="col-4">Стоимость:</div>
<div class="col-8"><input type="text" name="cost" id="cost" /></div> <div class="col-8"><input type="text" name="cost" id="cost" /></div>
</div> </div>
<table class="table">
<thead>
<tr>
<th>
</th>
<th>
Название
</th>
<th>
Стоимость
</th>
<th>
Дата создания
</th>
<th>
Количество
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
<input type="checkbox" class="form-check-input" name="furnitureModuleIds[]" value="@item.Id" id="@item.Id">
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cost)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateCreate)
</td>
<td>
<input type="text" id="@item.Id:count" name="counts[]" />
</td>
</tr>
}
</tbody>
</table>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>

View File

@ -1,8 +1,4 @@
@page "{code?}" @model FurnitureAssemblyWorkerClientApp.Models.ErrorViewModel
@model ErrorViewModel
@{
ViewData["Title"] = "Ошибка";
}
<h1 class="text-danger">Произошла ошибка</h1> <h1 class="text-danger">Произошла ошибка</h1>
@if (Model.ShowRequestId) @if (Model.ShowRequestId)