diff --git a/RentACar/Data/Migrations/20220407201957_migrena.Designer.cs b/RentACar/Data/Migrations/20220407201957_migrena.Designer.cs deleted file mode 100644 index 1f08e92..0000000 --- a/RentACar/Data/Migrations/20220407201957_migrena.Designer.cs +++ /dev/null @@ -1,405 +0,0 @@ -// -using System; -using Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Data.Migrations -{ - [DbContext(typeof(RentACarDbContext))] - [Migration("20220407201957_migrena")] - partial class migrena - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.15") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Data.Entities.Car", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("Brand") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CountPassengerSeats") - .HasColumnType("int"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("Model") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PriceForDay") - .HasColumnType("decimal(18,2)"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Cars"); - }); - - modelBuilder.Entity("Data.Entities.Rents", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("CarId") - .HasColumnType("int"); - - b.Property("EndDate") - .HasColumnType("datetime2"); - - b.Property("StartDate") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("CarId"); - - b.HasIndex("UserId"); - - b.ToTable("Rents"); - }); - - modelBuilder.Entity("Data.Entities.User", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("FirstName") - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .HasColumnType("nvarchar(max)"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); - - b.Property("PersonalNumber") - .HasColumnType("nvarchar(450)"); - - b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); - - b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); - - b.Property("TwoFactorEnabled") - .HasColumnType("bit"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.HasIndex("PersonalNumber") - .IsUnique() - .HasFilter("[PersonalNumber] IS NOT NULL"); - - b.ToTable("AspNetUsers"); - - b.HasData( - new - { - Id = "387f2544-bfa8-44ed-9793-a5bd5eaafe57", - AccessFailedCount = 0, - ConcurrencyStamp = "6fa96ce1-7e47-4f44-bdeb-e13705729bdb", - Email = "admin@admin.admin", - EmailConfirmed = false, - LockoutEnabled = false, - PasswordHash = "AQAAAAEAACcQAAAAECdhgDXw9WdaYvos/Ef9zaSiSApNswFCna2iNk8tu8BsvXRVMQWvdPLE1L8sTdgjDQ==", - PhoneNumberConfirmed = false, - SecurityStamp = "db1ac172-eb3b-4b93-9f31-3f748a1eda84", - TwoFactorEnabled = false, - UserName = "admin" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles"); - - b.HasData( - new - { - Id = "fb054f77-3578-45ee-a3d6-e6fe706526b2", - ConcurrencyStamp = "4af0d06c-63be-448c-a1ee-7c369398dee5", - Name = "Admin" - }, - new - { - Id = "d3aa27bb-2866-4a7d-9f0d-30498859ae94", - ConcurrencyStamp = "64b281d1-f963-43ae-a25e-1f8f220b553d", - Name = "Employee" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("RoleId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles"); - - b.HasData( - new - { - UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57", - RoleId = "fb054f77-3578-45ee-a3d6-e6fe706526b2" - }, - new - { - UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57", - RoleId = "d3aa27bb-2866-4a7d-9f0d-30498859ae94" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .HasColumnType("nvarchar(450)"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("Data.Entities.Rents", b => - { - b.HasOne("Data.Entities.Car", "Car") - .WithMany() - .HasForeignKey("CarId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Data.Entities.User", "User") - .WithMany() - .HasForeignKey("UserId"); - - b.Navigation("Car"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/RentACar/Data/Migrations/20220407201957_migrena.cs b/RentACar/Data/Migrations/20220407201957_migrena.cs deleted file mode 100644 index 59e1597..0000000 --- a/RentACar/Data/Migrations/20220407201957_migrena.cs +++ /dev/null @@ -1,316 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Data.Migrations -{ - public partial class migrena : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - FirstName = table.Column(type: "nvarchar(max)", nullable: true), - LastName = table.Column(type: "nvarchar(max)", nullable: true), - PersonalNumber = table.Column(type: "nvarchar(450)", nullable: true), - UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "bit", nullable: false), - PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), - SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), - TwoFactorEnabled = table.Column(type: "bit", nullable: false), - LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), - LockoutEnabled = table.Column(type: "bit", nullable: false), - AccessFailedCount = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Cars", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Brand = table.Column(type: "nvarchar(max)", nullable: false), - Model = table.Column(type: "nvarchar(max)", nullable: false), - Year = table.Column(type: "int", nullable: false), - CountPassengerSeats = table.Column(type: "int", nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: true), - PriceForDay = table.Column(type: "decimal(18,2)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Cars", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - RoleId = table.Column(type: "nvarchar(450)", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "nvarchar(450)", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), - ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), - ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), - UserId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(type: "nvarchar(450)", nullable: false), - RoleId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - columns: table => new - { - UserId = table.Column(type: "nvarchar(450)", nullable: false), - LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(450)", nullable: false), - Value = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Rents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - CarId = table.Column(type: "int", nullable: false), - StartDate = table.Column(type: "datetime2", nullable: false), - EndDate = table.Column(type: "datetime2", nullable: false), - UserId = table.Column(type: "nvarchar(450)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Rents", x => x.Id); - table.ForeignKey( - name: "FK_Rents_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Rents_Cars_CarId", - column: x => x.CarId, - principalTable: "Cars", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[] { "fb054f77-3578-45ee-a3d6-e6fe706526b2", "4af0d06c-63be-448c-a1ee-7c369398dee5", "Admin", null }); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[] { "d3aa27bb-2866-4a7d-9f0d-30498859ae94", "64b281d1-f963-43ae-a25e-1f8f220b553d", "Employee", null }); - - migrationBuilder.InsertData( - table: "AspNetUsers", - columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" }, - values: new object[] { "387f2544-bfa8-44ed-9793-a5bd5eaafe57", 0, "6fa96ce1-7e47-4f44-bdeb-e13705729bdb", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAECdhgDXw9WdaYvos/Ef9zaSiSApNswFCna2iNk8tu8BsvXRVMQWvdPLE1L8sTdgjDQ==", null, null, false, "db1ac172-eb3b-4b93-9f31-3f748a1eda84", false, "admin" }); - - migrationBuilder.InsertData( - table: "AspNetUserRoles", - columns: new[] { "RoleId", "UserId" }, - values: new object[] { "fb054f77-3578-45ee-a3d6-e6fe706526b2", "387f2544-bfa8-44ed-9793-a5bd5eaafe57" }); - - migrationBuilder.InsertData( - table: "AspNetUserRoles", - columns: new[] { "RoleId", "UserId" }, - values: new object[] { "d3aa27bb-2866-4a7d-9f0d-30498859ae94", "387f2544-bfa8-44ed-9793-a5bd5eaafe57" }); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "AspNetRoles", - column: "NormalizedName", - unique: true, - filter: "[NormalizedName] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUsers_PersonalNumber", - table: "AspNetUsers", - column: "PersonalNumber", - unique: true, - filter: "[PersonalNumber] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true, - filter: "[NormalizedUserName] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_Rents_CarId", - table: "Rents", - column: "CarId"); - - migrationBuilder.CreateIndex( - name: "IX_Rents_UserId", - table: "Rents", - column: "UserId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AspNetRoleClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens"); - - migrationBuilder.DropTable( - name: "Rents"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - - migrationBuilder.DropTable( - name: "Cars"); - } - } -} diff --git a/RentACar/Data/Migrations/RentACarDbContextModelSnapshot.cs b/RentACar/Data/Migrations/RentACarDbContextModelSnapshot.cs deleted file mode 100644 index 3390eac..0000000 --- a/RentACar/Data/Migrations/RentACarDbContextModelSnapshot.cs +++ /dev/null @@ -1,403 +0,0 @@ -// -using System; -using Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Data.Migrations -{ - [DbContext(typeof(RentACarDbContext))] - partial class RentACarDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.15") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Data.Entities.Car", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("Brand") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CountPassengerSeats") - .HasColumnType("int"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("Model") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PriceForDay") - .HasColumnType("decimal(18,2)"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Cars"); - }); - - modelBuilder.Entity("Data.Entities.Rents", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("CarId") - .HasColumnType("int"); - - b.Property("EndDate") - .HasColumnType("datetime2"); - - b.Property("StartDate") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("CarId"); - - b.HasIndex("UserId"); - - b.ToTable("Rents"); - }); - - modelBuilder.Entity("Data.Entities.User", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("FirstName") - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .HasColumnType("nvarchar(max)"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); - - b.Property("PersonalNumber") - .HasColumnType("nvarchar(450)"); - - b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); - - b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); - - b.Property("TwoFactorEnabled") - .HasColumnType("bit"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.HasIndex("PersonalNumber") - .IsUnique() - .HasFilter("[PersonalNumber] IS NOT NULL"); - - b.ToTable("AspNetUsers"); - - b.HasData( - new - { - Id = "387f2544-bfa8-44ed-9793-a5bd5eaafe57", - AccessFailedCount = 0, - ConcurrencyStamp = "6fa96ce1-7e47-4f44-bdeb-e13705729bdb", - Email = "admin@admin.admin", - EmailConfirmed = false, - LockoutEnabled = false, - PasswordHash = "AQAAAAEAACcQAAAAECdhgDXw9WdaYvos/Ef9zaSiSApNswFCna2iNk8tu8BsvXRVMQWvdPLE1L8sTdgjDQ==", - PhoneNumberConfirmed = false, - SecurityStamp = "db1ac172-eb3b-4b93-9f31-3f748a1eda84", - TwoFactorEnabled = false, - UserName = "admin" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles"); - - b.HasData( - new - { - Id = "fb054f77-3578-45ee-a3d6-e6fe706526b2", - ConcurrencyStamp = "4af0d06c-63be-448c-a1ee-7c369398dee5", - Name = "Admin" - }, - new - { - Id = "d3aa27bb-2866-4a7d-9f0d-30498859ae94", - ConcurrencyStamp = "64b281d1-f963-43ae-a25e-1f8f220b553d", - Name = "Employee" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("RoleId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles"); - - b.HasData( - new - { - UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57", - RoleId = "fb054f77-3578-45ee-a3d6-e6fe706526b2" - }, - new - { - UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57", - RoleId = "d3aa27bb-2866-4a7d-9f0d-30498859ae94" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .HasColumnType("nvarchar(450)"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("Data.Entities.Rents", b => - { - b.HasOne("Data.Entities.Car", "Car") - .WithMany() - .HasForeignKey("CarId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Data.Entities.User", "User") - .WithMany() - .HasForeignKey("UserId"); - - b.Navigation("Car"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Data.Entities.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/RentACar/Data/Models/Rents.cs b/RentACar/Data/Models/Rents.cs index 807b722..4e614d5 100644 --- a/RentACar/Data/Models/Rents.cs +++ b/RentACar/Data/Models/Rents.cs @@ -14,7 +14,6 @@ namespace Data.Entities public int Id { get; set; } [Required] [ForeignKey("Car")] - public int CarId { get; set; } public virtual Car Car { get; set; } [Required] public DateTime StartDate { get; set; } diff --git a/RentACar/WebApp/Controllers/RentsController.cs b/RentACar/WebApp/Controllers/RentsController.cs index 6233890..636d668 100644 --- a/RentACar/WebApp/Controllers/RentsController.cs +++ b/RentACar/WebApp/Controllers/RentsController.cs @@ -42,6 +42,11 @@ namespace WebApp.Controllers return View(rents); } + public async Task DateSelect(DateTime startDate, DateTime endDate) + { + + return RedirectToAction(nameof(Index)); + } // GET: Rents/Create public IActionResult Create(int id) @@ -55,11 +60,11 @@ namespace WebApp.Controllers [HttpPost] [ValidateAntiForgeryToken] - public async Task Create([Bind("Id,CarId,StartDate,EndDate,UserId")] Rents rents) + public async Task Create([Bind("Id,Car.Id,StartDate,EndDate,UserId")] Rents rents) { if (ModelState.IsValid) { - var car = _context.Cars.FirstOrDefault(car => car.Id == rents.CarId); + var car = _context.Cars.FirstOrDefault(car => car.Id == rents.Car.Id); rents.Car = car; _context.Add(rents); await _context.SaveChangesAsync(); @@ -152,5 +157,18 @@ namespace WebApp.Controllers { return _context.Rents.Any(e => e.Id == id); } + public bool CarIsAvailable(int carId, DateTime startDate, DateTime endDate) + { + var rents = _context.Rents.Where(x => x.Car.Id == carId); + if (rents != null) + { + foreach (var item in rents) + { + return !(item.StartDate < endDate && startDate < item.EndDate); + } + return false; + } + else return true; + } } } diff --git a/RentACar/WebApp/Views/Cars/Index.cshtml b/RentACar/WebApp/Views/Cars/Index.cshtml index f3a918a..acbd785 100644 --- a/RentACar/WebApp/Views/Cars/Index.cshtml +++ b/RentACar/WebApp/Views/Cars/Index.cshtml @@ -4,19 +4,18 @@ ViewData["Title"] = "Cars"; } -

