component crud

This commit is contained in:
the 2023-05-17 17:28:31 +04:00
parent 2ca68c463a
commit dbd3e7b5ef
7 changed files with 174 additions and 34 deletions

View File

@ -9,37 +9,37 @@ using System.Threading.Tasks;
namespace ComputerShopBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IBlankStorage _blankStorage;
private readonly IDocumentStorage _documentStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public List<ReportPurchaseReceivingViewModel> GetPurchaseReceiving()
{
throw new NotImplementedException();
}
//public class ReportLogic : IReportLogic
//{
// private readonly IBlankStorage _blankStorage;
// private readonly IDocumentStorage _documentStorage;
// private readonly IOrderStorage _orderStorage;
// private readonly AbstractSaveToExcel _saveToExcel;
// private readonly AbstractSaveToWord _saveToWord;
// private readonly AbstractSaveToPdf _saveToPdf;
// public List<ReportPurchaseReceivingViewModel> GetPurchaseReceiving()
// {
// throw new NotImplementedException();
// }
public List<ReportPurchaseSupplyViewModel> GetPurchaseSupply()
{
throw new NotImplementedException();
}
// public List<ReportPurchaseSupplyViewModel> GetPurchaseSupply()
// {
// throw new NotImplementedException();
// }
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
// public void SaveOrdersToPdfFile(ReportBindingModel model)
// {
// throw new NotImplementedException();
// }
public void SavePackagesToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
// public void SavePackagesToWordFile(ReportBindingModel model)
// {
// throw new NotImplementedException();
// }
public void SaveProductComponentToExcelFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
// public void SaveProductComponentToExcelFile(ReportBindingModel model)
// {
// throw new NotImplementedException();
// }
//}
}

View File

@ -11,6 +11,6 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportAssemlyComponentViewModel> DocumentBlanks { get; set; } = new();
//public List<ReportAssemlyComponentViewModel> DocumentBlanks { get; set; } = new();
}
}

View File

@ -13,6 +13,6 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportOrdersViewModel> Orders { get; set; } = new();
//public List<ReportOrdersViewModel> Orders { get; set; } = new();
}
}

View File

@ -187,7 +187,7 @@ namespace ComputerShopClientApp.Controllers
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/main/getcomponentlist?clientId={APIClient.Client.Id}");
return View();
}
[HttpDelete]
[HttpPost]
public void DeleteComponent(int component)
{
if (APIClient.Client == null)
@ -198,7 +198,7 @@ namespace ComputerShopClientApp.Controllers
{
Id = component
});
Response.Redirect("Index");
Response.Redirect("Component");
}
[HttpGet]
@ -345,5 +345,55 @@ namespace ComputerShopClientApp.Controllers
var comp = APIClient.GetRequest<ComponentViewModel>($"api/main/getcomponent?componentId={component}");
return count * (comp?.Cost ?? 1);
}
public IActionResult EditComponent()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/component/getcomponentlist?clientId={APIClient.Client.Id}");
return View();
}
[HttpPost]
public void EditComponent(int component, string componentName, int price)
{
if (APIClient.Client == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(componentName))
{
throw new Exception("Название не может быть пустым");
}
if (price < 0)
{
throw new Exception("Цена не может быть меньше нуля");
}
APIClient.PostRequest("api/component/editcomponent", new ComponentBindingModel
{
Id = component,
ComponentName = componentName,
Cost = price,
ClientId = APIClient.Client.Id
});
Response.Redirect("Assembly");
}
[HttpGet]
public ComponentViewModel? GetComponent(int componentId)
{
if (APIClient.Client == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<ComponentViewModel>($"api/component/getcomponent?componentId={componentId}");
if (result == null)
{
return default;
}
return result;
}
}
}

View File

@ -22,6 +22,9 @@
<p>
<a asp-action="CreateComponent">Создать комплектующее</a>
</p>
<p>
<a asp-action="EditComponent">Изменить комплектующее</a>
</p>
<p>
<a asp-action="DeleteComponent">Удалить комплектующее</a>
</p>

View File

@ -0,0 +1,59 @@
@using ComputerShopContracts.ViewModels;
@using ComputerShopDataModels.Models;
@{
ViewData["Title"] = "EditComponent";
}
<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="component" name="component" class="form-control" asp-items="@(new SelectList(@ViewBag.Components, "Id", "ComponentName"))"></select>
</div>
</div>
<div class="u-form-group u-form-name u-label-top">
<label class="u-label u-text-custom-color-1 u-label-1">Название компонента</label>
<input type="text"
id="componentName"
placeholder="Введите название компонента"
name="componentName"
class="u-input u-input-rectangle" />
</div>
<div class="u-form-group u-form-name u-label-top">
<label class="u-label u-text-custom-color-1 u-label-1">Цена сборки</label>
<input type="text"
id="price"
placeholder="Введите цену компонента"
name="price"
class="u-input u-input-rectangle" />
</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>
@section Scripts
{
<script>
function check() {
var component = $('#component').val();
if (component) {
$.ajax({
method: "GET",
url: "/Home/GetComponent",
data: { componentId: component },
success: function (result) {
$('#componentName').val(result.componentName);
$('#price').val(result.Cost.ToString());
}
});
};
}
check();
$('#component').on('change', function () {
check();
});
</script>
}

View File

@ -47,7 +47,7 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
[HttpDelete]
[HttpPost]
public void DeleteComponent(ComponentBindingModel model)
{
try
@ -60,5 +60,33 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
[HttpPost]
public void EditComponent(ComponentBindingModel model)
{
try
{
_component.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка изменения компонента");
throw;
}
}
[HttpGet]
public ComponentViewModel? GetComponent(int componentId)
{
try
{
return _component.ReadElement(new ComponentSearchModel { Id = componentId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения компонента по id={Id}", componentId);
throw;
}
}
}
}