Merge branch 'WebApp' of https://git.is.ulstu.ru/Ilfedotov.01/CourseWorkElectronicsShop into WebApp
This commit is contained in:
commit
c66b4bc56b
@ -6,6 +6,7 @@ using ElectronicsShopDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using System.Text;
|
||||
@ -34,9 +35,11 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
if (component == null) {
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
return context.CostItems
|
||||
.Include(x => x.Employee)
|
||||
.FirstOrDefault(x => x.ID == component.ID)?.GetViewModel;
|
||||
}
|
||||
|
||||
public CostItemViewModel? Delete(CostItemBindingModel model)
|
||||
@ -47,8 +50,10 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
{
|
||||
context.CostItems.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return context.CostItems
|
||||
.Include(x => x.Employee)
|
||||
.FirstOrDefault(x => x.ID == element.ID)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -119,6 +119,42 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
Response.Redirect("CostItem");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult EditCostItem(int id) {
|
||||
var _costitem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={id}");
|
||||
|
||||
if (_costitem == null) {
|
||||
return Redirect("/Home/CostItem");
|
||||
}
|
||||
|
||||
var obj = new CostItemViewModel {
|
||||
ID = _costitem.ID,
|
||||
Name = _costitem.Name,
|
||||
Price = _costitem.Price,
|
||||
CostNum = _costitem.CostNum,
|
||||
};
|
||||
|
||||
return View(obj);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void EditCostItem(string name, double price, int costNum, int _ID) {
|
||||
if (APIEmployee.Employee == null) {
|
||||
throw new Exception("Ňîëüęî äë˙ ŕâňîđčçîâŕíűő");
|
||||
}
|
||||
if (price <= 0) {
|
||||
throw new Exception("Ńóěěŕ çŕňđŕň äîëćíŕ áűňü áîëüřĺ 0");
|
||||
}
|
||||
APIEmployee.PostRequest("api/employee/editcostitem", new CostItemBindingModel {
|
||||
ID = _ID,
|
||||
Name = name,
|
||||
Price = price,
|
||||
CostNum = costNum,
|
||||
EmployeeID = APIEmployee.Employee.ID
|
||||
});
|
||||
Response.Redirect("CostItem");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateProduct() {
|
||||
ViewBag.CostItems = APIEmployee.GetRequset<List<CostItemViewModel>>($"api/employee/getcostitems?_employeeid={APIEmployee.Employee.ID}");
|
||||
@ -126,11 +162,11 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateProduct(string name, int costitem, double productprice) {
|
||||
public void CreateProduct(string name, int costitem, double productprice, double price) {
|
||||
if (APIEmployee.Employee == null) {
|
||||
throw new Exception("Òîëüêî äëÿ àâòîðèçîâàííûõ");
|
||||
}
|
||||
if (productprice <= 0) {
|
||||
if (price <= 0) {
|
||||
throw new Exception("Ñòîèìîñòü òîâàðà äîëæíà áûòü áîëüøå 0");
|
||||
}
|
||||
APIEmployee.PostRequest("api/employee/createproduct", new ProductBindingModel {
|
||||
@ -141,6 +177,18 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteCostItem(int id) {
|
||||
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={id}");
|
||||
|
||||
if (_costItem == null) {
|
||||
return Redirect("/Home/Index");
|
||||
}
|
||||
|
||||
APIEmployee.PostRequest("api/employee/deletecostitem", new CostItemBindingModel { ID = id });
|
||||
return RedirectToAction("CostItem");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult EditProduct(int id) {
|
||||
var _product = APIEmployee.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={id}");
|
||||
@ -149,7 +197,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
return Redirect("/Home/Index");
|
||||
}
|
||||
|
||||
ViewBag.CostItems = APIEmployee.GetRequset<List<CostItemViewModel>>($"api/employee/getcostitems?_employeeid={APIEmployee.Employee.ID}");
|
||||
ViewBag.CostItems = APIEmployee.GetRequset<List<CostItemViewModel>>($"api/employee/getcostitems?_employeeid={APIEmployee.Employee?.ID}");
|
||||
|
||||
var obj = new ProductViewModel {
|
||||
ProductName = _product.ProductName,
|
||||
@ -158,31 +206,39 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
ID = _product.ID
|
||||
};
|
||||
|
||||
var _costitemLoad = (APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={obj.CostItemID}"));
|
||||
|
||||
if (_costitemLoad?.Name != ViewBag.CostItems[0].Name) {
|
||||
int index = 0;
|
||||
if (ViewBag.CostItems.Count != 0) {
|
||||
var _costitemLoad = (APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={obj.CostItemID}"));
|
||||
|
||||
for (int i = 0; i < ViewBag.CostItems.Count; i++) {
|
||||
if (ViewBag.CostItems[i].Name == _costitemLoad?.Name) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
if (_costitemLoad == null) {
|
||||
return Redirect("/Home/Index");
|
||||
}
|
||||
|
||||
var tmp = ViewBag.CostItems[0];
|
||||
ViewBag.CostItems[0] = _costitemLoad;
|
||||
ViewBag.CostItems[index] = tmp;
|
||||
if (_costitemLoad?.Name != ViewBag.CostItems[0].Name) {
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < ViewBag.CostItems.Count; i++) {
|
||||
if (ViewBag.CostItems[i].Name == _costitemLoad?.Name) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var tmp = ViewBag.CostItems[0];
|
||||
ViewBag.CostItems[0] = _costitemLoad;
|
||||
ViewBag.CostItems[index] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return View(obj);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void EditProduct(string name, int costitem, double productprice, int _ID) {
|
||||
public void EditProduct(string name, int costitem, double productprice, int _ID, double price) {
|
||||
if (APIEmployee.Employee == null) {
|
||||
throw new Exception("Òîëüêî äëÿ àâòîðèçîâàííûõ");
|
||||
}
|
||||
if (productprice <= 0) {
|
||||
if (price <= 0) {
|
||||
throw new Exception("Ñòîèìîñòü òîâàðà äîëæíà áûòü áîëüøå 0");
|
||||
}
|
||||
APIEmployee.PostRequest("api/employee/editproduct", new ProductBindingModel {
|
||||
|
@ -21,12 +21,6 @@
|
||||
<p>
|
||||
<a asp-action="CreateCostItem">Создать</a>
|
||||
</p>
|
||||
<p>
|
||||
<a asp-action="UpdateCostItem">Изменить</a>
|
||||
</p>
|
||||
<p>
|
||||
<a asp-action="DeleteCostItem">Удалить</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -50,20 +44,24 @@
|
||||
<tbody>
|
||||
@foreach (var item in Model) {
|
||||
<tr>
|
||||
<td>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.ID)
|
||||
</td>
|
||||
<td>
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
</td>
|
||||
<td>
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.EmployeeFIO)
|
||||
</td>
|
||||
<td>
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.Price)
|
||||
</td>
|
||||
<td>
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.CostNum)
|
||||
</th>
|
||||
<td>
|
||||
<a class="btn btn-primary btn-sm" asp-action="EditCostItem" asp-route-ID="@item.ID">Изменить</a>
|
||||
<a class="btn btn-primary btn-sm" asp-action="DeleteCostItem" asp-route-ID="@item.ID">Удалить</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
@{
|
||||
ViewData["Title"] = "EditCostItem";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание статьи затрат</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<label class="col-4">ID:</label>
|
||||
<div class="col-8">
|
||||
<input id="_ID" class="form-control" type="text" name="_ID" value="@Model.ID" readonly />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название статьи затрат:</div>
|
||||
<div class="col-8">
|
||||
<input id="name" type="text" name="name" value="@Model.Name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Номер счета:</div>
|
||||
<div class="col-8">
|
||||
<input id="costnum" type="text" name="costnum" value="@Model.CostNum" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Затраты:</div>
|
||||
<div class="col-8">
|
||||
<input id="price" type="text" name="price" value="@Model.Price" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-8">
|
||||
<input type="submit" value="Сохранить" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -93,6 +93,28 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void EditCostItem(CostItemBindingModel model) {
|
||||
try {
|
||||
_costItem.Update(model);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteCostItem(CostItemBindingModel model) {
|
||||
try {
|
||||
_costItem.Delete(model);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_logger.LogError(ex, "Ошибка удаления статьи затрат");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateProduct(ProductBindingModel model) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user