Compare commits

...

2 Commits

5 changed files with 25 additions and 17 deletions

View File

@ -7,6 +7,6 @@ namespace ComputerHardwareStoreContracts.BindingModels
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public double Cost { get; set; }
public int StoreKeeperId { get; set; }
public IStoreKeeperModel StoreKeeper { get; set; }
}
}

View File

@ -10,6 +10,6 @@ namespace ComputerHardwareStoreContracts.ViewModels
public string Name { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Cost { get; set; }
public int StoreKeeperId { get; set; }
public IStoreKeeperModel StoreKeeper { get; set; }
}
}

View File

@ -4,6 +4,6 @@
{
string Name { get; }
double Cost { get; }
int StoreKeeperId { get; }
IStoreKeeperModel StoreKeeper { get; }
}
}

View File

@ -14,8 +14,9 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
[Required]
public double Cost { get; set; }
[Required]
public int StoreKeeperId { get; private set; }
public virtual StoreKeeper? StoreKeeper { get; set; }
[NotMapped]
IStoreKeeperModel IComponentModel.StoreKeeper => throw new NotImplementedException();
[ForeignKey("ComponentId")]
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
@ -30,7 +31,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
StoreKeeper = context.StoreKeepers.First(x => x.Id == model.StoreKeeperId)
StoreKeeper = context.StoreKeepers.First(x => x.Id == model.StoreKeeper.Id)
};
}
public void Update (ComponentBindingModel model)

View File

@ -58,18 +58,25 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Id = model.Id,
Cost = model.Cost,
DateCreate = model.DateCreate,
Builds = model.PurchaseBuilds.Select(x =>
new PurchaseBuild
{
Build = context.Builds.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList(),
Products = model.PurchaseProducts.Select(x =>
new PurchaseProduct
{
Product = context.Products.First(z => z.Id == z.Key),
Count = x.Value.Item2
}).ToList()
Builds = context.Builds
.Where(b => model.PurchaseBuilds.ContainsKey(b.Id))
.Select(b => new PurchaseBuild()
{
PurchaseId = model.Id,
BuildId = b.Id,
Build = b,
Count = model.PurchaseProducts[b.Id].Item2
}).ToList(),
Products = context.Products
.Where(p => model.PurchaseProducts.ContainsKey(p.Id))
.Select (p => new PurchaseProduct()
{
PurchaseId = model.Id,
ProductId = p.Id,
Product = p,
Count = model.PurchaseProducts[p.Id].Item2
})
.ToList()
};
}
public void Update(PurchaseBindingModel model)