Многие-ко-многим Машина Комплектации

This commit is contained in:
Леонид Малафеев 2024-04-28 16:41:15 +04:00
parent 245f5de6ca
commit fb65ccd9a2
4 changed files with 47 additions and 4 deletions

View File

@ -15,7 +15,7 @@ namespace CarCenterContracts.ViewModels
public int? FeatureId { get; set; }
[DisplayName("Цена особенности")]
public double FeaturePrice { get; set; }
public int? StorekeeperId { get; set; }
public int StorekeeperId { get; set; }
[DisplayName("Имя работника")]
public string StorekeeperName { get; set; } = string.Empty;
[DisplayName("Марка")]

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -23,6 +24,8 @@ namespace CarCenterDatabaseImplement.Models
public ToolKit ToolKit { get; set; } = ToolKit.Неизвестно;
[Required]
public double Price { get; set; }
[ForeignKey("BundlingId")]
public virtual List<CarBundling> CarBundling { get; set; } = new();
public static Bundling? Create(BundlingBindingModel model)
{
if (model == null)

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -15,7 +16,7 @@ namespace CarCenterDatabaseImplement.Models
public class Car : ICarModel
{
public int Id { get; private set; }
public int? StorekeeperId { get; set; }
public int StorekeeperId { get; set; }
public int? FeatureId { get; set; }
[Required]
public CarBrand CarBrand { get; set; } = CarBrand.Неизвестно;
@ -31,11 +32,25 @@ namespace CarCenterDatabaseImplement.Models
public long VINnumber { get; set; }
[Required]
public int FeatureID { get; set; }
public Dictionary<int, IBundlingModel> CarBundlings { get; set; } = new();
public virtual Storekeeper Storekeeper { get; set; }
public virtual Feature Feature { get; set; }
public static Car? Create(CarBindingModel model)
private Dictionary<int, IBundlingModel>? _carBundlings = null;
[ForeignKey("CarId")]
public virtual List<CarBundling> Bundlings { get; set; } = new();
[NotMapped]
public Dictionary<int, IBundlingModel> CarBundlings
{
get
{
if (_carBundlings == null)
{
_carBundlings = Bundlings.ToDictionary(recPc => recPc.BundlingId, recPc => recPc.Bundling as IBundlingModel);
}
return _carBundlings;
}
}
public static Car? Create(CarCenterDatabase context, CarBindingModel model)
{
if (model == null)
{
@ -53,6 +68,10 @@ namespace CarCenterDatabaseImplement.Models
Price = model.Price,
VINnumber = model.VINnumber,
FeatureID = model.FeatureID,
Bundlings = model.CarBundlings.Select(x => new CarBundling
{
Bundling = context.Bundlings.First(y => y.Id == x.Key)
}).ToList()
};
}
public void Update(CarBindingModel model)

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarCenterDatabaseImplement.Models
{
public class CarBundling
{
public int Id { get; set; }
[Required]
public int CarId { get; set; }
[Required]
public int BundlingId { get; set; }
[Required]
public virtual Car Car { get; set; } = new();
public virtual Bundling Bundling { get; set; } = new();
}
}