diff --git a/RentACar/Data/Models/Rents.cs b/RentACar/Data/Models/Rents.cs index 807b722..dcda45b 100644 --- a/RentACar/Data/Models/Rents.cs +++ b/RentACar/Data/Models/Rents.cs @@ -13,16 +13,14 @@ namespace Data.Entities { public int Id { get; set; } [Required] - [ForeignKey("Car")] - public int CarId { get; set; } - public virtual Car Car { get; set; } + [ForeignKey("CarId")] + public Car Car { get; set; } [Required] public DateTime StartDate { get; set; } [Required] public DateTime EndDate { get; set; } - [ForeignKey("User")] - public string UserId { get; set; } - public virtual User User { get; set; } + [ForeignKey("UserId")] + public User User { get; set; } } } diff --git a/RentACar/WebApp/Controllers/RentsController.cs b/RentACar/WebApp/Controllers/RentsController.cs index 574d066..c402911 100644 --- a/RentACar/WebApp/Controllers/RentsController.cs +++ b/RentACar/WebApp/Controllers/RentsController.cs @@ -60,11 +60,11 @@ namespace WebApp.Controllers [HttpPost] [ValidateAntiForgeryToken] - public async Task Create([Bind("Id,Car.Id,StartDate,EndDate,UserId")] Rents rents) + public async Task Create([Bind("Id,CarId,StartDate,EndDate,UserId")] Rents rents) { if (ModelState.IsValid) { - var car = _context.Cars.FirstOrDefault(car => car.Id == rents.Car.Id); + var car = _context.Cars.FirstOrDefault(car => car.Id == rents.CarId); rents.Car = car; _context.Add(rents); await _context.SaveChangesAsync(); diff --git a/RentACar/WebApp/Views/Rents/Create.cshtml b/RentACar/WebApp/Views/Rents/Create.cshtml index 0e221a3..0bca600 100644 --- a/RentACar/WebApp/Views/Rents/Create.cshtml +++ b/RentACar/WebApp/Views/Rents/Create.cshtml @@ -10,9 +10,9 @@
- - - + + +
diff --git a/RentACar/WebApp/Views/Rents/Index.cshtml b/RentACar/WebApp/Views/Rents/Index.cshtml index afc1c5f..49a9107 100644 --- a/RentACar/WebApp/Views/Rents/Index.cshtml +++ b/RentACar/WebApp/Views/Rents/Index.cshtml @@ -36,7 +36,7 @@ { - @Html.DisplayFor(modelItem => item.Car.Id) + @Html.DisplayFor(modelItem => item.CarId) @Html.DisplayFor(modelItem => item.StartDate)