Vehicle

-

Available cars

+

Vehicles

@if (this.User.IsInRole("Admin")) { - Create car + Add new car }

@@ -66,9 +65,6 @@ - @if (this.User.IsInRole("Admin")) { +
- @Html.DisplayNameFor(model => model.Id) + ID @Html.DisplayNameFor(model => model.Brand) @@ -28,16 +27,16 @@ @Html.DisplayNameFor(model => model.Year) - @Html.DisplayNameFor(model => model.CountPassengerSeats) + Seats @Html.DisplayNameFor(model => model.Description) - @Html.DisplayNameFor(model => model.PriceForDay) + Daily price - Select + Actions
@Html.DisplayFor(modelItem => item.PriceForDay) - Select - diff --git a/RentACar/WebApp/Views/Home/Index.cshtml b/RentACar/WebApp/Views/Home/Index.cshtml index 61c3e83..2b4d8b1 100644 --- a/RentACar/WebApp/Views/Home/Index.cshtml +++ b/RentACar/WebApp/Views/Home/Index.cshtml @@ -3,5 +3,11 @@ }
-

Welcome

+

Welcome, @User.Identity.Name

+
+ Manage cars + @if (this.User.IsInRole("Admin")) + { + Manage rents + }
diff --git a/RentACar/WebApp/Views/Home/Privacy.cshtml b/RentACar/WebApp/Views/Home/Privacy.cshtml deleted file mode 100644 index af4fb19..0000000 --- a/RentACar/WebApp/Views/Home/Privacy.cshtml +++ /dev/null @@ -1,6 +0,0 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

