Lazy Loading fix, new migration, Rents Index data

This commit is contained in:
Dimitar Byalkov
2022-04-09 03:21:47 +03:00
parent 21117225b7
commit 9c857a9458
14 changed files with 143 additions and 92 deletions

View File

@@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.12" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.12" /> <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.12" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.12" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.12"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.12">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

View File

@@ -20,7 +20,7 @@ namespace Data
{ {
if (!optionsBuilder.IsConfigured) if (!optionsBuilder.IsConfigured)
{ {
optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;"); optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;").UseLazyLoadingProxies();
} }
} }
@@ -63,7 +63,6 @@ namespace Data
modelBuilder.Entity<Car>().HasKey(car => car.Id); modelBuilder.Entity<Car>().HasKey(car => car.Id);
modelBuilder.Entity<Rents>().HasOne(rents => rents.User); modelBuilder.Entity<Rents>().HasOne(rents => rents.User);
modelBuilder.Entity<Rents>().HasOne(rents => rents.Car); modelBuilder.Entity<Rents>().HasOne(rents => rents.Car);
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
} }

View File

@@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Data.Migrations namespace Data.Migrations
{ {
[DbContext(typeof(RentACarDbContext))] [DbContext(typeof(RentACarDbContext))]
[Migration("20220408211811_initial")] [Migration("20220408234818_Initial")]
partial class initial partial class Initial
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
@@ -68,7 +68,6 @@ namespace Data.Migrations
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<string>("UserId") b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(450)"); .HasColumnType("nvarchar(450)");
b.HasKey("Id"); b.HasKey("Id");
@@ -156,15 +155,15 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "28c75ddc-f972-4532-be46-adae03df32fb", Id = "691a45ed-4399-47a1-a8c2-2a2abac9ba74",
AccessFailedCount = 0, AccessFailedCount = 0,
ConcurrencyStamp = "33c93ad2-8f61-4e3c-8d61-1583ea02a347", ConcurrencyStamp = "c91c153e-ba2e-4da9-a397-5ac6f098d369",
Email = "admin@admin.admin", Email = "admin@admin.admin",
EmailConfirmed = false, EmailConfirmed = false,
LockoutEnabled = false, LockoutEnabled = false,
PasswordHash = "AQAAAAEAACcQAAAAEMzxMVddhY+nvlkkmN6QRcuyj3Vh4iVvZ9xMarXBCh1APRAhWUU90mP4SOf0qS3A8Q==", PasswordHash = "AQAAAAEAACcQAAAAEBajAJZYLZCUESCrgsH15V9n0OFqo9MLHWVzA3zHo7aqKbmSoUCv1TAu9j3r+PC/mw==",
PhoneNumberConfirmed = false, PhoneNumberConfirmed = false,
SecurityStamp = "f548cc6f-ef08-4714-9c7a-e4e660cdced3", SecurityStamp = "b105af8c-ee72-4969-9ba5-98bd13897459",
TwoFactorEnabled = false, TwoFactorEnabled = false,
UserName = "admin" UserName = "admin"
}); });
@@ -199,14 +198,14 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "14ca6e11-5721-43c8-a170-b74dbd8dd7f8", Id = "8af8225c-ac26-406b-9d29-c172f95240c0",
ConcurrencyStamp = "18c88b14-89fd-4563-927c-23ed1da3d868", ConcurrencyStamp = "446df763-47b2-4b18-b196-86f63f2a6a8b",
Name = "Admin" Name = "Admin"
}, },
new new
{ {
Id = "b79e8165-7e4a-409f-8d27-455dd03ca398", Id = "b006be23-eb9f-480d-b127-0f76a4b01d38",
ConcurrencyStamp = "32443d24-2ba0-4d21-90f4-40971854864c", ConcurrencyStamp = "13ae3b09-1b07-46d7-870e-ff9a78ac556d",
Name = "Employee" Name = "Employee"
}); });
}); });
@@ -298,13 +297,13 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
UserId = "28c75ddc-f972-4532-be46-adae03df32fb", UserId = "691a45ed-4399-47a1-a8c2-2a2abac9ba74",
RoleId = "14ca6e11-5721-43c8-a170-b74dbd8dd7f8" RoleId = "8af8225c-ac26-406b-9d29-c172f95240c0"
}, },
new new
{ {
UserId = "28c75ddc-f972-4532-be46-adae03df32fb", UserId = "691a45ed-4399-47a1-a8c2-2a2abac9ba74",
RoleId = "b79e8165-7e4a-409f-8d27-455dd03ca398" RoleId = "b006be23-eb9f-480d-b127-0f76a4b01d38"
}); });
}); });
@@ -337,9 +336,7 @@ namespace Data.Migrations
b.HasOne("Data.Entities.User", "User") b.HasOne("Data.Entities.User", "User")
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId");
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Car"); b.Navigation("Car");

