Compare commits
2 Commits
245f5de6ca
...
8a4a34b232
Author | SHA1 | Date | |
---|---|---|---|
8a4a34b232 | |||
fb65ccd9a2 |
@ -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("Марка")]
|
||||
|
@ -29,5 +29,6 @@ namespace CarCenterDatabaseImplement
|
||||
public virtual DbSet<Request> Requests { set; get; }
|
||||
public virtual DbSet<Feature> Features { set; get; }
|
||||
public virtual DbSet<Bundling> Bundlings { set; get; }
|
||||
public virtual DbSet<CarBundling> CarBundlings { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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,8 +68,28 @@ 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 UpdateBundlings(CarCenterDatabase context, CarBindingModel model)
|
||||
{
|
||||
var car = context.Cars.First(x => x.Id == Id);
|
||||
foreach (var pc in model.CarBundlings)
|
||||
{
|
||||
context.CarBundlings.Add(new CarBundling
|
||||
{
|
||||
Car = car,
|
||||
Bundling = context.Bundlings.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_carBundlings = null;
|
||||
}
|
||||
|
||||
public void Update(CarBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -85,6 +120,7 @@ namespace CarCenterDatabaseImplement.Models
|
||||
Price = Price,
|
||||
VINnumber = VINnumber,
|
||||
FeatureID = FeatureID,
|
||||
CarBundlings = CarBundlings,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
21
CarCenter/CarCenterDatabaseImplement/Models/CarBundling.cs
Normal file
21
CarCenter/CarCenterDatabaseImplement/Models/CarBundling.cs
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user