fixed crash on car renting

This commit is contained in:
Dimitar Todorov
2022-04-07 21:58:11 +03:00
parent 6f246bff8b
commit 7a352c35f6
10 changed files with 52 additions and 550 deletions

View File

@@ -44,7 +44,7 @@ namespace WebApp.Controllers
}
// GET: Rents/Create
public IActionResult Create()
public IActionResult Create(int id)
{
return View();
}
@@ -58,6 +58,8 @@ namespace WebApp.Controllers
{
if (ModelState.IsValid)
{
var car = _context.Cars.FirstOrDefault(car => car.Id == 1);
rents.Car = car;
_context.Add(rents);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));

View File

@@ -32,7 +32,9 @@
<th>
@Html.DisplayNameFor(model => model.PriceForDay)
</th>
<th></th>
<th>
Select
</th>
</tr>
</thead>
<tbody>
@@ -57,6 +59,9 @@
<td>
@Html.DisplayFor(modelItem => item.PriceForDay)
</td>
<td>
<a asp-controller="Rents" asp-action="Create">Select</a>
</td>
@if (this.User.IsInRole("Admin"))
{
<td>

View File

@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;"
"DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;"
},
"Logging": {
"LogLevel": {

View File

@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;"
"DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;"
},
"Logging": {
"LogLevel": {