Mostly working create rent. Awaiting migration
This commit is contained in:
@@ -12,22 +12,12 @@ namespace Data.Entities
|
|||||||
[Required]
|
[Required]
|
||||||
[Key]
|
[Key]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string Brand { get; set; }
|
public string Brand { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string Model { get; set; }
|
public string Model { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int Year { get; set; }
|
public int Year { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int CountPassengerSeats { get; set; }
|
public int CountPassengerSeats { get; set; }
|
||||||
|
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public decimal PriceForDay { get; set; }
|
public decimal PriceForDay { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,12 +59,14 @@ namespace WebApp.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<IActionResult> Create([Bind("CarId,StartDate,EndDate")] Rents rents)
|
public async Task<IActionResult> Create(Rents rents)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
var car = _context.Cars.FirstOrDefault(car => car.Id == 1);
|
var car = _context.Cars.FirstOrDefault(car => car.Id == 1);
|
||||||
rents.Car = car;
|
rents.Car = car;
|
||||||
|
var user = _context.Users.FirstOrDefault(user => user.UserName == User.Identity.Name);
|
||||||
|
rents.User = user;
|
||||||
_context.Add(rents);
|
_context.Add(rents);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
@@ -95,13 +97,8 @@ namespace WebApp.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
[Authorize(Roles = "Admin")]
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Edit(int id, [Bind("CarId,StartDate,EndDate")] Rents rents)
|
public async Task<IActionResult> Edit(Rents rents)
|
||||||
{
|
{
|
||||||
if (id != rents.Id)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -23,6 +23,9 @@
|
|||||||
<th>
|
<th>
|
||||||
End Date
|
End Date
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
User
|
||||||
|
</th>
|
||||||
@if (this.User.IsInRole("Admin"))
|
@if (this.User.IsInRole("Admin"))
|
||||||
{
|
{
|
||||||
<th>
|
<th>
|
||||||
@@ -34,25 +37,28 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var item in Model)
|
@foreach (var item in Model)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Car.Id)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.StartDate)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.EndDate)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.User.UserName)
|
||||||
|
</td>
|
||||||
|
@if (this.User.IsInRole("Admin"))
|
||||||
|
{
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Car.Id)
|
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
|
||||||
|
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
|
||||||
|
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
}
|
||||||
@Html.DisplayFor(modelItem => item.StartDate)
|
</tr>
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.EndDate)
|
|
||||||
</td>
|
|
||||||
@if (this.User.IsInRole("Admin"))
|
|
||||||
{
|
|
||||||
<td>
|
|
||||||
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
|
|
||||||
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
|
|
||||||
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
|
|
||||||
</td>
|
|
||||||
}
|
|
||||||
</tr>
|
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user