Compare commits
No commits in common. "8a4a34b232e21474b7097fecc6988f4ec2cf8b10" and "245f5de6ca891b7d48ac2b8e2ac65b424d59cd79" have entirely different histories.
8a4a34b232
...
245f5de6ca
@ -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,6 +29,5 @@ 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,7 +6,6 @@ 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;
|
||||
@ -24,8 +23,6 @@ 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,7 +6,6 @@ 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;
|
||||
@ -16,7 +15,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.Неизвестно;
|
||||
@ -32,25 +31,11 @@ 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; }
|
||||
|
||||
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)
|
||||
public static Car? Create(CarBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -68,28 +53,8 @@ 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)
|
||||
@ -120,7 +85,6 @@ namespace CarCenterDatabaseImplement.Models
|
||||
Price = Price,
|
||||
VINnumber = VINnumber,
|
||||
FeatureID = FeatureID,
|
||||
CarBundlings = CarBundlings,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
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