fix linkpurchase
This commit is contained in:
parent
b64aa50fc8
commit
fe06bc28e1
@ -80,6 +80,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
return context.Purchases
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.Builds)
|
||||
.ThenInclude(x => x.Build)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BusinessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
||||
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using HardwareShopDataModels.Enums;
|
||||
@ -123,11 +124,10 @@ namespace HardwareShopRestApi.Controllers
|
||||
var build = GetBuild(buildId);//APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
||||
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
|
||||
if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
|
||||
purchase.Sum = purchase.Sum + build.Price * count;
|
||||
if (build.BuildPurchases.ContainsKey(purchaseId))
|
||||
{
|
||||
|
||||
build.BuildPurchases[purchaseId] = (build.BuildPurchases[purchaseId].Item1, build.BuildPurchases[purchaseId].Item2 + count);
|
||||
build.BuildPurchases[purchaseId] = (purchase, build.BuildPurchases[purchaseId].Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -140,6 +140,14 @@ namespace HardwareShopRestApi.Controllers
|
||||
BuildName = build.BuildName,
|
||||
BuildPurchases = build.BuildPurchases
|
||||
});
|
||||
purchase.Sum = Calc(purchase.Id);
|
||||
_purchaseLogic.Update(new PurchaseBindingModel
|
||||
{
|
||||
Id = purchase.Id,
|
||||
Sum = purchase.Sum,
|
||||
PurchaseStatus = purchase.PurchaseStatus,
|
||||
PurchaseGoods = purchase.PurchaseGoods,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -148,7 +156,20 @@ namespace HardwareShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private double Calc(int purchaseId)
|
||||
{
|
||||
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
|
||||
double price = 0;
|
||||
foreach (var elem in purchase.PurchaseBuilds)
|
||||
{
|
||||
price += ((elem.Value.Item1?.Price ?? 0) * elem.Value.Item2);
|
||||
}
|
||||
foreach (var elem in purchase.PurchaseGoods)
|
||||
{
|
||||
price += ((elem.Value.Item1?.Price ?? 0) * elem.Value.Item2);
|
||||
}
|
||||
return Math.Round(price * 1.1, 2);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public bool DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId)
|
||||
@ -158,7 +179,6 @@ namespace HardwareShopRestApi.Controllers
|
||||
var build = GetBuild(deleteBuildId);//APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
||||
var purchase = _purchaseLogic.ReadElement(new() { Id = deletePurchaseId });
|
||||
if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
|
||||
purchase.Sum = purchase.Sum - build.Price * build.BuildPurchases[deletePurchaseId].Item2;
|
||||
build.BuildPurchases.Remove(deletePurchaseId);//Add(purchaseId, (purchase as IPurchaseModel, count));
|
||||
|
||||
Update(new BuildBindingModel
|
||||
@ -168,7 +188,7 @@ namespace HardwareShopRestApi.Controllers
|
||||
BuildName = build.BuildName,
|
||||
BuildPurchases = build.BuildPurchases
|
||||
});
|
||||
|
||||
purchase.Sum = Calc(purchase.Id);
|
||||
_purchaseLogic.Update(new PurchaseBindingModel
|
||||
{
|
||||
Id = purchase.Id,
|
||||
@ -194,17 +214,8 @@ namespace HardwareShopRestApi.Controllers
|
||||
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
|
||||
@ -218,6 +229,15 @@ namespace HardwareShopRestApi.Controllers
|
||||
BuildName = build.BuildName,
|
||||
BuildPurchases = build.BuildPurchases
|
||||
});
|
||||
purchase.Sum = Calc(purchase.Id);
|
||||
_purchaseLogic.Update(new PurchaseBindingModel
|
||||
{
|
||||
Id = purchase.Id,
|
||||
Sum = purchase.Sum,
|
||||
PurchaseStatus = purchase.PurchaseStatus,
|
||||
DatePurchase = purchase.DatePurchase,
|
||||
PurchaseGoods = purchase.PurchaseGoods,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -411,7 +411,7 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[HttpGet]
|
||||
public void DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
@ -429,5 +429,24 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
APIClient.GetRequest<bool>($"api/build/deleteLinkPurchase?deleteBuildId={deleteBuildId}&deletePurchaseId={deletePurchaseId}");
|
||||
Response.Redirect($"LinkPurchase?buildId={deleteBuildId}");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public void UpdateLinkPurchase(int updateBuildId, int updatePurchaseId, int count)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (updateBuildId <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0");
|
||||
}
|
||||
if (updatePurchaseId <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификтаор покупки не может быть ниже или равен 0");
|
||||
}
|
||||
APIClient.GetRequest<bool>($"api/build/UpdateLinkPurchase?updateBuildId={updateBuildId}&updatePurchaseId={updatePurchaseId}&count={count}");
|
||||
Response.Redirect($"LinkPurchase?buildId={updateBuildId}");
|
||||
}
|
||||
}
|
||||
}
|
@ -98,7 +98,7 @@
|
||||
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="post" asp-controller="home" asp-action="DeleteLinkPurchase">
|
||||
<form method="get" asp-controller="home" asp-action="DeleteLinkPurchase">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Удаление покупки</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
@ -119,6 +119,31 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="get" asp-controller="home" asp-action="UpdateLinkPurchase">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Создание сборку</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Количество</label>
|
||||
<input type="number" class="form-control" required="required" name="count" />
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="updateBuildId" name="updateBuildId" />
|
||||
<input type="hidden" id="updatePurchaseId" name="updatePurchaseId" />
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<input type="submit" class="btn btn-primary" value="Сохранить">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
@ -126,10 +151,12 @@
|
||||
let currentUrl = window.location.href;
|
||||
console.log(currentUrl);
|
||||
getURLParameter(currentUrl, 'buildId');
|
||||
console.log(getURLParameter(currentUrl, 'buildId'));
|
||||
$('#buildId').val(getURLParameter(currentUrl, 'buildId'));
|
||||
$('#deleteBuildId').val(getURLParameter(currentUrl, 'buildId'));
|
||||
var id = document.getElementById("buildId");
|
||||
let buildId = getURLParameter(currentUrl, 'buildId');
|
||||
console.log(buildId);
|
||||
$('#buildId').val(buildId);
|
||||
$('#deleteBuildId').val(buildId);
|
||||
$('#updateBuildId').val(buildId);
|
||||
var id = document.getElementById("updateBuildId");
|
||||
console.log(id.value);
|
||||
}
|
||||
|
||||
@ -146,6 +173,7 @@
|
||||
function getPurchase(purchaseId) {
|
||||
getBuild();
|
||||
$('#deletePurchaseId').val(purchaseId);
|
||||
$('#updatePurchaseId').val(purchaseId);
|
||||
console.log(purchaseId);
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user