Merge branch 'Storekeeper' into Worker_Raspaev
This commit is contained in:
commit
f07b35cd87
@ -322,7 +322,7 @@ namespace HardwareShopStorekeeperApp.Controllers
|
||||
{
|
||||
throw new Exception($"Цена комплектующего не может быть меньше или равна 0");
|
||||
}
|
||||
APIClient.PostRequest("api/component/updatedata", new ComponentBindingModel
|
||||
APIClient.PostRequest("api/component/updatecomponent", new ComponentBindingModel
|
||||
{
|
||||
Id = component,
|
||||
ComponentName = name,
|
||||
|
@ -25,6 +25,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Комплектующее</th>
|
||||
<th scope="col">Стоимость</th>
|
||||
<th scope="col">Количество</th>
|
||||
<th scope="col">Сумма</th>
|
||||
<th scope="col">Действие</th>
|
||||
@ -74,7 +75,7 @@
|
||||
console.log('try to add component')
|
||||
var count = $('#count').val();
|
||||
var component = $('#component').val();
|
||||
if (component && count)
|
||||
if (component && count && count > 0) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: `/Storekeeper/GetComponent`,
|
||||
@ -96,6 +97,7 @@
|
||||
}).fail(function(xhr, textStatus, errorThrown) {
|
||||
alert(xhr.responseText);
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
saveBtn.addEventListener("click", () => {
|
||||
@ -129,7 +131,7 @@
|
||||
let price = 0;
|
||||
let count = 0;
|
||||
list.forEach((elem) => {
|
||||
resultTable.innerHTML += `<tr><td>${elem.component.componentName}</td><td>${elem.count}</td><td>${Math.round(elem.component.cost * elem.count * 100) / 100}</td><td> \
|
||||
resultTable.innerHTML += `<tr><td>${elem.component.componentName}</td><td>${elem.component.cost}</td><td>${elem.count}</td><td>${Math.round(elem.component.cost * elem.count * 100) / 100}</td><td> \
|
||||
<div> \
|
||||
<button onclick="deleteComponent(${count})" type="button" class="btn btn-danger"> \
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> \
|
||||
|
@ -28,6 +28,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Комплектующее</th>
|
||||
<th scope="col">Стоимость</th>
|
||||
<th scope="col">Количество</th>
|
||||
<th scope="col">Сумма</th>
|
||||
<th scope="col">Действие</th>
|
||||
@ -79,6 +80,7 @@
|
||||
console.log('try to add component')
|
||||
var count = $('#count').val();
|
||||
var component = $('#component').val();
|
||||
if (component && count && count > 0)
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: `/Storekeeper/GetComponent`,
|
||||
@ -133,7 +135,7 @@
|
||||
let price = 0;
|
||||
let count = 0;
|
||||
list.forEach((elem) => {
|
||||
resultTable.innerHTML += `<tr><td>${elem.component.componentName}</td><td>${elem.count}</td><td>${Math.round(elem.component.cost * elem.count * 100) / 100}</td><td> \
|
||||
resultTable.innerHTML += `<tr><td>${elem.component.componentName}</td><td>${elem.component.cost}</td><td>${elem.count}</td><td>${Math.round(elem.component.cost * elem.count * 100) / 100}</td><td> \
|
||||
<div> \
|
||||
<button onclick="deleteComponent(${count})" type="button" class="btn btn-danger"> \
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> \
|
||||
|
@ -19,6 +19,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
|
||||
if (element != null)
|
||||
{
|
||||
var componentGoods = context.GoodsComponents.Where(x => x.ComponentId == element.Id).ToList();
|
||||
var componentBuilds = context.ComponentsBuilds.Where(x => x.ComponentId == element.Id).ToList();
|
||||
componentGoods.ForEach(x =>
|
||||
{
|
||||
var good = context.Goods.Include(x => x.Components).FirstOrDefault(rec => rec.Id == x.GoodId);
|
||||
@ -31,6 +32,15 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
|
||||
good.Price = Math.Round(good.Price, 2);
|
||||
}
|
||||
});
|
||||
componentBuilds.ForEach(x =>
|
||||
{
|
||||
var build = context.Builds.Include(x => x.Components).FirstOrDefault(rec => rec.Id == x.BuildId);
|
||||
if (build != null)
|
||||
{
|
||||
build.Price -= element.Cost * x.Count;
|
||||
build.Price = Math.Round(build.Price, 2);
|
||||
}
|
||||
});
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
@ -121,19 +131,36 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var good = context.Components
|
||||
var component = context.Components
|
||||
.Include(x => x.Builds)
|
||||
.ThenInclude(x => x.Build)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (good == null || good.UserId != model.UserId)
|
||||
if (component == null || component.UserId != model.UserId)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
good.Update(model);
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
if (model.ComponentBuilds == null)
|
||||
{
|
||||
context.Builds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Where(x => x.ContainsComponent(model.Id))
|
||||
.ToList().ForEach(x => { x.Price = x.Components.Sum(x => x.Component.Cost * x.Count); });
|
||||
}
|
||||
else
|
||||
component.UpdateBuilds(context, model);
|
||||
context.Goods
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Where(x => x.ContainsComponent(model.Id))
|
||||
.ToList().ForEach(x => { x.Price = x.Components.Sum(x => x.Component.Cost * x.Count); });
|
||||
context.SaveChanges();
|
||||
good.UpdateBuilds(context, model);
|
||||
transaction.Commit();
|
||||
return good.GetViewModel;
|
||||
return component.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -71,6 +71,11 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public bool ContainsComponent(int componentId)
|
||||
{
|
||||
return GoodComponents.ContainsKey(componentId);
|
||||
}
|
||||
|
||||
public GoodViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
|
@ -91,6 +91,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public bool ContainsComponent(int componentId)
|
||||
{
|
||||
return BuildComponents.ContainsKey(componentId);
|
||||
}
|
||||
|
||||
public BuildViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
|
@ -105,6 +105,21 @@ namespace HardwareShopRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateComponent(ComponentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
model.ComponentBuilds = null!;
|
||||
_component.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных комплектующего");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteComponent(ComponentBindingModel model)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user