Add and delete for assembly
This commit is contained in:
parent
904981a408
commit
cfb0caf0f7
@ -101,10 +101,10 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия сборки", nameof(model.AssemblyName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость сборки должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
//if (model.Price <= 0)
|
||||
//{
|
||||
// throw new ArgumentNullException("Стоимость сборки должна быть больше 0", nameof(model.Price));
|
||||
//}
|
||||
_logger.LogInformation("Assembly. ComputerName:{AssemblyName}.Price:{ Price}. Id: { Id}", model.AssemblyName, model.Price, model.Id);
|
||||
var element = _assemblyStorage.GetElement(new AssemblySearchModel
|
||||
{
|
||||
|
@ -7,78 +7,77 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopBusinessLogic.OfficePackage
|
||||
{
|
||||
public class AbstractSaveToExcel
|
||||
public abstract class AbstractSaveToExcel
|
||||
{
|
||||
public void CreateReport(ExcelInfo info)
|
||||
{
|
||||
CreateExcel(info);
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
uint rowIndex = 2;
|
||||
foreach (var pc in info.DocumentBlanks)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.DocumentName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
foreach (var (Blank, Count) in pc.Blanks)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = Blank,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||
});
|
||||
rowIndex++;
|
||||
}
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Итого",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
}
|
||||
SaveExcel(info);
|
||||
}
|
||||
/// Создание excel-файла
|
||||
protected abstract void CreateExcel(ExcelInfo info);
|
||||
/// Добавляем новую ячейку в лист
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
/// Объединение ячеек
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
/// Сохранение файла
|
||||
protected abstract void SaveExcel(ExcelInfo info);
|
||||
}
|
||||
//public void CreateReport(ExcelInfo info)
|
||||
//{
|
||||
// CreateExcel(info);
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "A",
|
||||
// RowIndex = 1,
|
||||
// Text = info.Title,
|
||||
// StyleInfo = ExcelStyleInfoType.Title
|
||||
// });
|
||||
// MergeCells(new ExcelMergeParameters
|
||||
// {
|
||||
// CellFromName = "A1",
|
||||
// CellToName = "C1"
|
||||
// });
|
||||
// uint rowIndex = 2;
|
||||
// foreach (var pc in info.DocumentBlanks)
|
||||
// {
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "A",
|
||||
// RowIndex = rowIndex,
|
||||
// Text = pc.DocumentName,
|
||||
// StyleInfo = ExcelStyleInfoType.Text
|
||||
// });
|
||||
// rowIndex++;
|
||||
// foreach (var (Blank, Count) in pc.Blanks)
|
||||
// {
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "B",
|
||||
// RowIndex = rowIndex,
|
||||
// Text = Blank,
|
||||
// StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||
// });
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "C",
|
||||
// RowIndex = rowIndex,
|
||||
// Text = Count.ToString(),
|
||||
// StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||
// });
|
||||
// rowIndex++;
|
||||
// }
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "A",
|
||||
// RowIndex = rowIndex,
|
||||
// Text = "Итого",
|
||||
// StyleInfo = ExcelStyleInfoType.Text
|
||||
// });
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "C",
|
||||
// RowIndex = rowIndex,
|
||||
// Text = pc.TotalCount.ToString(),
|
||||
// StyleInfo = ExcelStyleInfoType.Text
|
||||
// });
|
||||
// rowIndex++;
|
||||
// }
|
||||
// SaveExcel(info);
|
||||
//}
|
||||
///// Создание excel-файла
|
||||
//protected abstract void CreateExcel(ExcelInfo info);
|
||||
///// Добавляем новую ячейку в лист
|
||||
//protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
///// Объединение ячеек
|
||||
//protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
///// Сохранение файла
|
||||
//protected abstract void SaveExcel(ExcelInfo info);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace ComputerShopClientApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<AssemblyViewModel>>($"api/assembly/getassemblylist"));
|
||||
return View(APIClient.GetRequest<List<AssemblyViewModel>>($"api/Assembly/getassemblylist?clientId={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -208,25 +208,45 @@ namespace ComputerShopClientApp.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateAssembly(string name, int sum)
|
||||
public void CreateAssembly(string name, int cost)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (sum <= 0)
|
||||
APIClient.PostRequest("api/assembly/createassembly", new AssemblyBindingModel
|
||||
{
|
||||
throw new Exception("Сумма должна быть больше 0");
|
||||
}
|
||||
//APIClient.PostRequest("api/assembly/createassembly", new AssemblyBindingModel
|
||||
//{
|
||||
// ClientId = APIClient.Client.Id,
|
||||
// AssemblyName = name,
|
||||
// Price = 0,
|
||||
// AssemblyComponents = new()
|
||||
//});
|
||||
ClientId = APIClient.Client.Id,
|
||||
AssemblyName = name,
|
||||
Price = cost,
|
||||
});
|
||||
System.Diagnostics.Debug.WriteLine("it might work");
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Assembly");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteAssembly()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Assemblies = APIClient.GetRequest<List<AssemblyViewModel>>($"api/assembly/GetAssemblyList?clientId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteAssembly(int assembly)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Необходима авторизация");
|
||||
}
|
||||
APIClient.PostRequest("api/assembly/deleteassembly", new AssemblyBindingModel
|
||||
{
|
||||
Id = assembly
|
||||
});
|
||||
Response.Redirect("Assembly");
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,15 @@
|
||||
<p>
|
||||
<a asp-action="CreateAssembly">Создать сборку</a>
|
||||
</p>
|
||||
<p>
|
||||
<a asp-action="EditAssembly">Изменить сборку</a>
|
||||
</p>
|
||||
<p>
|
||||
<a asp-action="DeleteAssembly">Удалить сборку</a>
|
||||
</p>
|
||||
<p>
|
||||
<a asp-action="AddComponentToAssembly">Добавить комплектующее к сборке</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -1,6 +1,4 @@
|
||||
@using ComputerShopContracts.ViewModels
|
||||
|
||||
@{
|
||||
@{
|
||||
ViewData["Title"] = "CreateAssembly";
|
||||
}
|
||||
<div class="text-center">
|
||||
@ -8,64 +6,15 @@
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Компонент:</div>
|
||||
<div class="col-8">
|
||||
<select id="component" name="component" class="form-control" asp-items="@(new SelectList(@ViewBag.Components,"Id", "ComponentName"))"></select>
|
||||
</div>
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8"><input type="text" name="name" id="name" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8"><input type="text" name="count" id="count" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Сумма:</div>
|
||||
<div class="col-8"><input type="text" id="sum" name="sum" readonly /></div>
|
||||
<div class="col-4">Цена:</div>
|
||||
<div class="col-8"><input type="text" name="cost" id="cost" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Добавить компонент" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Список компонентов</h1>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Компонент
|
||||
</th>
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in (ViewBag.CurrentComponents as IEnumerable<ComponentViewModel>))
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.ComponentName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Cost)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
@ -0,0 +1,16 @@
|
||||
@{
|
||||
ViewData["Title"] = "DeleteAssembly";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<div class="u-form-group u-form-name u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Сборка: </label>
|
||||
<div class="u-input u-input-rectangle">
|
||||
<select id="assembly" name="assembly" class="form-control" asp-items="@(new SelectList(@ViewBag.Assemblies, "Id", "AssemblyName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Удалить" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
|
||||
</div>
|
||||
</form>
|
@ -10,5 +10,6 @@ namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? AssemblyName { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,21 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
}
|
||||
public List<AssemblyViewModel> GetFilteredList(AssemblySearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.AssemblyName))
|
||||
if (string.IsNullOrEmpty(model.AssemblyName) && model.ClientId == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputerShopDatabase();
|
||||
if (model.ClientId != null)
|
||||
return context.Assemblies
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
else
|
||||
{
|
||||
return context.Assemblies
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
@ -40,6 +50,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
public AssemblyViewModel? GetElement(AssemblySearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.AssemblyName) &&
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@ -19,11 +20,14 @@ namespace ComputerShopRestApi.Controllers
|
||||
_component = component;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<AssemblyViewModel>? GetAssemblyList()
|
||||
public List<AssemblyViewModel>? GetAssemblyList(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _assembly.ReadList(null);
|
||||
return _assembly.ReadList(new AssemblySearchModel
|
||||
{
|
||||
ClientId = clientId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -57,5 +61,18 @@ namespace ComputerShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void DeleteAssembly(AssemblyBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_assembly.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления сборки");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user