mg1
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ namespace WebApp.Controllers
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
|
||||
public async Task<IActionResult> Create([Bind("Id,Car.Id,StartDate,EndDate,UserId")] Rents rents)
|
||||
public async Task<IActionResult> 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();
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
<div class="col-md-4">
|
||||
<form asp-action="Create">
|
||||
<div class="form-group">
|
||||
<label asp-for="Car.Id" class="control-label"></label>
|
||||
<input asp-for="Car.Id" class="form-control" />
|
||||
<span asp-validation-for="Car.Id" class="text-danger"></span>
|
||||
<label asp-for="CarId" class="control-label"></label>
|
||||
<input asp-for="CarId" class="form-control" />
|
||||
<span asp-validation-for="CarId" class="text-danger"></span>
|
||||
</div>
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Car.Id)
|
||||
@Html.DisplayFor(modelItem => item.CarId)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.StartDate)
|
||||
|
||||
Reference in New Issue
Block a user