- -

Use this page to detail your site's privacy policy.

diff --git a/RentACar/WebApp/Views/Rents/Create.cshtml b/RentACar/WebApp/Views/Rents/Create.cshtml index 49e13ea..0e221a3 100644 --- a/RentACar/WebApp/Views/Rents/Create.cshtml +++ b/RentACar/WebApp/Views/Rents/Create.cshtml @@ -4,19 +4,17 @@ ViewData["Title"] = "Create"; } -

Create

- -

Rents

+

Create rent


-
- - - + + +
+
@@ -38,6 +36,8 @@ Back to List
+ + @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} } diff --git a/RentACar/WebApp/Views/Rents/DateSelect.cshtml b/RentACar/WebApp/Views/Rents/DateSelect.cshtml new file mode 100644 index 0000000..f986344 --- /dev/null +++ b/RentACar/WebApp/Views/Rents/DateSelect.cshtml @@ -0,0 +1,34 @@ +@model Data.Entities.Rents + +@{ + ViewData["Title"] = "DateSelect"; +} + + +

Rent a car

+

Select dates

+ +
+
+ +
+
+ + + +
+
+ + + +
+
+ +
+ +
+
+ +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} \ No newline at end of file diff --git a/RentACar/WebApp/Views/Rents/Delete.cshtml b/RentACar/WebApp/Views/Rents/Delete.cshtml index aacf430..f4c1e6a 100644 --- a/RentACar/WebApp/Views/Rents/Delete.cshtml +++ b/RentACar/WebApp/Views/Rents/Delete.cshtml @@ -4,30 +4,53 @@ ViewData["Title"] = "Delete"; } -

