commiting some changes

This commit is contained in:
ani_konarcheva@abv.bg
2022-04-08 14:05:16 +03:00
parent e1f462fb1d
commit 547c6e8774
10 changed files with 56 additions and 37 deletions

View File

@@ -20,7 +20,7 @@ namespace Data
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("Server=.;Database=RentACar;Integrated Security=true;");
optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;");
}
}

View File

@@ -10,6 +10,7 @@ namespace Data.Entities
public class Car
{
[Required]
[Key]
public int Id { get; set; }
[Required]

View File

@@ -54,11 +54,11 @@ namespace WebApp.Controllers
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,StartDate,EndDate")] 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 == 1);
var car = _context.Cars.FirstOrDefault(car => car.Id == rents.CarId);
rents.Car = car;
_context.Add(rents);
await _context.SaveChangesAsync();
@@ -88,7 +88,7 @@ namespace WebApp.Controllers
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("Id,StartDate,EndDate")] Rents rents)
public async Task<IActionResult> Edit(int id, [Bind("Id,CarId,StartDate,EndDate,UserId")] Rents rents)
{
if (id != rents.Id)
{

View File

@@ -39,7 +39,7 @@ namespace API
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.User.RequireUniqueEmail = false;
options.User.RequireUniqueEmail = true;
})
.AddRoles<IdentityRole>()
.AddDefaultUI()
@@ -78,6 +78,7 @@ namespace API
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
}
}

View File

@@ -14,6 +14,9 @@
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Brand)
</th>
@@ -40,36 +43,39 @@
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Brand)
</td>
<td>
@Html.DisplayFor(modelItem => item.Model)
</td>
<td>
@Html.DisplayFor(modelItem => item.Year)
</td>
<td>
@Html.DisplayFor(modelItem => item.CountPassengerSeats)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.PriceForDay)
</td>
<td>
<a asp-controller="Rents" asp-action="Create">Select</a>
</td>
@if (this.User.IsInRole("Admin"))
{
<tr>
<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>
@Html.DisplayFor(modelItem => item.Id)
</td>
}
<td>
@Html.DisplayFor(modelItem => item.Brand)
</td>
<td>
@Html.DisplayFor(modelItem => item.Model)
</td>
<td>
@Html.DisplayFor(modelItem => item.Year)
</td>
<td>
@Html.DisplayFor(modelItem => item.CountPassengerSeats)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.PriceForDay)
</td>
<td>
<a asp-controller="Rents" asp-action="Create">Select</a>
</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>

View File

@@ -12,6 +12,11 @@
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<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 class="form-group">
<label asp-for="StartDate" class="control-label"></label>
<input asp-for="StartDate" class="form-control" />

View File

@@ -13,6 +13,9 @@
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.CarId)
</th>
<th>
@Html.DisplayNameFor(model => model.StartDate)
</th>
@@ -25,6 +28,9 @@
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.CarId)
</td>
<td>
@Html.DisplayFor(modelItem => item.StartDate)
</td>
@@ -39,7 +45,7 @@
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
}
</tr>
</tr>
}
</tbody>
</table>

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

View File

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

View File

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