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);
return element;
}
public bool Create(SetBindingModel model)
public SetViewModel? Create(SetBindingModel model)
{
CheckModel(model);
if (_SetStorage.Insert(model) == null)
var set = _SetStorage.Insert(model);
if (set == null)
{
_logger.LogWarning("Insert operation failed");
return false;
return null;
}
return true;
return set;
}
public bool Update(SetBindingModel model)
{

View File

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

View File

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

View File

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

View File

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

View File

@ -23,12 +23,12 @@ builder.Services.AddControllersWithViews();
var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
if (!app.Environment.IsDevelopment())
{
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.
app.UseHsts();
//}
}
app.UseHttpsRedirection();
app.UseStaticFiles();

View File

@ -1,6 +1,8 @@
@{
@using FurnitureAssemblyContracts.ViewModels;
@{
ViewData["Title"] = "Создание гарнитура";
}
@model List<FurnitureModuleViewModel>
<div class="text-center">
<h2 class="display-4">Создание гарнитура</h2>
</div>
@ -13,6 +15,49 @@
<div class="col-4">Стоимость:</div>
<div class="col-8"><input type="text" name="cost" id="cost" /></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="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>

View File

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