Production fix

This commit is contained in:
Sergey Kozyrev 2024-04-30 23:02:06 +04:00
parent 7f6c257c99
commit 571fc1da8f
3 changed files with 15 additions and 2 deletions

View File

@ -14,7 +14,6 @@ namespace DatabaseImplement.Models
public int DetailId { get; set; }
[Required]
public int ProductionId { get; set; }
public virtual Detail Detail { get; set; } = new();
public virtual Production Production { get; set; } = new();
}

View File

@ -68,7 +68,7 @@ namespace DatabaseImplement.Models
var productionDetails = context.DetailProductions.Where(rec => rec.ProductionId == model.Id).ToList();
if (productionDetails != null && productionDetails.Count > 0)
{
context.DetailProductions.RemoveRange(productionDetails.Where(rec => model.ProductionDetails.ContainsKey(rec.ProductionId)));
context.DetailProductions.RemoveRange(productionDetails.Where(rec => !model.ProductionDetails.ContainsKey(rec.ProductionId)));
context.SaveChanges();
}
var production = context.Productions.First(x => x.Id == model.Id);

View File

@ -14,3 +14,17 @@ ProductionStorage productionionStorage = new ProductionStorage();
ProductStorage productStorage = new ProductStorage();
MachineStorage machineStorage = new MachineStorage();
GuarantorStorage guarantorStorage = new GuarantorStorage();
productionionStorage.Update(new()
{
Id = 4,
Name = "name",
Cost = 1,
UserId = 1,
ProductionDetails = new()
{
{1, detailStorage.GetElement(new() { Id = 1 }) },
{3, detailStorage.GetElement(new() { Id = 3 }) }
}
});