View File

@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations namespace Data.Migrations
{ {
public partial class initial : Migration public partial class Initial : Migration
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
@@ -182,7 +182,7 @@ namespace Data.Migrations
CarId = table.Column<int>(type: "int", nullable: false), CarId = table.Column<int>(type: "int", nullable: false),
StartDate = table.Column<DateTime>(type: "datetime2", nullable: false), StartDate = table.Column<DateTime>(type: "datetime2", nullable: false),
EndDate = table.Column<DateTime>(type: "datetime2", nullable: false), EndDate = table.Column<DateTime>(type: "datetime2", nullable: false),
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false) UserId = table.Column<string>(type: "nvarchar(450)", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
@@ -192,7 +192,7 @@ namespace Data.Migrations
column: x => x.UserId, column: x => x.UserId,
principalTable: "AspNetUsers", principalTable: "AspNetUsers",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Restrict);
table.ForeignKey( table.ForeignKey(
name: "FK_Rents_Cars_CarId", name: "FK_Rents_Cars_CarId",
column: x => x.CarId, column: x => x.CarId,
@@ -204,27 +204,27 @@ namespace Data.Migrations
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "AspNetRoles", table: "AspNetRoles",
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
values: new object[] { "14ca6e11-5721-43c8-a170-b74dbd8dd7f8", "18c88b14-89fd-4563-927c-23ed1da3d868", "Admin", null }); values: new object[] { "8af8225c-ac26-406b-9d29-c172f95240c0", "446df763-47b2-4b18-b196-86f63f2a6a8b", "Admin", null });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "AspNetRoles", table: "AspNetRoles",
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
values: new object[] { "b79e8165-7e4a-409f-8d27-455dd03ca398", "32443d24-2ba0-4d21-90f4-40971854864c", "Employee", null }); values: new object[] { "b006be23-eb9f-480d-b127-0f76a4b01d38", "13ae3b09-1b07-46d7-870e-ff9a78ac556d", "Employee", null });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "AspNetUsers", table: "AspNetUsers",
columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" }, columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" },
values: new object[] { "28c75ddc-f972-4532-be46-adae03df32fb", 0, "33c93ad2-8f61-4e3c-8d61-1583ea02a347", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAEMzxMVddhY+nvlkkmN6QRcuyj3Vh4iVvZ9xMarXBCh1APRAhWUU90mP4SOf0qS3A8Q==", null, null, false, "f548cc6f-ef08-4714-9c7a-e4e660cdced3", false, "admin" }); values: new object[] { "691a45ed-4399-47a1-a8c2-2a2abac9ba74", 0, "c91c153e-ba2e-4da9-a397-5ac6f098d369", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAEBajAJZYLZCUESCrgsH15V9n0OFqo9MLHWVzA3zHo7aqKbmSoUCv1TAu9j3r+PC/mw==", null, null, false, "b105af8c-ee72-4969-9ba5-98bd13897459", false, "admin" });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "AspNetUserRoles", table: "AspNetUserRoles",
columns: new[] { "RoleId", "UserId" }, columns: new[] { "RoleId", "UserId" },
values: new object[] { "14ca6e11-5721-43c8-a170-b74dbd8dd7f8", "28c75ddc-f972-4532-be46-adae03df32fb" }); values: new object[] { "8af8225c-ac26-406b-9d29-c172f95240c0", "691a45ed-4399-47a1-a8c2-2a2abac9ba74" });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "AspNetUserRoles", table: "AspNetUserRoles",
columns: new[] { "RoleId", "UserId" }, columns: new[] { "RoleId", "UserId" },
values: new object[] { "b79e8165-7e4a-409f-8d27-455dd03ca398", "28c75ddc-f972-4532-be46-adae03df32fb" }); values: new object[] { "b006be23-eb9f-480d-b127-0f76a4b01d38", "691a45ed-4399-47a1-a8c2-2a2abac9ba74" });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId", name: "IX_AspNetRoleClaims_RoleId",

View File

