mg1
This commit is contained in:
@@ -13,16 +13,14 @@ namespace Data.Entities
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
[ForeignKey("Car")]
|
[ForeignKey("CarId")]
|
||||||
public int CarId { get; set; }
|
public Car Car { get; set; }
|
||||||
public virtual Car Car { get; set; }
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime StartDate { get; set; }
|
public DateTime StartDate { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime EndDate { get; set; }
|
public DateTime EndDate { get; set; }
|
||||||
|
|
||||||
[ForeignKey("User")]
|
[ForeignKey("UserId")]
|
||||||
public string UserId { get; set; }
|
public User User { get; set; }
|
||||||
public virtual User User { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ namespace WebApp.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[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)
|
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;
|
rents.Car = car;
|
||||||
_context.Add(rents);
|
_context.Add(rents);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<form asp-action="Create">
|
<form asp-action="Create">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="Car.Id" class="control-label"></label>
|
<label asp-for="CarId" class="control-label"></label>
|
||||||
<input asp-for="Car.Id" class="form-control" />
|
<input asp-for="CarId" class="form-control" />
|
||||||
<span asp-validation-for="Car.Id" class="text-danger"></span>
|
<span asp-validation-for="CarId" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Car.Id)
|
@Html.DisplayFor(modelItem => item.CarId)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.StartDate)
|
@Html.DisplayFor(modelItem => item.StartDate)
|
||||||
|
|||||||
Reference in New Issue
Block a user