добавили десятый график. сделали 12 этап курсовой работы
This commit is contained in:
parent
6f449c505b
commit
10fb62b17e
@ -322,7 +322,7 @@ namespace HardwareShopStorekeeperApp.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception($"Цена комплектующего не может быть меньше или равна 0");
|
throw new Exception($"Цена комплектующего не может быть меньше или равна 0");
|
||||||
}
|
}
|
||||||
APIClient.PostRequest("api/component/updatedata", new ComponentBindingModel
|
APIClient.PostRequest("api/component/updatecomponent", new ComponentBindingModel
|
||||||
{
|
{
|
||||||
Id = component,
|
Id = component,
|
||||||
ComponentName = name,
|
ComponentName = name,
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Комплектующее</th>
|
<th scope="col">Комплектующее</th>
|
||||||
|
<th scope="col">Стоимость</th>
|
||||||
<th scope="col">Количество</th>
|
<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')
|
console.log('try to add component')
|
||||||
var count = $('#count').val();
|
var count = $('#count').val();
|
||||||
var component = $('#component').val();
|
var component = $('#component').val();
|
||||||
if (component && count)
|
if (component && count && count > 0) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: `/Storekeeper/GetComponent`,
|
url: `/Storekeeper/GetComponent`,
|
||||||
@ -96,6 +97,7 @@
|
|||||||
}).fail(function(xhr, textStatus, errorThrown) {
|
}).fail(function(xhr, textStatus, errorThrown) {
|
||||||
alert(xhr.responseText);
|
alert(xhr.responseText);
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
saveBtn.addEventListener("click", () => {
|
saveBtn.addEventListener("click", () => {
|
||||||
@ -129,7 +131,7 @@
|
|||||||
let price = 0;
|
let price = 0;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
list.forEach((elem) => {
|
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> \
|
<div> \
|
||||||
<button onclick="deleteComponent(${count})" type="button" class="btn btn-danger"> \
|
<button onclick="deleteComponent(${count})" type="button" class="btn btn-danger"> \
|
||||||
<i class="fa fa-trash" aria-hidden="true"></i> \
|
<i class="fa fa-trash" aria-hidden="true"></i> \
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Комплектующее</th>
|
<th scope="col">Комплектующее</th>
|
||||||
|
<th scope="col">Стоимость</th>
|
||||||
<th scope="col">Количество</th>
|
<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')
|
console.log('try to add component')
|
||||||
var count = $('#count').val();
|
var count = $('#count').val();
|
||||||
var component = $('#component').val();
|
var component = $('#component').val();
|
||||||
|
if (component && count && count > 0)
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: `/Storekeeper/GetComponent`,
|
url: `/Storekeeper/GetComponent`,
|
||||||
@ -133,7 +135,7 @@
|
|||||||
let price = 0;
|
let price = 0;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
list.forEach((elem) => {
|
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> \
|
<div> \
|
||||||
<button onclick="deleteComponent(${count})" type="button" class="btn btn-danger"> \
|
<button onclick="deleteComponent(${count})" type="button" class="btn btn-danger"> \
|
||||||
<i class="fa fa-trash" aria-hidden="true"></i> \
|
<i class="fa fa-trash" aria-hidden="true"></i> \
|
||||||
|
@ -19,6 +19,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
|
|||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
var componentGoods = context.GoodsComponents.Where(x => x.ComponentId == element.Id).ToList();
|
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 =>
|
componentGoods.ForEach(x =>
|
||||||
{
|
{
|
||||||
var good = context.Goods.Include(x => x.Components).FirstOrDefault(rec => rec.Id == x.GoodId);
|
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);
|
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.Components.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
@ -121,19 +131,36 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
|
|||||||
using var transaction = context.Database.BeginTransaction();
|
using var transaction = context.Database.BeginTransaction();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var good = context.Components
|
var component = context.Components
|
||||||
.Include(x => x.Builds)
|
.Include(x => x.Builds)
|
||||||
.ThenInclude(x => x.Build)
|
.ThenInclude(x => x.Build)
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (good == null || good.UserId != model.UserId)
|
if (component == null || component.UserId != model.UserId)
|
||||||
{
|
{
|
||||||
return null;
|
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();
|
context.SaveChanges();
|
||||||
good.UpdateBuilds(context, model);
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
return good.GetViewModel;
|
return component.GetViewModel;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -71,6 +71,11 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ContainsComponent(int componentId)
|
||||||
|
{
|
||||||
|
return GoodComponents.ContainsKey(componentId);
|
||||||
|
}
|
||||||
|
|
||||||
public GoodViewModel GetViewModel => new()
|
public GoodViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
@ -91,6 +91,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ContainsComponent(int componentId)
|
||||||
|
{
|
||||||
|
return BuildComponents.ContainsKey(componentId);
|
||||||
|
}
|
||||||
|
|
||||||
public BuildViewModel GetViewModel => new()
|
public BuildViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
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]
|
[HttpPost]
|
||||||
public void DeleteComponent(ComponentBindingModel model)
|
public void DeleteComponent(ComponentBindingModel model)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user