commiting something

This commit is contained in:
ani_konarcheva@abv.bg
2022-04-09 00:11:38 +03:00
parent 8935dbdc99
commit 91e835f63d
6 changed files with 46 additions and 40 deletions

View File

@@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Data.Migrations namespace Data.Migrations
{ {
[DbContext(typeof(RentACarDbContext))] [DbContext(typeof(RentACarDbContext))]
[Migration("20220408165704_initial")] [Migration("20220408204254_initial")]
partial class initial partial class initial
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -70,6 +70,7 @@ 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");
@@ -157,15 +158,15 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "6672fb82-eac5-434e-bfb3-b006250c3c70", Id = "90eb7ea0-1453-414e-bd62-1598743235f9",
AccessFailedCount = 0, AccessFailedCount = 0,
ConcurrencyStamp = "73ea1656-0fe7-4798-8c49-2bf075752f0d", ConcurrencyStamp = "2d3a925b-5e08-49ee-ad6d-0478d5f3835d",
Email = "admin@admin.admin", Email = "admin@admin.admin",
EmailConfirmed = false, EmailConfirmed = false,
LockoutEnabled = false, LockoutEnabled = false,
PasswordHash = "AQAAAAEAACcQAAAAEF1qZnzmOwaxX7gg8131im6Fsf15IdhzXMNGdGdZ2/A44dccfIebf3/ogztSjIxDYw==", PasswordHash = "AQAAAAEAACcQAAAAED+NUmnyTAFii5q3rHXmsdJw3qQB6PZGujYBjKMXKm8Vgh/9YINv1bWutfkY010xvQ==",
PhoneNumberConfirmed = false, PhoneNumberConfirmed = false,
SecurityStamp = "7c3cfc39-00b4-45e4-a0ab-4fed3c22bf61", SecurityStamp = "36eacd85-50f6-4f93-928e-d5b7b53d4dfa",
TwoFactorEnabled = false, TwoFactorEnabled = false,
UserName = "admin" UserName = "admin"
}); });
@@ -200,14 +201,14 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "616b0c38-7885-4bbb-ba58-eb9ffd670331", Id = "ea075722-31b3-4f87-9306-05a2b3955385",
ConcurrencyStamp = "fc82a4fb-c5d8-4c95-963f-8332e6896085", ConcurrencyStamp = "75739597-d83b-4934-8676-ac31019c2a65",
Name = "Admin" Name = "Admin"
}, },
new new
{ {
Id = "2ebdf39c-05b9-41f5-a505-4dab3788136f", Id = "fed57231-c916-4cd0-9eed-7a2dee121d2d",
ConcurrencyStamp = "5638a11d-92a1-46bd-9d05-d43cae4eee4e", ConcurrencyStamp = "96013243-e917-4ffc-a6a7-b1e3a7eb5f7e",
Name = "Employee" Name = "Employee"
}); });
}); });
@@ -299,13 +300,13 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
UserId = "6672fb82-eac5-434e-bfb3-b006250c3c70", UserId = "90eb7ea0-1453-414e-bd62-1598743235f9",
RoleId = "616b0c38-7885-4bbb-ba58-eb9ffd670331" RoleId = "ea075722-31b3-4f87-9306-05a2b3955385"
}, },
new new
{ {
UserId = "6672fb82-eac5-434e-bfb3-b006250c3c70", UserId = "90eb7ea0-1453-414e-bd62-1598743235f9",
RoleId = "2ebdf39c-05b9-41f5-a505-4dab3788136f" RoleId = "fed57231-c916-4cd0-9eed-7a2dee121d2d"
}); });
}); });
@@ -338,7 +339,9 @@ 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

@@ -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: true) UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
}, },
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.Restrict); onDelete: ReferentialAction.Cascade);
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[] { "616b0c38-7885-4bbb-ba58-eb9ffd670331", "fc82a4fb-c5d8-4c95-963f-8332e6896085", "Admin", null }); values: new object[] { "ea075722-31b3-4f87-9306-05a2b3955385", "75739597-d83b-4934-8676-ac31019c2a65", "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[] { "2ebdf39c-05b9-41f5-a505-4dab3788136f", "5638a11d-92a1-46bd-9d05-d43cae4eee4e", "Employee", null }); values: new object[] { "fed57231-c916-4cd0-9eed-7a2dee121d2d", "96013243-e917-4ffc-a6a7-b1e3a7eb5f7e", "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[] { "6672fb82-eac5-434e-bfb3-b006250c3c70", 0, "73ea1656-0fe7-4798-8c49-2bf075752f0d", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAEF1qZnzmOwaxX7gg8131im6Fsf15IdhzXMNGdGdZ2/A44dccfIebf3/ogztSjIxDYw==", null, null, false, "7c3cfc39-00b4-45e4-a0ab-4fed3c22bf61", false, "admin" }); values: new object[] { "90eb7ea0-1453-414e-bd62-1598743235f9", 0, "2d3a925b-5e08-49ee-ad6d-0478d5f3835d", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAED+NUmnyTAFii5q3rHXmsdJw3qQB6PZGujYBjKMXKm8Vgh/9YINv1bWutfkY010xvQ==", null, null, false, "36eacd85-50f6-4f93-928e-d5b7b53d4dfa", false, "admin" });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "AspNetUserRoles", table: "AspNetUserRoles",
columns: new[] { "RoleId", "UserId" }, columns: new[] { "RoleId", "UserId" },
values: new object[] { "616b0c38-7885-4bbb-ba58-eb9ffd670331", "6672fb82-eac5-434e-bfb3-b006250c3c70" }); values: new object[] { "ea075722-31b3-4f87-9306-05a2b3955385", "90eb7ea0-1453-414e-bd62-1598743235f9" });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "AspNetUserRoles", table: "AspNetUserRoles",
columns: new[] { "RoleId", "UserId" }, columns: new[] { "RoleId", "UserId" },
values: new object[] { "2ebdf39c-05b9-41f5-a505-4dab3788136f", "6672fb82-eac5-434e-bfb3-b006250c3c70" }); values: new object[] { "fed57231-c916-4cd0-9eed-7a2dee121d2d", "90eb7ea0-1453-414e-bd62-1598743235f9" });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId", name: "IX_AspNetRoleClaims_RoleId",

