diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs index ee6afca..85782ae 100644 --- a/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs +++ b/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs @@ -17,7 +17,7 @@ namespace CarCenterDatabaseImplement.Implements public List GetFullList() { using var context = new CarCenterDatabase(); - return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + return context.Presales.Include(x => x.Car).Include(x => x.Employee).Include(x => x.TypeOfJob) .Select(x => x.GetViewModel) .ToList(); } @@ -30,7 +30,7 @@ namespace CarCenterDatabaseImplement.Implements if (model.EmployeeId.HasValue) { using var context = new CarCenterDatabase(); - return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + return context.Presales.Include(x => x.Car).Include(x => x.Employee).Include(x => x.TypeOfJob) .Where(x => x.EmployeeId == model.EmployeeId) .Select(x => x.GetViewModel) .ToList(); @@ -38,7 +38,7 @@ namespace CarCenterDatabaseImplement.Implements else { using var context = new CarCenterDatabase(); - return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + return context.Presales.Include(x => x.Car).Include(x => x.Employee).Include(x => x.TypeOfJob) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -51,7 +51,7 @@ namespace CarCenterDatabaseImplement.Implements return null; } using var context = new CarCenterDatabase(); - return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + return context.Presales.Include(x => x.Car).Include(x => x.Employee).Include(x => x.TypeOfJob) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs b/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs index 0a24156..e808b02 100644 --- a/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs +++ b/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs @@ -16,6 +16,7 @@ namespace CarCenterDatabaseImplement.Models public int Id { get; set; } [Required] public DateTime PresaleDate { get; set; } = DateTime.Now; + public virtual Car Car { get; set; } = new(); public int CarId { get; set; } [Required] public int EmployeeId { get; set; } @@ -36,11 +37,23 @@ namespace CarCenterDatabaseImplement.Models Id = model.Id, Name = model.Name, CarId = model.CarId, + Car = context.Cars.First(x => x.Id == model.CarId), PresaleDate = model.PresaleDate, EmployeeId = model.EmployeeId, Employee = context.Employees.First(x => x.Id == model.EmployeeId) }; } + public static Presale? Create(CarCenterDatabase context, PresaleViewModel model) + { + return new Presale() + { + Id = model.Id, + Name = model.Name, + CarId = model.CarId, + PresaleDate = model.PresaleDate, + Car = context.Cars.First(x => x.Id == model.CarId), + }; + } public void Update(PresaleBindingModel? model) { if (model == null) @@ -49,6 +62,7 @@ namespace CarCenterDatabaseImplement.Models } if (model.TypeOfJobId.HasValue) TypeOfJobId = TypeOfJobId; Name = Name; + CarId = CarId; } public PresaleViewModel GetViewModel => new() {