пофиксил обновление цены при привязке сборки к покупке
This commit is contained in:
parent
b84b593b88
commit
d3b455117e
@ -18,12 +18,15 @@ namespace HardwareShopRestApi.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IBuildLogic _buildLogic;
|
private readonly IBuildLogic _buildLogic;
|
||||||
|
private readonly IPurchaseLogic _purchaseLogic;
|
||||||
|
|
||||||
public BuildController(IBuildLogic buildLogic, ILogger<UserController> logger)
|
public BuildController(IBuildLogic buildLogic, IPurchaseLogic purchaseLogic, ILogger<UserController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_buildLogic = buildLogic;
|
_buildLogic = buildLogic;
|
||||||
}
|
_purchaseLogic = purchaseLogic;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<BuildViewModel>? GetBuilds(int userId)
|
public List<BuildViewModel>? GetBuilds(int userId)
|
||||||
@ -112,7 +115,41 @@ namespace HardwareShopRestApi.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpGet]
|
||||||
|
public bool LinkPurchase(int buildId, int purchaseId, int count)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var build = GetBuild(buildId);//APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
||||||
|
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
|
||||||
|
purchase.Sum = purchase.Sum + build.Price * count;
|
||||||
|
build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
|
||||||
|
Update(new BuildBindingModel
|
||||||
|
{
|
||||||
|
Id = buildId,
|
||||||
|
Price = build.Price,
|
||||||
|
BuildName = build.BuildName,
|
||||||
|
BuildPurchases = build.BuildPurchases
|
||||||
|
});
|
||||||
|
|
||||||
|
_purchaseLogic.Update(new PurchaseBindingModel
|
||||||
|
{
|
||||||
|
Id = purchase.Id,
|
||||||
|
Sum = purchase.Sum,
|
||||||
|
PurchaseStatus = purchase.PurchaseStatus,
|
||||||
|
DatePurchase = purchase.DatePurchase,
|
||||||
|
PurchaseGoods = purchase.PurchaseGoods,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления данных");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
public void DeleteBuild(BuildBindingModel model)
|
public void DeleteBuild(BuildBindingModel model)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -40,11 +40,11 @@ namespace HardwareShopRestApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public PurchaseViewModel? GetPurchase(int id)
|
public PurchaseViewModel? GetPurchase(int purchaseId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _purchaseLogic.ReadElement(new() { Id = id });
|
return _purchaseLogic.ReadElement(new() { Id = purchaseId });
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -89,6 +89,20 @@ namespace HardwareShopRestApi.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Update(PurchaseBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_purchaseLogic.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления данных товара");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void DeletePurchase(PurchaseBindingModel model)
|
public void DeletePurchase(PurchaseBindingModel model)
|
||||||
{
|
{
|
||||||
|
@ -167,20 +167,24 @@ namespace HardwareShopWorkerApp.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception($"Количество сборок в покупке не может быть ниже или равен 0");
|
throw new Exception($"Количество сборок в покупке не может быть ниже или равен 0");
|
||||||
}
|
}
|
||||||
var build = APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
//APIClient.PostRequest("api/build/linkPurchase", new { buildId, purchaseId, count });
|
||||||
var purchase = APIClient.GetRequest<BuildViewModel>($"api/purchase/getpurchase?purchaseId={purchaseId}");
|
APIClient.GetRequest<bool>($"api/build/linkPurchase?buildId={buildId}&purchaseId={purchaseId}&count={count}");
|
||||||
build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
|
|
||||||
APIClient.PostRequest("api/build/update", new BuildBindingModel
|
//var build = APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
||||||
{
|
//var purchase = APIClient.GetRequest<PurchaseViewModel>($"api/purchase/getpurchase?purchaseId={purchaseId}");
|
||||||
Id = buildId,
|
//purchase.Sum = purchase.Sum + build.Price * count;
|
||||||
Price = build.Price,
|
//build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
|
||||||
BuildName = build.BuildName,
|
//APIClient.PostRequest("api/build/update", new BuildBindingModel
|
||||||
BuildPurchases = build.BuildPurchases
|
//{
|
||||||
});
|
// Id = buildId,
|
||||||
|
// Price = build.Price,
|
||||||
|
// BuildName = build.BuildName,
|
||||||
|
// BuildPurchases = build.BuildPurchases
|
||||||
|
//});
|
||||||
|
//APIClient.PostRequest("api/purchase/update", purchase);
|
||||||
Response.Redirect("Builds");
|
Response.Redirect("Builds");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void DeleteBuild(int deleteBuildId)
|
public void DeleteBuild(int deleteBuildId)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user