Delete

+

Delete rent

Are you sure you want to delete this?

-

Rents


-
+
+ @Html.DisplayNameFor(model => model.Car.Id) +
+
+ @Html.DisplayFor(model => model.Car.Id) +
+
+ @Html.DisplayNameFor(model => model.Car.Brand) +
+
+ @Html.DisplayFor(model => model.Car.Brand) +
+
+ @Html.DisplayNameFor(model => model.Car.Model) +
+
+ @Html.DisplayFor(model => model.Car.Model) +
+
+ @Html.DisplayNameFor(model => model.Car.PriceForDay) +
+
+ @Html.DisplayFor(model => model.Car.PriceForDay) +
+
@Html.DisplayNameFor(model => model.StartDate)
-
+
@Html.DisplayFor(model => model.StartDate)
-
+
@Html.DisplayNameFor(model => model.EndDate)
-
+
@Html.DisplayFor(model => model.EndDate)
- | - Back to List + + Back to List
diff --git a/RentACar/WebApp/Views/Rents/Details.cshtml b/RentACar/WebApp/Views/Rents/Details.cshtml index e6b5f63..a819364 100644 --- a/RentACar/WebApp/Views/Rents/Details.cshtml +++ b/RentACar/WebApp/Views/Rents/Details.cshtml @@ -7,7 +7,6 @@

