написал логику обновления
This commit is contained in:
parent
70f28e3c66
commit
b64aa50fc8
@ -124,7 +124,15 @@ namespace HardwareShopRestApi.Controllers
|
||||
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
|
||||
if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
|
||||
purchase.Sum = purchase.Sum + build.Price * count;
|
||||
build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
|
||||
if (build.BuildPurchases.ContainsKey(purchaseId))
|
||||
{
|
||||
|
||||
build.BuildPurchases[purchaseId] = (build.BuildPurchases[purchaseId].Item1, build.BuildPurchases[purchaseId].Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
|
||||
}
|
||||
Update(new BuildBindingModel
|
||||
{
|
||||
Id = buildId,
|
||||
@ -178,6 +186,47 @@ namespace HardwareShopRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public bool UpdateLinkPurchase(int updateBuildId, int updatePurchaseId, int count)
|
||||
{
|
||||
try
|
||||
{
|
||||
var build = GetBuild(updateBuildId);//APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
||||
var purchase = _purchaseLogic.ReadElement(new() { Id = updatePurchaseId });
|
||||
if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
|
||||
purchase.Sum = purchase.Sum + build.Price * count;
|
||||
if (build.BuildPurchases.ContainsKey(updatePurchaseId))
|
||||
{
|
||||
if (count > build.BuildPurchases[updatePurchaseId].Item2)
|
||||
{
|
||||
purchase.Sum = purchase.Sum + (count - build.BuildPurchases[updatePurchaseId].Item2) * build.Price;
|
||||
}
|
||||
else
|
||||
{
|
||||
purchase.Sum = purchase.Sum - (build.BuildPurchases[updatePurchaseId].Item2 - count) * build.Price;
|
||||
}
|
||||
build.BuildPurchases[updatePurchaseId] = (build.BuildPurchases[updatePurchaseId].Item1, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Update(new BuildBindingModel
|
||||
{
|
||||
Id = updateBuildId,
|
||||
Price = build.Price,
|
||||
BuildName = build.BuildName,
|
||||
BuildPurchases = build.BuildPurchases
|
||||
});
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteBuild(BuildBindingModel model)
|
||||
{
|
||||
|
@ -167,21 +167,7 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
{
|
||||
throw new Exception($"Количество сборок в покупке не может быть ниже или равен 0");
|
||||
}
|
||||
//APIClient.PostRequest("api/build/linkPurchase", new { buildId, purchaseId, count });
|
||||
APIClient.GetRequest<bool>($"api/build/linkPurchase?buildId={buildId}&purchaseId={purchaseId}&count={count}");
|
||||
|
||||
//var build = APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
||||
//var purchase = APIClient.GetRequest<PurchaseViewModel>($"api/purchase/getpurchase?purchaseId={purchaseId}");
|
||||
//purchase.Sum = purchase.Sum + build.Price * count;
|
||||
//build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
|
||||
//APIClient.PostRequest("api/build/update", new BuildBindingModel
|
||||
//{
|
||||
// Id = buildId,
|
||||
// Price = build.Price,
|
||||
// BuildName = build.BuildName,
|
||||
// BuildPurchases = build.BuildPurchases
|
||||
//});
|
||||
//APIClient.PostRequest("api/purchase/update", purchase);
|
||||
Response.Redirect($"LinkPurchase?buildId={buildId}");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user