@@ -66,7 +66,6 @@ namespace Data.Migrations
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<string>("UserId") b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(450)"); .HasColumnType("nvarchar(450)");
b.HasKey("Id"); b.HasKey("Id");
@@ -154,15 +153,15 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "28c75ddc-f972-4532-be46-adae03df32fb", Id = "691a45ed-4399-47a1-a8c2-2a2abac9ba74",
AccessFailedCount = 0, AccessFailedCount = 0,
ConcurrencyStamp = "33c93ad2-8f61-4e3c-8d61-1583ea02a347", ConcurrencyStamp = "c91c153e-ba2e-4da9-a397-5ac6f098d369",
Email = "admin@admin.admin", Email = "admin@admin.admin",
EmailConfirmed = false, EmailConfirmed = false,
LockoutEnabled = false, LockoutEnabled = false,
PasswordHash = "AQAAAAEAACcQAAAAEMzxMVddhY+nvlkkmN6QRcuyj3Vh4iVvZ9xMarXBCh1APRAhWUU90mP4SOf0qS3A8Q==", PasswordHash = "AQAAAAEAACcQAAAAEBajAJZYLZCUESCrgsH15V9n0OFqo9MLHWVzA3zHo7aqKbmSoUCv1TAu9j3r+PC/mw==",
PhoneNumberConfirmed = false, PhoneNumberConfirmed = false,
SecurityStamp = "f548cc6f-ef08-4714-9c7a-e4e660cdced3", SecurityStamp = "b105af8c-ee72-4969-9ba5-98bd13897459",
TwoFactorEnabled = false, TwoFactorEnabled = false,
UserName = "admin" UserName = "admin"
}); });
@@ -197,14 +196,14 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "14ca6e11-5721-43c8-a170-b74dbd8dd7f8", Id = "8af8225c-ac26-406b-9d29-c172f95240c0",
ConcurrencyStamp = "18c88b14-89fd-4563-927c-23ed1da3d868", ConcurrencyStamp = "446df763-47b2-4b18-b196-86f63f2a6a8b",
Name = "Admin" Name = "Admin"
}, },
new new
{ {
Id = "b79e8165-7e4a-409f-8d27-455dd03ca398", Id = "b006be23-eb9f-480d-b127-0f76a4b01d38",
ConcurrencyStamp = "32443d24-2ba0-4d21-90f4-40971854864c", ConcurrencyStamp = "13ae3b09-1b07-46d7-870e-ff9a78ac556d",
Name = "Employee" Name = "Employee"
}); });
}); });
@@ -296,13 +295,13 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
UserId = "28c75ddc-f972-4532-be46-adae03df32fb", UserId = "691a45ed-4399-47a1-a8c2-2a2abac9ba74",
RoleId = "14ca6e11-5721-43c8-a170-b74dbd8dd7f8" RoleId = "8af8225c-ac26-406b-9d29-c172f95240c0"
}, },
new new
{ {
UserId = "28c75ddc-f972-4532-be46-adae03df32fb", UserId = "691a45ed-4399-47a1-a8c2-2a2abac9ba74",
RoleId = "b79e8165-7e4a-409f-8d27-455dd03ca398" RoleId = "b006be23-eb9f-480d-b127-0f76a4b01d38"
}); });
}); });
@@ -335,9 +334,7 @@ namespace Data.Migrations
b.HasOne("Data.Entities.User", "User") b.HasOne("Data.Entities.User", "User")
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId");
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Car"); b.Navigation("Car");

View File

@@ -11,13 +11,15 @@ namespace Data.Entities
{ {
[Required] [Required]
[Key] [Key]
[Display(Name = "Car ID")]
public int Id { get; set; } public int Id { get; set; }
public string Brand { get; set; } public string Brand { get; set; }
public string Model { get; set; } public string Model { get; set; }
public int Year { get; set; } public int Year { get; set; }
[Display(Name = "Seats")]
public int CountPassengerSeats { get; set; } public int CountPassengerSeats { get; set; }
public string Description { get; set; } public string Description { get; set; }
[Display(Name = "Daily price")]
public decimal PriceForDay { get; set; } public decimal PriceForDay { get; set; }
} }
} }

View File

@@ -12,19 +12,19 @@ namespace Data.Entities
public class Rents public class Rents
{ {
public int Id { get; set; } public int Id { get; set; }
[Required]
[ForeignKey("CarId")] [ForeignKey("CarId")]
public Car Car { get; set; } public int CarId { get; set; }
public virtual Car Car { get; set; }
[Required] [Required]
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; } public DateTime StartDate { get; set; }
[Required] [Required]
[Display(Name = "End Date")]
public DateTime EndDate { get; set; } public DateTime EndDate { get; set; }
[Required]
[ForeignKey("UserId")] [ForeignKey("UserId")]
public User User { get; set; } public string UserId { get; set; }
public virtual User User { get; set; }
} }
} }

View File

