bug fixes

This commit is contained in:
Илья Федотов 2024-06-09 20:35:36 +04:00
parent 403f2c1c79
commit a8ccf282e3
13 changed files with 105 additions and 34 deletions

View File

@ -101,7 +101,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
_logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}" +
$"CostNum:{model.CostNum}");
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("Такая статья затрат уде есть");
}

View File

@ -11,7 +11,6 @@ namespace ElectronicsShopContracts.SearchModels
{
public int? ID { get; set; }
public string? ProductName { get; set; }
public string? CostItem { get; set; }
public PaymeantOption? PayOption { get; set; }
public int? CostItemID { get; set; }
}
}

View File

@ -12,7 +12,7 @@ namespace ElectronicsShopContracts.StorageContracts
public interface IProductStorage
{
List<ProductViewModel> GetFullList();
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
List<ProductViewModel>? GetFilteredList(ProductSearchModel model);
ProductViewModel? GetElement(ProductSearchModel model);
ProductViewModel? Insert(ProductBindingModel model);
ProductViewModel? Update(ProductBindingModel model);

View File

@ -57,26 +57,37 @@ namespace ElectronicsShopDataBaseImplement.Implements
public ProductViewModel? GetElement(ProductSearchModel model)
{
if (string.IsNullOrEmpty(model.ProductName) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
if (model.ID.HasValue && !string.IsNullOrEmpty(model.ProductName)) {
return context.Products
.Include(x => x.CostItem)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) ||
(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();
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 null;
}
public List<ProductViewModel> GetFullList()
{

View File

@ -1,4 +1,5 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopEmployeeApp.Models;
using Microsoft.AspNetCore.Mvc;
@ -145,6 +146,15 @@ namespace ElectronicsShopEmployeeApp.Controllers {
if (price <= 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 {
ID = _ID,
Name = name,
@ -152,12 +162,32 @@ namespace ElectronicsShopEmployeeApp.Controllers {
CostNum = costNum,
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");
}
[HttpGet]
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();
}
@ -182,7 +212,12 @@ namespace ElectronicsShopEmployeeApp.Controllers {
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={id}");
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 });
@ -193,7 +228,14 @@ namespace ElectronicsShopEmployeeApp.Controllers {
public IActionResult EditProduct(int id) {
var _product = APIEmployee.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={id}");
if (_product == null) {
throw new Exception("Îřčáęŕ ďîëó÷ĺíč˙ äŕííűő");
}
var _costitem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={_product.CostItemID}");
if (_costitem == null) {
return Redirect("/Home/Index");
}
@ -202,7 +244,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
var obj = new ProductViewModel {
ProductName = _product.ProductName,
CostItemID = _product.CostItemID,
Price = _product.Price,
Price = _product.Price - _costitem.Price,
ID = _product.ID
};
@ -234,7 +276,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
}
[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) {
throw new Exception("Ňîëüęî äë˙ ŕâňîđčçîâŕííűő");
}
@ -261,7 +303,18 @@ namespace ElectronicsShopEmployeeApp.Controllers {
[HttpPost]
public double Calc(int costitem, double productprice) {
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);
}
}
}

View File

@ -61,7 +61,7 @@
</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>
<a class="btn btn-primary btn-sm" asp-action="DeleteCostItem" style="background-color:red;" asp-route-ID="@item.ID">Удалить</a>
</td>
</tr>
}

View File

@ -50,13 +50,15 @@
</form>
<script>
check();
$('#costitem').on('change', function () {
check();
});
$('#productprice').on('change', function () {
check();
});
function check() {
var costitem = $('#costitem').val();
var productprice = $('#productprice').val();

View File

@ -54,7 +54,7 @@
</th>
<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="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>
</tr>
}

View File

@ -33,8 +33,11 @@ namespace ElectronicsShopRestAPI.Controllers {
}
[HttpGet]
public List<ProductViewModel>? GetProducts() {
public List<ProductViewModel>? GetProducts(int? _costitemid) {
try {
if (_costitemid != null) {
return _product.ReadList(new ProductSearchModel { CostItemID = _costitemid });
}
return _product.ReadList(null);
}
catch (Exception ex) {
@ -43,10 +46,13 @@ namespace ElectronicsShopRestAPI.Controllers {
}
}
[HttpGet]
public ProductViewModel? GetProduct(int _productID)
public ProductViewModel? GetProduct(int? _productID, int? _costitemID)
{
try
{
if (_costitemID != null) {
return _product.ReadElement(new ProductSearchModel { CostItemID = _costitemID });
}
return _product.ReadElement(new ProductSearchModel
{
ID = _productID

View File

@ -66,7 +66,7 @@
</th>
<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>
</tr>
}
@ -76,7 +76,7 @@
<div class="col-4"></div>
<div class="col-8">
<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>

View File

@ -66,7 +66,7 @@
</th>
<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>
</tr>
}
@ -77,7 +77,7 @@
<div class="col-4"></div>
<div class="col-8">
<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>

View File

@ -50,7 +50,7 @@
<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="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>
</tr>
}

View File

@ -76,7 +76,7 @@
<div class="row">
<div class="col-4"></div>
<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>