Фикс CarId

This commit is contained in:
Марат Заргаров 2023-05-20 10:56:09 +04:00
parent f01cdafff3
commit eeb2371b91
2 changed files with 18 additions and 4 deletions

View File

@ -17,7 +17,7 @@ namespace CarCenterDatabaseImplement.Implements
public List<PresaleViewModel> 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;
}

View File

@ -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()
{