пурчайз

This commit is contained in:
bekodeg 2024-04-30 20:06:35 +04:00
parent af397abdac
commit 4fe042017b
5 changed files with 25 additions and 17 deletions

View File

@ -7,6 +7,6 @@ namespace ComputerHardwareStoreContracts.BindingModels
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public double Cost { get; set; } 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; public string Name { get; set; } = string.Empty;
[DisplayName("Цена")] [DisplayName("Цена")]
public double Cost { get; set; } public double Cost { get; set; }
public int StoreKeeperId { get; set; } public IStoreKeeperModel StoreKeeper { get; set; }
} }
} }

View File

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

View File

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

View File

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