Фикс CarId
This commit is contained in:
parent
f01cdafff3
commit
eeb2371b91
@ -17,7 +17,7 @@ namespace CarCenterDatabaseImplement.Implements
|
|||||||
public List<PresaleViewModel> GetFullList()
|
public List<PresaleViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new CarCenterDatabase();
|
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)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ namespace CarCenterDatabaseImplement.Implements
|
|||||||
if (model.EmployeeId.HasValue)
|
if (model.EmployeeId.HasValue)
|
||||||
{
|
{
|
||||||
using var context = new CarCenterDatabase();
|
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)
|
.Where(x => x.EmployeeId == model.EmployeeId)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -38,7 +38,7 @@ namespace CarCenterDatabaseImplement.Implements
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
using var context = new CarCenterDatabase();
|
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)
|
.Where(x => x.Id == model.Id)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -51,7 +51,7 @@ namespace CarCenterDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new CarCenterDatabase();
|
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)
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ namespace CarCenterDatabaseImplement.Models
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime PresaleDate { get; set; } = DateTime.Now;
|
public DateTime PresaleDate { get; set; } = DateTime.Now;
|
||||||
|
public virtual Car Car { get; set; } = new();
|
||||||
public int CarId { get; set; }
|
public int CarId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int EmployeeId { get; set; }
|
public int EmployeeId { get; set; }
|
||||||
@ -36,11 +37,23 @@ namespace CarCenterDatabaseImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
CarId = model.CarId,
|
CarId = model.CarId,
|
||||||
|
Car = context.Cars.First(x => x.Id == model.CarId),
|
||||||
PresaleDate = model.PresaleDate,
|
PresaleDate = model.PresaleDate,
|
||||||
EmployeeId = model.EmployeeId,
|
EmployeeId = model.EmployeeId,
|
||||||
Employee = context.Employees.First(x => x.Id == 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)
|
public void Update(PresaleBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -49,6 +62,7 @@ namespace CarCenterDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
if (model.TypeOfJobId.HasValue) TypeOfJobId = TypeOfJobId;
|
if (model.TypeOfJobId.HasValue) TypeOfJobId = TypeOfJobId;
|
||||||
Name = Name;
|
Name = Name;
|
||||||
|
CarId = CarId;
|
||||||
}
|
}
|
||||||
public PresaleViewModel GetViewModel => new()
|
public PresaleViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user