Trying to implement assembly crud
This commit is contained in:
@@ -19,8 +19,9 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
public string AssemblyName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _assemblyComponents =
|
||||
null;
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _assemblyComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents
|
||||
{
|
||||
@@ -39,6 +40,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
public virtual List<AssemblyComponent> Components { get; set; } = new();
|
||||
[ForeignKey("AssemblyId")]
|
||||
public virtual List<AssemblyOrder> Orders { get; set; } = new();
|
||||
public virtual Client Client { get; set; }
|
||||
public static Assembly Create(ComputerShopDatabase context, AssemblyBindingModel model)
|
||||
{
|
||||
return new Assembly()
|
||||
@@ -46,6 +48,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
Id = model.Id,
|
||||
AssemblyName = model.AssemblyName,
|
||||
Price = model.Price,
|
||||
ClientId = model.ClientId,
|
||||
Components = model.AssemblyComponents.Select(x => new
|
||||
AssemblyComponent
|
||||
{
|
||||
@@ -64,12 +67,12 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
Id = Id,
|
||||
AssemblyName = AssemblyName,
|
||||
Price = Price,
|
||||
AssemblyComponents = AssemblyComponents
|
||||
AssemblyComponents = AssemblyComponents,
|
||||
ClientId = ClientId
|
||||
};
|
||||
public void UpdateComponents(ComputerShopDatabase context, AssemblyBindingModel model)
|
||||
{
|
||||
var assemblyComponents = context.AssemblyComponents.Where(rec =>
|
||||
rec.Id == model.Id).ToList();
|
||||
var assemblyComponents = context.AssemblyComponents.Where(rec => rec.Id == model.Id).ToList();
|
||||
if (assemblyComponents != null && assemblyComponents.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.AssemblyComponents.RemoveRange(assemblyComponents.Where(rec
|
||||
|
||||
Reference in New Issue
Block a user