fix purchase

This commit is contained in:
Николай 2023-05-16 19:49:58 +04:00
parent f032fc0f44
commit d498e507ff
5 changed files with 15 additions and 7 deletions

View File

@ -75,7 +75,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
model.PurchaseStatus = PurchaseStatus.Выдан;
model.DatePurchase = DateTime.Now;
CheckModel(model, false);
if (_purchaseStorage.Update(model) == null)
if (_purchaseStorage.Update(model, false) == null)
{
_logger.LogWarning("Change status operation failed");
return false;

View File

@ -11,7 +11,7 @@ namespace HardwareShopContracts.StoragesContracts
List<PurchaseViewModel> GetReportFilteredList(PurchaseSearchModel model);
PurchaseViewModel? GetElement(PurchaseSearchModel model);
PurchaseViewModel? Insert(PurchaseBindingModel model);
PurchaseViewModel? Update(PurchaseBindingModel model);
PurchaseViewModel? Update(PurchaseBindingModel model, bool withParams = true);
PurchaseViewModel? Delete(PurchaseBindingModel model);
}
}

View File

@ -101,7 +101,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
?.GetViewModel;
}
public PurchaseViewModel? Update(PurchaseBindingModel model)
public PurchaseViewModel? Update(PurchaseBindingModel model, bool withParams = true)
{
using var context = new HardwareShopDatabase();
using var transaction = context.Database.BeginTransaction();
@ -117,7 +117,11 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
}
purchase.Update(model);
context.SaveChanges();
purchase.UpdateGoods(context, model);
if (!withParams) {
transaction.Commit();
return purchase.GetViewModel;
}
purchase.UpdateGoods(context, model);
transaction.Commit();
return purchase.GetViewModel;
}

View File

@ -3,6 +3,7 @@ using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.Storekeeper;
using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Models;
using HardwareShopRestApi.Controllers;
using Microsoft.AspNetCore.Mvc;
@ -59,8 +60,7 @@ namespace HardwareShopRestApi.Controllers
{
for (int i = 0; i < model.PurchaseGoodsCounts.Count; i++)
{
model.PurchaseGoods.Add(model.ListPurchaseGoods[i].Id,
(model.ListPurchaseGoods[i] as IGoodModel, model.PurchaseGoodsCounts[i]));
model.PurchaseGoods.Add(model.ListPurchaseGoods[i].Id,(model.ListPurchaseGoods[i] as IGoodModel, model.PurchaseGoodsCounts[i]));
}
_purchaseLogic.Create(model);
}
@ -76,6 +76,10 @@ namespace HardwareShopRestApi.Controllers
{
try
{
var oldModel = _purchaseLogic.ReadElement(new() {
Id = model.Id,
});
model.Sum = oldModel.Sum;
_purchaseLogic.DeliveryPurchase(model);
}
catch (Exception ex)

View File

@ -106,7 +106,7 @@
contentType: 'application/json',
data: JSON.stringify({
"Sum": parseFloat(totalSum.value),
"ListPurchaseGoods": goods
"ListPurchaseGoods": goods, "PurchaseGoodsCounts": counts
})
}
).done(() => window.location.href = '/Home/Purchases')