From 547c6e8774038833583ccae8602632c74db482a7 Mon Sep 17 00:00:00 2001 From: "ani_konarcheva@abv.bg" Date: Fri, 8 Apr 2022 14:05:16 +0300 Subject: [PATCH] commiting some changes --- RentACar/Data/Data/RentACarDbContext.cs | 2 +- RentACar/Data/Models/Car.cs | 1 + .../WebApp/Controllers/RentsController.cs | 6 +- RentACar/WebApp/Startup.cs | 3 +- RentACar/WebApp/Views/Cars/Index.cshtml | 62 ++++++++++--------- RentACar/WebApp/Views/Rents/Create.cshtml | 5 ++ RentACar/WebApp/Views/Rents/Index.cshtml | 8 ++- RentACar/WebApp/WebApp.csproj | 2 +- RentACar/WebApp/appsettings.json | 2 +- .../WebApp/bin/Debug/net5.0/appsettings.json | 2 +- 10 files changed, 56 insertions(+), 37 deletions(-) diff --git a/RentACar/Data/Data/RentACarDbContext.cs b/RentACar/Data/Data/RentACarDbContext.cs index 80fe50b..5e28229 100644 --- a/RentACar/Data/Data/RentACarDbContext.cs +++ b/RentACar/Data/Data/RentACarDbContext.cs @@ -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;"); } } diff --git a/RentACar/Data/Models/Car.cs b/RentACar/Data/Models/Car.cs index 8416f84..ae49492 100644 --- a/RentACar/Data/Models/Car.cs +++ b/RentACar/Data/Models/Car.cs @@ -10,6 +10,7 @@ namespace Data.Entities public class Car { [Required] + [Key] public int Id { get; set; } [Required] diff --git a/RentACar/WebApp/Controllers/RentsController.cs b/RentACar/WebApp/Controllers/RentsController.cs index 0238e68..5658037 100644 --- a/RentACar/WebApp/Controllers/RentsController.cs +++ b/RentACar/WebApp/Controllers/RentsController.cs @@ -54,11 +54,11 @@ namespace WebApp.Controllers // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] - public async Task Create([Bind("Id,StartDate,EndDate")] Rents rents) + public async Task 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 Edit(int id, [Bind("Id,StartDate,EndDate")] Rents rents) + public async Task Edit(int id, [Bind("Id,CarId,StartDate,EndDate,UserId")] Rents rents) { if (id != rents.Id) { diff --git a/RentACar/WebApp/Startup.cs b/RentACar/WebApp/Startup.cs index 083f3b5..b975999 100644 --- a/RentACar/WebApp/Startup.cs +++ b/RentACar/WebApp/Startup.cs @@ -39,7 +39,7 @@ namespace API options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = true; - options.User.RequireUniqueEmail = false; + options.User.RequireUniqueEmail = true; }) .AddRoles() .AddDefaultUI() @@ -78,6 +78,7 @@ namespace API pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); + } } } diff --git a/RentACar/WebApp/Views/Cars/Index.cshtml b/RentACar/WebApp/Views/Cars/Index.cshtml index 8e4115b..0013ac8 100644 --- a/RentACar/WebApp/Views/Cars/Index.cshtml +++ b/RentACar/WebApp/Views/Cars/Index.cshtml @@ -14,6 +14,9 @@ + @@ -40,36 +43,39 @@ @foreach (var item in Model) { - - - - - - - - - @if (this.User.IsInRole("Admin")) - { + - } + + + + + + + + @if (this.User.IsInRole("Admin")) + { + + } } diff --git a/RentACar/WebApp/Views/Rents/Create.cshtml b/RentACar/WebApp/Views/Rents/Create.cshtml index c6e8065..49e13ea 100644 --- a/RentACar/WebApp/Views/Rents/Create.cshtml +++ b/RentACar/WebApp/Views/Rents/Create.cshtml @@ -12,6 +12,11 @@
+
+ + + +
diff --git a/RentACar/WebApp/Views/Rents/Index.cshtml b/RentACar/WebApp/Views/Rents/Index.cshtml index c342a8a..ed1701b 100644 --- a/RentACar/WebApp/Views/Rents/Index.cshtml +++ b/RentACar/WebApp/Views/Rents/Index.cshtml @@ -13,6 +13,9 @@
+ @Html.DisplayNameFor(model => model.Id) + @Html.DisplayNameFor(model => model.Brand)
- @Html.DisplayFor(modelItem => item.Brand) - - @Html.DisplayFor(modelItem => item.Model) - - @Html.DisplayFor(modelItem => item.Year) - - @Html.DisplayFor(modelItem => item.CountPassengerSeats) - - @Html.DisplayFor(modelItem => item.Description) - - @Html.DisplayFor(modelItem => item.PriceForDay) - - Select -
- Edit | - Details | - Delete + @Html.DisplayFor(modelItem => item.Id) + @Html.DisplayFor(modelItem => item.Brand) + + @Html.DisplayFor(modelItem => item.Model) + + @Html.DisplayFor(modelItem => item.Year) + + @Html.DisplayFor(modelItem => item.CountPassengerSeats) + + @Html.DisplayFor(modelItem => item.Description) + + @Html.DisplayFor(modelItem => item.PriceForDay) + + Select + + Edit | + Details | + Delete +
+ @@ -25,6 +28,9 @@ @foreach (var item in Model) { + @@ -39,7 +45,7 @@ Delete } - + }
+ @Html.DisplayNameFor(model => model.CarId) + @Html.DisplayNameFor(model => model.StartDate)
+ @Html.DisplayFor(modelItem => item.CarId) + @Html.DisplayFor(modelItem => item.StartDate)
diff --git a/RentACar/WebApp/WebApp.csproj b/RentACar/WebApp/WebApp.csproj index 6c65f91..880cf2b 100644 --- a/RentACar/WebApp/WebApp.csproj +++ b/RentACar/WebApp/WebApp.csproj @@ -1,4 +1,4 @@ - + net5.0 diff --git a/RentACar/WebApp/appsettings.json b/RentACar/WebApp/appsettings.json index 5bd170a..e899df0 100644 --- a/RentACar/WebApp/appsettings.json +++ b/RentACar/WebApp/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;" + "DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;" }, "Logging": { "LogLevel": { diff --git a/RentACar/WebApp/bin/Debug/net5.0/appsettings.json b/RentACar/WebApp/bin/Debug/net5.0/appsettings.json index 5bd170a..e899df0 100644 --- a/RentACar/WebApp/bin/Debug/net5.0/appsettings.json +++ b/RentACar/WebApp/bin/Debug/net5.0/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;" + "DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;" }, "Logging": { "LogLevel": {