реализованно добавление и удаление сборок из покупок
This commit is contained in:
parent
d3b455117e
commit
70f28e3c66
@ -122,6 +122,7 @@ 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;
|
||||
build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
|
||||
Update(new BuildBindingModel
|
||||
@ -131,15 +132,6 @@ namespace HardwareShopRestApi.Controllers
|
||||
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)
|
||||
@ -148,7 +140,44 @@ namespace HardwareShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public bool DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId)
|
||||
{
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
Id = deleteBuildId,
|
||||
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)
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
Response.Redirect("Builds");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpGet]
|
||||
public void LinkBuildPurchase(int buildId, int purchaseId, int count)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
@ -182,7 +182,7 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
// BuildPurchases = build.BuildPurchases
|
||||
//});
|
||||
//APIClient.PostRequest("api/purchase/update", purchase);
|
||||
Response.Redirect("Builds");
|
||||
Response.Redirect($"LinkPurchase?buildId={buildId}");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -423,5 +423,25 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
ViewBag.Purchase = APIClient.GetRequest<List<PurchaseViewModel>>($"api/purchase/getpurchases?userId={APIClient.User.Id}");
|
||||
return View(APIClient.GetRequest<List<Tuple<PurchaseViewModel, int>>>($"api/build/GetBuildPurchase?buildId={buildId}"));
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (deleteBuildId <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0");
|
||||
}
|
||||
if (deletePurchaseId <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификтаор покупки не может быть ниже или равен 0");
|
||||
}
|
||||
APIClient.GetRequest<bool>($"api/build/deleteLinkPurchase?deleteBuildId={deleteBuildId}&deletePurchaseId={deletePurchaseId}");
|
||||
Response.Redirect($"LinkPurchase?buildId={deleteBuildId}");
|
||||
}
|
||||
}
|
||||
}
|
@ -53,12 +53,13 @@
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<button onclick="getURLParameter" type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#updateModal">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i>
|
||||
<button onclick="getPurchase(@item.Item1.Id)" type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#updateModal">
|
||||
Изменить
|
||||
</button>
|
||||
<button onclick="deleteComponent(@item.Item1.Id)" type="button" class="btn btn-danger">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i>
|
||||
<button onclick="getPurchase(@item.Item1.Id)" type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
|
||||
Удалить
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@ -71,7 +72,7 @@
|
||||
<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="post" asp-controller="home" asp-action="LinkBuildPurchase">
|
||||
<form method="get" asp-controller="home" asp-action="LinkBuildPurchase">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Создание сборку</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
@ -94,6 +95,30 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<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">
|
||||
<h1>Вы уверенны что хотите удалить сборку?</h1>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="deleteBuildId" name="deleteBuildId" />
|
||||
<input type="hidden" id="deletePurchaseId" name="deletePurchaseId" />
|
||||
<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>
|
||||
@ -103,12 +128,11 @@
|
||||
getURLParameter(currentUrl, 'buildId');
|
||||
console.log(getURLParameter(currentUrl, 'buildId'));
|
||||
$('#buildId').val(getURLParameter(currentUrl, 'buildId'));
|
||||
$('#deleteBuildId').val(getURLParameter(currentUrl, 'buildId'));
|
||||
var id = document.getElementById("buildId");
|
||||
console.log(id.value);
|
||||
}
|
||||
|
||||
console.log(getURLParameter('http://www.example.com/?page=24&info=13', 'page'));
|
||||
|
||||
function getURLParameter(sUrl, sParam) {
|
||||
let sPageURL = sUrl.substring(sUrl.indexOf('?') + 1);
|
||||
let sURLVariables = sPageURL.split('&');
|
||||
@ -119,6 +143,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
function getPurchase(purchaseId) {
|
||||
getBuild();
|
||||
$('#deletePurchaseId').val(purchaseId);
|
||||
console.log(purchaseId);
|
||||
}
|
||||
</script>
|
||||
}
|
||||
@*
|
||||
|
Loading…
Reference in New Issue
Block a user