@@ -11,10 +11,11 @@ namespace Data.Entities
{ {
public class User : IdentityUser<string> public class User : IdentityUser<string>
{ {
[Display(Name = "First Name")]
public string FirstName { get; set; } public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; } public string LastName { get; set; }
[Display(Name = "ID Number")]
public string PersonalNumber { get; set; } public string PersonalNumber { get; set; }
} }

View File

@@ -61,6 +61,7 @@ namespace WebApp.Controllers
[Authorize] [Authorize]
public async Task<IActionResult> Create(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);

View File

@@ -29,7 +29,7 @@ namespace API
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddDbContext<RentACarDbContext>(options => services.AddDbContext<RentACarDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); options.UseLazyLoadingProxies().UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDatabaseDeveloperPageExceptionFilter(); services.AddDatabaseDeveloperPageExceptionFilter();
services.AddIdentity<User, IdentityRole>(options => services.AddIdentity<User, IdentityRole>(options =>
{ {
@@ -45,7 +45,6 @@ namespace API
.AddDefaultUI() .AddDefaultUI()
.AddDefaultTokenProviders() .AddDefaultTokenProviders()
.AddEntityFrameworkStores<RentACarDbContext>(); .AddEntityFrameworkStores<RentACarDbContext>();
services.AddControllersWithViews(); services.AddControllersWithViews();
services.AddRazorPages(); services.AddRazorPages();
} }

View File

@@ -15,7 +15,7 @@
<thead> <thead>
<tr> <tr>
<th> <th>
ID @Html.DisplayNameFor(model => model.Id)
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Brand) @Html.DisplayNameFor(model => model.Brand)
@@ -27,13 +27,13 @@
@Html.DisplayNameFor(model => model.Year) @Html.DisplayNameFor(model => model.Year)
</th> </th>
<th> <th>
Seats @Html.DisplayNameFor(model => model.CountPassengerSeats)
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Description) @Html.DisplayNameFor(model => model.Description)
</th> </th>
<th> <th>
Daily price @Html.DisplayNameFor(model => model.PriceForDay)
</th> </th>
@if (this.User.IsInRole("Admin")) @if (this.User.IsInRole("Admin"))
{ {

View File

@@ -9,18 +9,72 @@
<div> <div>
<hr /> <hr />
<dl class="row"> <dl class="row">
<dt class = "col-sm-2"> <dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Car.Id)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Car.Id)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Car.Brand)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Car.Brand)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Car.Model)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Car.Model)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Car.CountPassengerSeats)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Car.CountPassengerSeats)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Car.PriceForDay)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Car.PriceForDay)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.StartDate) @Html.DisplayNameFor(model => model.StartDate)
</dt> </dt>
<dd class = "col-sm-10"> <dd class="col-sm-10">
@Html.DisplayFor(model => model.StartDate) @Html.DisplayFor(model => model.StartDate)
</dd> </dd>
<dt class = "col-sm-2"> <dt class="col-sm-2">
@Html.DisplayNameFor(model => model.EndDate) @Html.DisplayNameFor(model => model.EndDate)
</dt> </dt>
<dd class = "col-sm-10"> <dd class="col-sm-10">
@Html.DisplayFor(model => model.EndDate) @Html.DisplayFor(model => model.EndDate)
</dd> </dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.FirstName)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.FirstName)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.LastName)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.LastName)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.UserName)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.UserName)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.Email)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.Email)
</dd>
</dl> </dl>
</div> </div>
<div> <div>

View File

@@ -15,16 +15,16 @@
<thead> <thead>
<tr> <tr>
<th> <th>
Car ID @Html.DisplayNameFor(model => model.Car.Id)
</th> </th>
<th> <th>
Start Date @Html.DisplayNameFor(model => model.StartDate)
</th> </th>
<th> <th>
End Date @Html.DisplayNameFor(model => model.EndDate)
</th> </th>
<th> <th>
User @Html.DisplayNameFor(model => model.User.UserName)
</th> </th>
@if (this.User.IsInRole("Admin")) @if (this.User.IsInRole("Admin"))
{ {
@@ -37,28 +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>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> | @Html.DisplayFor(modelItem => item.Car.Id)
<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>
</tr> @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>
<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>

View File

@@ -13,22 +13,22 @@
<thead> <thead>
<tr> <tr>
<th> <th>
First name @Html.DisplayNameFor(model => model.FirstName)
</th> </th>
<th> <th>
Last name @Html.DisplayNameFor(model => model.LastName)
</th> </th>
<th> <th>
ID number @Html.DisplayNameFor(model => model.PersonalNumber)
</th> </th>
<th> <th>
Username @Html.DisplayNameFor(model => model.UserName)
</th> </th>
<th> <th>
E-mail @Html.DisplayNameFor(model => model.Email)
</th> </th>
<th> <th>
Phone number @Html.DisplayNameFor(model => model.PhoneNumber)
</th> </th>
<th> <th>
Actions Actions