Mostly working create rent. Awaiting migration

This commit is contained in:
Dimitar Byalkov
2022-04-09 00:16:58 +03:00
parent 91e835f63d
commit c04ffc5020
3 changed files with 27 additions and 34 deletions

View File

@@ -59,12 +59,14 @@ namespace WebApp.Controllers
[HttpPost]
[ValidateAntiForgeryToken]
[Authorize]
public async Task<IActionResult> Create([Bind("CarId,StartDate,EndDate")] Rents rents)
public async Task<IActionResult> Create(Rents rents)
{
if (ModelState.IsValid)
{
var car = _context.Cars.FirstOrDefault(car => car.Id == 1);
rents.Car = car;
var user = _context.Users.FirstOrDefault(user => user.UserName == User.Identity.Name);
rents.User = user;
_context.Add(rents);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
@@ -95,13 +97,8 @@ namespace WebApp.Controllers
[HttpPost]
[ValidateAntiForgeryToken]
[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)
{
try