bug fixes
This commit is contained in:
parent
403f2c1c79
commit
a8ccf282e3
@ -101,7 +101,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
_logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}" +
|
_logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}" +
|
||||||
$"CostNum:{model.CostNum}");
|
$"CostNum:{model.CostNum}");
|
||||||
var element = _storage.GetElement(new CostItemSearchModel { Name = model.Name });
|
var element = _storage.GetElement(new CostItemSearchModel { Name = model.Name });
|
||||||
if (element != null && element.Name == model.Name)
|
if (element != null && element.Name == model.Name && element.ID != model.ID)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Такая статья затрат уде есть");
|
throw new InvalidOperationException("Такая статья затрат уде есть");
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ namespace ElectronicsShopContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? ID { get; set; }
|
public int? ID { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? ProductName { get; set; }
|
||||||
public string? CostItem { get; set; }
|
public int? CostItemID { get; set; }
|
||||||
public PaymeantOption? PayOption { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace ElectronicsShopContracts.StorageContracts
|
|||||||
public interface IProductStorage
|
public interface IProductStorage
|
||||||
{
|
{
|
||||||
List<ProductViewModel> GetFullList();
|
List<ProductViewModel> GetFullList();
|
||||||
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
List<ProductViewModel>? GetFilteredList(ProductSearchModel model);
|
||||||
ProductViewModel? GetElement(ProductSearchModel model);
|
ProductViewModel? GetElement(ProductSearchModel model);
|
||||||
ProductViewModel? Insert(ProductBindingModel model);
|
ProductViewModel? Insert(ProductBindingModel model);
|
||||||
ProductViewModel? Update(ProductBindingModel model);
|
ProductViewModel? Update(ProductBindingModel model);
|
||||||
|
@ -57,26 +57,37 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
|||||||
|
|
||||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.ProductName) && !model.ID.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new Database();
|
using var context = new Database();
|
||||||
|
|
||||||
|
if (model.ID.HasValue && !string.IsNullOrEmpty(model.ProductName)) {
|
||||||
return context.Products
|
return context.Products
|
||||||
.Include(x => x.CostItem)
|
.Include(x => x.CostItem)
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) ||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) ||
|
||||||
(model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
|
(model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
else if (model.CostItemID.HasValue) {
|
||||||
|
return context.Products
|
||||||
|
.Include(x => x.CostItem)
|
||||||
|
.FirstOrDefault(x => model.CostItemID == x.CostItemID)?.GetViewModel;
|
||||||
|
|
||||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ProductName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel>? GetFilteredList(ProductSearchModel model)
|
||||||
|
{
|
||||||
using var context = new Database();
|
using var context = new Database();
|
||||||
|
|
||||||
|
if (model.CostItemID.HasValue && string.IsNullOrEmpty(model.ProductName)) {
|
||||||
|
return context.Products
|
||||||
|
.Where(x => x.CostItemID == model.CostItemID)
|
||||||
|
.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(model.ProductName) && model.ID.HasValue) {
|
||||||
return context.Products.Where(x => x.ProductName.Contains(model.ProductName)).Select(x => x.GetViewModel).ToList();
|
return context.Products.Where(x => x.ProductName.Contains(model.ProductName)).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ProductViewModel> GetFullList()
|
public List<ProductViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using ElectronicsShopContracts.BindingModels;
|
using ElectronicsShopContracts.BindingModels;
|
||||||
|
using ElectronicsShopContracts.SearchModels;
|
||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
using ElectronicsShopEmployeeApp.Models;
|
using ElectronicsShopEmployeeApp.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -145,6 +146,15 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
|||||||
if (price <= 0) {
|
if (price <= 0) {
|
||||||
throw new Exception("Ńóěěŕ çŕňđŕň äîëćíŕ áűňü áîëüřĺ 0");
|
throw new Exception("Ńóěěŕ çŕňđŕň äîëćíŕ áűňü áîëüřĺ 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _costitem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={_ID}");
|
||||||
|
|
||||||
|
if (_costitem == null) {
|
||||||
|
throw new Exception("Îřčáęŕ ďîëó÷ĺíč˙ äŕííűő");
|
||||||
|
}
|
||||||
|
|
||||||
|
double oldPrice = _costitem.Price;
|
||||||
|
|
||||||
APIEmployee.PostRequest("api/employee/editcostitem", new CostItemBindingModel {
|
APIEmployee.PostRequest("api/employee/editcostitem", new CostItemBindingModel {
|
||||||
ID = _ID,
|
ID = _ID,
|
||||||
Name = name,
|
Name = name,
|
||||||
@ -152,12 +162,32 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
|||||||
CostNum = costNum,
|
CostNum = costNum,
|
||||||
EmployeeID = APIEmployee.Employee.ID
|
EmployeeID = APIEmployee.Employee.ID
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ďĺđĺáčđŕĺě ńďčńîę ňîâŕđîâ ďî costitemid
|
||||||
|
// Âű÷čňŕĺě čç öĺíű ńňŕđóţ ńňîčěîńňü ńňŕňüč çŕňđŕň
|
||||||
|
// ďĺđĺđŕń÷čňűâŕĺě
|
||||||
|
// îňďđŕâë˙ĺě çŕďđîń íŕ čçěĺíĺíčĺ
|
||||||
|
|
||||||
|
var productList = APIEmployee.GetRequset<List<ProductViewModel>>($"api/main/getproducts?_costitemid={_ID}");
|
||||||
|
if (productList != null) {
|
||||||
|
foreach (var item in productList) {
|
||||||
|
APIEmployee.PostRequest("api/employee/editproduct", new ProductBindingModel {
|
||||||
|
ID = item.ID,
|
||||||
|
CostItemID = item.CostItemID,
|
||||||
|
ProductName = item.ProductName,
|
||||||
|
Price = Calc(item.CostItemID, item.Price - oldPrice)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Response.Redirect("CostItem");
|
Response.Redirect("CostItem");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult CreateProduct() {
|
public IActionResult CreateProduct() {
|
||||||
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}");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +212,12 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
|||||||
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={id}");
|
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={id}");
|
||||||
|
|
||||||
if (_costItem == null) {
|
if (_costItem == null) {
|
||||||
return Redirect("/Home/Index");
|
throw new Exception("Îřčáęŕ ďîëó÷ĺíč˙ äŕííűő");
|
||||||
|
}
|
||||||
|
|
||||||
|
var _product = APIEmployee.GetRequset<ProductViewModel>($"api/main/getproduct?_costitemID={_costItem.ID}");
|
||||||
|
if (_product != null) {
|
||||||
|
throw new Exception("Ńňŕňü˙ çŕňđŕň ďđčęđĺďëĺíŕ ę ňîâŕđó čëč ňîâŕđŕě");
|
||||||
}
|
}
|
||||||
|
|
||||||
APIEmployee.PostRequest("api/employee/deletecostitem", new CostItemBindingModel { ID = id });
|
APIEmployee.PostRequest("api/employee/deletecostitem", new CostItemBindingModel { ID = id });
|
||||||
@ -193,7 +228,14 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
|||||||
public IActionResult EditProduct(int id) {
|
public IActionResult EditProduct(int id) {
|
||||||
var _product = APIEmployee.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={id}");
|
var _product = APIEmployee.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={id}");
|
||||||
|
|
||||||
|
|
||||||
if (_product == null) {
|
if (_product == null) {
|
||||||
|
throw new Exception("Îřčáęŕ ďîëó÷ĺíč˙ äŕííűő");
|
||||||
|
}
|
||||||
|
|
||||||
|
var _costitem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={_product.CostItemID}");
|
||||||
|
|
||||||
|
if (_costitem == null) {
|
||||||
return Redirect("/Home/Index");
|
return Redirect("/Home/Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +244,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
|||||||
var obj = new ProductViewModel {
|
var obj = new ProductViewModel {
|
||||||
ProductName = _product.ProductName,
|
ProductName = _product.ProductName,
|
||||||
CostItemID = _product.CostItemID,
|
CostItemID = _product.CostItemID,
|
||||||
Price = _product.Price,
|
Price = _product.Price - _costitem.Price,
|
||||||
ID = _product.ID
|
ID = _product.ID
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -234,7 +276,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void EditProduct(string name, int costitem, double productprice, int _ID, double price) {
|
public void EditProduct(string name, int costitem, int _ID, double price, double productprice) {
|
||||||
if (APIEmployee.Employee == null) {
|
if (APIEmployee.Employee == null) {
|
||||||
throw new Exception("Ňîëüęî äë˙ ŕâňîđčçîâŕííűő");
|
throw new Exception("Ňîëüęî äë˙ ŕâňîđčçîâŕííűő");
|
||||||
}
|
}
|
||||||
@ -261,7 +303,18 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public double Calc(int costitem, double productprice) {
|
public double Calc(int costitem, double productprice) {
|
||||||
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={costitem}");
|
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={costitem}");
|
||||||
return productprice + (_costItem?.Price ?? 500);
|
return productprice + (_costItem?.Price ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public double CalcReload(int costitem, int productid) {
|
||||||
|
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={costitem}");
|
||||||
|
var product = APIEmployee.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={productid}");
|
||||||
|
|
||||||
|
if (product == null) {
|
||||||
|
throw new Exception("Îřčáęŕ ďîëó÷ĺíč˙ äŕííűő");
|
||||||
|
}
|
||||||
|
return product.Price + (_costItem?.Price ?? 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
</th>
|
</th>
|
||||||
<td>
|
<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="EditCostItem" asp-route-ID="@item.ID">Изменить</a>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="DeleteCostItem" asp-route-ID="@item.ID">Удалить</a>
|
<a class="btn btn-primary btn-sm" asp-action="DeleteCostItem" style="background-color:red;" asp-route-ID="@item.ID">Удалить</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,15 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
check();
|
||||||
|
|
||||||
$('#costitem').on('change', function () {
|
$('#costitem').on('change', function () {
|
||||||
check();
|
check();
|
||||||
});
|
});
|
||||||
$('#productprice').on('change', function () {
|
$('#productprice').on('change', function () {
|
||||||
check();
|
check();
|
||||||
});
|
});
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
var costitem = $('#costitem').val();
|
var costitem = $('#costitem').val();
|
||||||
var productprice = $('#productprice').val();
|
var productprice = $('#productprice').val();
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="EditProduct" asp-route-ID="@item.ID">Изменить</a>
|
<a class="btn btn-primary btn-sm" asp-action="EditProduct" asp-route-ID="@item.ID">Изменить</a>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="DeleteProduct" asp-route-ID="@item.ID">Удалить</a>
|
<a class="btn btn-primary btn-sm" asp-action="DeleteProduct" style="background-color:red;" asp-route-ID="@item.ID">Удалить</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,11 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<ProductViewModel>? GetProducts() {
|
public List<ProductViewModel>? GetProducts(int? _costitemid) {
|
||||||
try {
|
try {
|
||||||
|
if (_costitemid != null) {
|
||||||
|
return _product.ReadList(new ProductSearchModel { CostItemID = _costitemid });
|
||||||
|
}
|
||||||
return _product.ReadList(null);
|
return _product.ReadList(null);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@ -43,10 +46,13 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ProductViewModel? GetProduct(int _productID)
|
public ProductViewModel? GetProduct(int? _productID, int? _costitemID)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (_costitemID != null) {
|
||||||
|
return _product.ReadElement(new ProductSearchModel { CostItemID = _costitemID });
|
||||||
|
}
|
||||||
return _product.ReadElement(new ProductSearchModel
|
return _product.ReadElement(new ProductSearchModel
|
||||||
{
|
{
|
||||||
ID = _productID
|
ID = _productID
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
</th>
|
</th>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" asp-route-ID="@item.Key">Удалить</a>
|
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" style="background-color:red;" asp-route-ID="@item.Key">Удалить</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@
|
|||||||
<div class="col-4"></div>
|
<div class="col-4"></div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="submit" value="Заказ готов, вернуться!" class="btn btn-primary" />
|
<input type="submit" value="Заказ готов, вернуться!" class="btn btn-primary" />
|
||||||
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" asp-route-ID="@Model.Item1">Удалить</a>
|
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" style="background-color:red;" asp-route-ID="@Model.Item1">Удалить</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
</th>
|
</th>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" asp-route-ID="@item.Key">Удалить</a>
|
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" style="background-color:red;" asp-route-ID="@item.Key">Удалить</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@
|
|||||||
<div class="col-4"></div>
|
<div class="col-4"></div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="submit" value="Заказ готов, вернуться!" class="btn btn-primary" />
|
<input type="submit" value="Заказ готов, вернуться!" class="btn btn-primary" />
|
||||||
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" asp-route-ID="@Model.Item1">Отменить создание корзины</a>
|
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" style="background-color:red;" asp-route-ID="@Model.Item1">Отменить создание корзины</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="Payment" asp-route-ID="@item.ID">Оплатить</a>
|
<a class="btn btn-primary btn-sm" asp-action="Payment" asp-route-ID="@item.ID">Оплатить</a>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="EditOrder" asp-route-ID="@item.ID">Изменить</a>
|
<a class="btn btn-primary btn-sm" asp-action="EditOrder" asp-route-ID="@item.ID">Изменить</a>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" asp-route-ID="@item.ID">Удалить</a>
|
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" style="background-color:red;" asp-route-ID="@item.ID">Удалить</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4"></div>
|
<div class="col-4"></div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<a class="btn btn-primary btn-sm" asp-action="Index">Отменить - вернуться на главную страницу</a>
|
<a class="btn btn-primary btn-sm" style="background-color:red;" asp-action="Index">Отменить - вернуться на главную страницу</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user