Details

-

Rents


@@ -25,6 +24,6 @@
diff --git a/RentACar/WebApp/Views/Rents/Edit.cshtml b/RentACar/WebApp/Views/Rents/Edit.cshtml index 63aea9d..0e32495 100644 --- a/RentACar/WebApp/Views/Rents/Edit.cshtml +++ b/RentACar/WebApp/Views/Rents/Edit.cshtml @@ -4,15 +4,18 @@ ViewData["Title"] = "Edit"; } -

Edit

- -

Rents

+

Edit rent


+
+ + + +
@@ -24,15 +27,13 @@
- + + Back to List
- @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} diff --git a/RentACar/WebApp/Views/Rents/Index.cshtml b/RentACar/WebApp/Views/Rents/Index.cshtml index d3ea5fb..afc1c5f 100644 --- a/RentACar/WebApp/Views/Rents/Index.cshtml +++ b/RentACar/WebApp/Views/Rents/Index.cshtml @@ -7,44 +7,53 @@

Rents

- Create New + Rent a car

- - - - - - - - - - -@foreach (var item in Model) { - - - - - @if (this.User.IsInRole("Admin")) +@if (this.User.IsInRole("Admin")) +{ +
- @Html.DisplayNameFor(model => model.CarId) - - @Html.DisplayNameFor(model => model.StartDate) - - @Html.DisplayNameFor(model => model.EndDate) -
- @Html.DisplayFor(modelItem => item.CarId) - - @Html.DisplayFor(modelItem => item.StartDate) - - @Html.DisplayFor(modelItem => item.EndDate) -
+ + + + + + @if (this.User.IsInRole("Admin")) + { + + } + + + + @foreach (var item in Model) { - + + + + + @if (this.User.IsInRole("Admin")) + { + + } + } - -} - -
+ Car ID + + Start Date + + End Date + + Actions +
- Edit | - Details | - Delete -
+ @Html.DisplayFor(modelItem => item.Car.Id) + + @Html.DisplayFor(modelItem => item.StartDate) + + @Html.DisplayFor(modelItem => item.EndDate) + + Edit | + Details | + Delete +
+
+} \ No newline at end of file diff --git a/RentACar/WebApp/Views/Shared/_Layout.cshtml b/RentACar/WebApp/Views/Shared/_Layout.cshtml index f8cb8f2..f97f7e6 100644 --- a/RentACar/WebApp/Views/Shared/_Layout.cshtml +++ b/RentACar/WebApp/Views/Shared/_Layout.cshtml @@ -27,12 +27,6 @@ - @if (this.User.IsInRole("Admin")) - { - - } diff --git a/RentACar/WebApp/Views/Shared/_LoginPartial.cshtml b/RentACar/WebApp/Views/Shared/_LoginPartial.cshtml index dc41016..b9d7d61 100644 --- a/RentACar/WebApp/Views/Shared/_LoginPartial.cshtml +++ b/RentACar/WebApp/Views/Shared/_LoginPartial.cshtml @@ -7,7 +7,7 @@ @if (SignInManager.IsSignedIn(User)) {