View File

@@ -68,6 +68,7 @@ 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");
@@ -155,15 +156,15 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "6672fb82-eac5-434e-bfb3-b006250c3c70", Id = "90eb7ea0-1453-414e-bd62-1598743235f9",
AccessFailedCount = 0, AccessFailedCount = 0,
ConcurrencyStamp = "73ea1656-0fe7-4798-8c49-2bf075752f0d", ConcurrencyStamp = "2d3a925b-5e08-49ee-ad6d-0478d5f3835d",
Email = "admin@admin.admin", Email = "admin@admin.admin",
EmailConfirmed = false, EmailConfirmed = false,
LockoutEnabled = false, LockoutEnabled = false,
PasswordHash = "AQAAAAEAACcQAAAAEF1qZnzmOwaxX7gg8131im6Fsf15IdhzXMNGdGdZ2/A44dccfIebf3/ogztSjIxDYw==", PasswordHash = "AQAAAAEAACcQAAAAED+NUmnyTAFii5q3rHXmsdJw3qQB6PZGujYBjKMXKm8Vgh/9YINv1bWutfkY010xvQ==",
PhoneNumberConfirmed = false, PhoneNumberConfirmed = false,
SecurityStamp = "7c3cfc39-00b4-45e4-a0ab-4fed3c22bf61", SecurityStamp = "36eacd85-50f6-4f93-928e-d5b7b53d4dfa",
TwoFactorEnabled = false, TwoFactorEnabled = false,
UserName = "admin" UserName = "admin"
}); });
@@ -198,14 +199,14 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
Id = "616b0c38-7885-4bbb-ba58-eb9ffd670331", Id = "ea075722-31b3-4f87-9306-05a2b3955385",
ConcurrencyStamp = "fc82a4fb-c5d8-4c95-963f-8332e6896085", ConcurrencyStamp = "75739597-d83b-4934-8676-ac31019c2a65",
Name = "Admin" Name = "Admin"
}, },
new new
{ {
Id = "2ebdf39c-05b9-41f5-a505-4dab3788136f", Id = "fed57231-c916-4cd0-9eed-7a2dee121d2d",
ConcurrencyStamp = "5638a11d-92a1-46bd-9d05-d43cae4eee4e", ConcurrencyStamp = "96013243-e917-4ffc-a6a7-b1e3a7eb5f7e",
Name = "Employee" Name = "Employee"
}); });
}); });
@@ -297,13 +298,13 @@ namespace Data.Migrations
b.HasData( b.HasData(
new new
{ {
UserId = "6672fb82-eac5-434e-bfb3-b006250c3c70", UserId = "90eb7ea0-1453-414e-bd62-1598743235f9",
RoleId = "616b0c38-7885-4bbb-ba58-eb9ffd670331" RoleId = "ea075722-31b3-4f87-9306-05a2b3955385"
}, },
new new
{ {
UserId = "6672fb82-eac5-434e-bfb3-b006250c3c70", UserId = "90eb7ea0-1453-414e-bd62-1598743235f9",
RoleId = "2ebdf39c-05b9-41f5-a505-4dab3788136f" RoleId = "fed57231-c916-4cd0-9eed-7a2dee121d2d"
}); });
}); });
@@ -336,7 +337,9 @@ 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

@@ -22,7 +22,9 @@ namespace Data.Entities
[Required] [Required]
public DateTime EndDate { get; set; } public DateTime EndDate { get; set; }
[Required]
[ForeignKey("UserId")] [ForeignKey("UserId")]
public User User { get; set; } public User User { get; set; }
} }
} }

View File

@@ -59,14 +59,12 @@ namespace WebApp.Controllers
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
[Authorize] [Authorize]
public async Task<IActionResult> Create([Bind("Id,Car.Id,StartDate,EndDate,User.Id")] Rents rents) public async Task<IActionResult> Create([Bind("CarId,StartDate,EndDate")] Rents rents)
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
var car = _context.Cars.FirstOrDefault(car => car.Id == rents.Car.Id); var car = _context.Cars.FirstOrDefault(car => car.Id == 1);
rents.Car = car; rents.Car = car;
var user = _context.Users.FirstOrDefault(user => user.Id == rents.User.Id);
rents.User = user;
_context.Add(rents); _context.Add(rents);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index)); return RedirectToAction(nameof(Index));
@@ -97,7 +95,7 @@ namespace WebApp.Controllers
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
[Authorize(Roles = "Admin")] [Authorize(Roles = "Admin")]
public async Task<IActionResult> Edit(int id, [Bind("Id,CarId,StartDate,EndDate,UserId")] Rents rents) public async Task<IActionResult> Edit(int id, [Bind("CarId,StartDate,EndDate")] Rents rents)
{ {
if (id != rents.Id) if (id != rents.Id)
{ {

View File

@@ -171,7 +171,7 @@ namespace WebApp.Controllers
} }
// GET: Users/Details/5 // GET: Users/Details/5
[Authorize(Roles = "Admin")] [Authorize(Roles = "Admin")]
public async Task<IActionResult> Details(string? id) public async Task<IActionResult> Details(string id)
{ {
if (id == null) if (id == null)
{ {