diff --git a/SQLQuery1.sql b/SQLQuery1.sql new file mode 100644 index 0000000..43919f1 --- /dev/null +++ b/SQLQuery1.sql @@ -0,0 +1,9 @@ +select * from dbo.AspNetUsers +select * from dbo.AspNetUserRoles +select * from dbo.AspNetRoles +select * from dbo.ShoppingCarts +select * from dbo.Companies +select * from dbo.Categories +select * from dbo.Products +select * from dbo.CoverType +select * from dbo.OrderHeaders diff --git a/XYZStore.DataAccess/Data/ApplicationDbContext.cs b/XYZStore.DataAccess/Data/ApplicationDbContext.cs index 221f232..b96d420 100644 --- a/XYZStore.DataAccess/Data/ApplicationDbContext.cs +++ b/XYZStore.DataAccess/Data/ApplicationDbContext.cs @@ -1,17 +1,24 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using XYZStore.DataAccess; using XYZStore.Models; using XYZStore.Models.Models; namespace XYZStore.DataAccess; -public class ApplicationDbContext : DbContext +public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext(DbContextOptionsoptions) : base(options) { } - public DbSetCategories { get; set; } - public DbSetCoverType { get; set; } - public DbSetProducts { get; set; } + public DbSet Categories { get; set; } + public DbSet CoverType { get; set; } + public DbSet Products { get; set; } + public DbSet ApplicationUsers { get; set; } + public DbSet Companies { get; set; } + public DbSet ShoppingCarts { get; set; } + public DbSet OrderHeaders { get; set; } + public DbSet OrderDetails { get; set; } + } diff --git a/XYZStore.DataAccess/DbInitializer/DbInitializer.cs b/XYZStore.DataAccess/DbInitializer/DbInitializer.cs new file mode 100644 index 0000000..200f205 --- /dev/null +++ b/XYZStore.DataAccess/DbInitializer/DbInitializer.cs @@ -0,0 +1,67 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using XYZStore.Models; +using XYZStore.Utility; + +namespace XYZStore.DataAccess.DbInitializer +{ + public class DbInitializer : IDbInitializer + { + private readonly UserManager _userManager; + private readonly RoleManager _roleManager; + private readonly ApplicationDbContext _db; + + public DbInitializer( + UserManager userManager, + RoleManager roleManager, + ApplicationDbContext db) + { + _roleManager = roleManager; + _userManager = userManager; + _db = db; + } + + public void Initialize() + { + //apply migrations if they are not applied + try + { + if(_db.Database.GetPendingMigrations().Count() > 0) + { + _db.Database.Migrate(); + } + } + catch(Exception ex) + { + + } + //create roles if they are not created + if (!_roleManager.RoleExistsAsync(SD.Role_Admin).GetAwaiter().GetResult()) + { + _roleManager.CreateAsync(new IdentityRole(SD.Role_Admin)).GetAwaiter().GetResult(); + _roleManager.CreateAsync(new IdentityRole(SD.Role_Employee)).GetAwaiter().GetResult(); + _roleManager.CreateAsync(new IdentityRole(SD.Role_User_Indi)).GetAwaiter().GetResult(); + _roleManager.CreateAsync(new IdentityRole(SD.Role_User_Comp)).GetAwaiter().GetResult(); + + //if roles are not created, then we will create admin user as well + + _userManager.CreateAsync(new ApplicationUser + { + UserName = "AdminoUser@outlook.com", + Email = "AdminoUser@outlook.com", + Name = "Admin Master", + PhoneNumber = "121212131313", + StreetAddress = "TownStreet", + State = "SWE", + PostalCode = "60666", + City = "Town" + }, "Admin123%").GetAwaiter().GetResult(); + ApplicationUser user = _db.ApplicationUsers.FirstOrDefault(u => u.Email == "AdminoUser@outlook.com"); + + + _userManager.AddToRoleAsync(user, SD.Role_Admin).GetAwaiter().GetResult(); + } + return; + } + } +} diff --git a/XYZStore.DataAccess/DbInitializer/IDbInitializer.cs b/XYZStore.DataAccess/DbInitializer/IDbInitializer.cs new file mode 100644 index 0000000..e72d479 --- /dev/null +++ b/XYZStore.DataAccess/DbInitializer/IDbInitializer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace XYZStore.DataAccess.DbInitializer +{ + public interface IDbInitializer + { + void Initialize(); + } +} diff --git a/XYZStore.DataAccess/Migrations/20220908124304_AddedIdentityToDb.Designer.cs b/XYZStore.DataAccess/Migrations/20220908124304_AddedIdentityToDb.Designer.cs new file mode 100644 index 0000000..7c9aed0 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220908124304_AddedIdentityToDb.Designer.cs @@ -0,0 +1,400 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220908124304_AddedIdentityToDb")] + partial class AddedIdentityToDb + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", 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("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("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.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220908124304_AddedIdentityToDb.cs b/XYZStore.DataAccess/Migrations/20220908124304_AddedIdentityToDb.cs new file mode 100644 index 0000000..c94129b --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220908124304_AddedIdentityToDb.cs @@ -0,0 +1,221 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class AddedIdentityToDb : 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), + 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: "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(128)", maxLength: 128, nullable: false), + ProviderKey = table.Column(type: "nvarchar(128)", maxLength: 128, 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(128)", maxLength: 128, nullable: false), + Name = table.Column(type: "nvarchar(128)", maxLength: 128, 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.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: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + } + + 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: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220908130411_extendIdentityUser.Designer.cs b/XYZStore.DataAccess/Migrations/20220908130411_extendIdentityUser.Designer.cs new file mode 100644 index 0000000..acab724 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220908130411_extendIdentityUser.Designer.cs @@ -0,0 +1,429 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220908130411_extendIdentityUser")] + partial class extendIdentityUser + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220908130411_extendIdentityUser.cs b/XYZStore.DataAccess/Migrations/20220908130411_extendIdentityUser.cs new file mode 100644 index 0000000..1e072f5 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220908130411_extendIdentityUser.cs @@ -0,0 +1,76 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class extendIdentityUser : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "City", + table: "AspNetUsers", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "Discriminator", + table: "AspNetUsers", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Name", + table: "AspNetUsers", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "PostalCode", + table: "AspNetUsers", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "State", + table: "AspNetUsers", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "StreetAddress", + table: "AspNetUsers", + type: "nvarchar(max)", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "City", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "Discriminator", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "Name", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "PostalCode", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "State", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "StreetAddress", + table: "AspNetUsers"); + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912085919_addedCompanyToDb.Designer.cs b/XYZStore.DataAccess/Migrations/20220912085919_addedCompanyToDb.Designer.cs new file mode 100644 index 0000000..4794367 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912085919_addedCompanyToDb.Designer.cs @@ -0,0 +1,461 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220912085919_addedCompanyToDb")] + partial class addedCompanyToDb + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912085919_addedCompanyToDb.cs b/XYZStore.DataAccess/Migrations/20220912085919_addedCompanyToDb.cs new file mode 100644 index 0000000..144d7dd --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912085919_addedCompanyToDb.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class addedCompanyToDb : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Companies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + StreetAddress = table.Column(type: "nvarchar(max)", nullable: true), + City = table.Column(type: "nvarchar(max)", nullable: true), + State = table.Column(type: "nvarchar(max)", nullable: true), + PostalCode = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Companies", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Companies"); + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912121121_addedCompanyIdToUser.Designer.cs b/XYZStore.DataAccess/Migrations/20220912121121_addedCompanyIdToUser.Designer.cs new file mode 100644 index 0000000..3fca8e9 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912121121_addedCompanyIdToUser.Designer.cs @@ -0,0 +1,474 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220912121121_addedCompanyIdToUser")] + partial class addedCompanyIdToUser + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912121121_addedCompanyIdToUser.cs b/XYZStore.DataAccess/Migrations/20220912121121_addedCompanyIdToUser.cs new file mode 100644 index 0000000..b362f1e --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912121121_addedCompanyIdToUser.cs @@ -0,0 +1,118 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class addedCompanyIdToUser : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Name", + table: "AspNetUserTokens", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserTokens", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + migrationBuilder.AddColumn( + name: "CompanyId", + table: "AspNetUsers", + type: "int", + nullable: true); + + migrationBuilder.AlterColumn( + name: "ProviderKey", + table: "AspNetUserLogins", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserLogins", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUsers_CompanyId", + table: "AspNetUsers", + column: "CompanyId"); + + migrationBuilder.AddForeignKey( + name: "FK_AspNetUsers_Companies_CompanyId", + table: "AspNetUsers", + column: "CompanyId", + principalTable: "Companies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AspNetUsers_Companies_CompanyId", + table: "AspNetUsers"); + + migrationBuilder.DropIndex( + name: "IX_AspNetUsers_CompanyId", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "CompanyId", + table: "AspNetUsers"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "AspNetUserTokens", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserTokens", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AlterColumn( + name: "ProviderKey", + table: "AspNetUserLogins", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserLogins", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912124223_addedCompanyIdToUserCorrect.Designer.cs b/XYZStore.DataAccess/Migrations/20220912124223_addedCompanyIdToUserCorrect.Designer.cs new file mode 100644 index 0000000..c416729 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912124223_addedCompanyIdToUserCorrect.Designer.cs @@ -0,0 +1,474 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220912124223_addedCompanyIdToUserCorrect")] + partial class addedCompanyIdToUserCorrect + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912124223_addedCompanyIdToUserCorrect.cs b/XYZStore.DataAccess/Migrations/20220912124223_addedCompanyIdToUserCorrect.cs new file mode 100644 index 0000000..60160bc --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912124223_addedCompanyIdToUserCorrect.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class addedCompanyIdToUserCorrect : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912131641_addedCompanyIdToUserCorrect2.Designer.cs b/XYZStore.DataAccess/Migrations/20220912131641_addedCompanyIdToUserCorrect2.Designer.cs new file mode 100644 index 0000000..e42d138 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912131641_addedCompanyIdToUserCorrect2.Designer.cs @@ -0,0 +1,474 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220912131641_addedCompanyIdToUserCorrect2")] + partial class addedCompanyIdToUserCorrect2 + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220912131641_addedCompanyIdToUserCorrect2.cs b/XYZStore.DataAccess/Migrations/20220912131641_addedCompanyIdToUserCorrect2.cs new file mode 100644 index 0000000..7807489 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220912131641_addedCompanyIdToUserCorrect2.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class addedCompanyIdToUserCorrect2 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913100927_null.Designer.cs b/XYZStore.DataAccess/Migrations/20220913100927_null.Designer.cs new file mode 100644 index 0000000..7dbbb17 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913100927_null.Designer.cs @@ -0,0 +1,457 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220913100927_null")] + partial class @null + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913100927_null.cs b/XYZStore.DataAccess/Migrations/20220913100927_null.cs new file mode 100644 index 0000000..baebd1b --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913100927_null.cs @@ -0,0 +1,92 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class @null : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Name", + table: "AspNetUserTokens", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserTokens", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + migrationBuilder.AlterColumn( + name: "ProviderKey", + table: "AspNetUserLogins", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserLogins", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(128)", + oldMaxLength: 128); + + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Companies"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "AspNetUserTokens", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserTokens", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AlterColumn( + name: "ProviderKey", + table: "AspNetUserLogins", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserLogins", + type: "nvarchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913115231_Adding.Designer.cs b/XYZStore.DataAccess/Migrations/20220913115231_Adding.Designer.cs new file mode 100644 index 0000000..fb96fb5 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913115231_Adding.Designer.cs @@ -0,0 +1,457 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220913115231_Adding")] + partial class Adding + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913115231_Adding.cs b/XYZStore.DataAccess/Migrations/20220913115231_Adding.cs new file mode 100644 index 0000000..add086e --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913115231_Adding.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class Adding : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913125952_addedShoppingCartToDb.Designer.cs b/XYZStore.DataAccess/Migrations/20220913125952_addedShoppingCartToDb.Designer.cs new file mode 100644 index 0000000..72bca67 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913125952_addedShoppingCartToDb.Designer.cs @@ -0,0 +1,520 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220913125952_addedShoppingCartToDb")] + partial class addedShoppingCartToDb + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.HasIndex("ProductId"); + + b.ToTable("ShoppingCarts"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913125952_addedShoppingCartToDb.cs b/XYZStore.DataAccess/Migrations/20220913125952_addedShoppingCartToDb.cs new file mode 100644 index 0000000..1338d00 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913125952_addedShoppingCartToDb.cs @@ -0,0 +1,86 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class addedShoppingCartToDb : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + //migrationBuilder.AddColumn( + // name: "CompanyId", + // table: "AspNetUsers", + // type: "int", + // nullable: true); + + migrationBuilder.CreateTable( + name: "ShoppingCarts", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProductId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + ApplicationUserId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShoppingCarts", x => x.Id); + table.ForeignKey( + name: "FK_ShoppingCarts_AspNetUsers_ApplicationUserId", + column: x => x.ApplicationUserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShoppingCarts_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + //migrationBuilder.CreateIndex( + // name: "IX_AspNetUsers_CompanyId", + // table: "AspNetUsers", + // column: "CompanyId"); + + migrationBuilder.CreateIndex( + name: "IX_ShoppingCarts_ApplicationUserId", + table: "ShoppingCarts", + column: "ApplicationUserId"); + + migrationBuilder.CreateIndex( + name: "IX_ShoppingCarts_ProductId", + table: "ShoppingCarts", + column: "ProductId"); + + //migrationBuilder.AddForeignKey( + // name: "FK_AspNetUsers_Companies_CompanyId", + // table: "AspNetUsers", + // column: "CompanyId", + // principalTable: "Companies", + // principalColumn: "Id", + // onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AspNetUsers_Companies_CompanyId", + table: "AspNetUsers"); + + migrationBuilder.DropTable( + name: "ShoppingCarts"); + + //migrationBuilder.DropIndex( + // name: "IX_AspNetUsers_CompanyId", + // table: "AspNetUsers"); + + //migrationBuilder.DropColumn( + // name: "CompanyId", + // table: "AspNetUsers"); + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913131814_null1.Designer.cs b/XYZStore.DataAccess/Migrations/20220913131814_null1.Designer.cs new file mode 100644 index 0000000..24c9ef6 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913131814_null1.Designer.cs @@ -0,0 +1,520 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220913131814_null1")] + partial class null1 + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.HasIndex("ProductId"); + + b.ToTable("ShoppingCarts"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220913131814_null1.cs b/XYZStore.DataAccess/Migrations/20220913131814_null1.cs new file mode 100644 index 0000000..997eecd --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220913131814_null1.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class null1 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220914114940_addedCart2.Designer.cs b/XYZStore.DataAccess/Migrations/20220914114940_addedCart2.Designer.cs new file mode 100644 index 0000000..70278dd --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220914114940_addedCart2.Designer.cs @@ -0,0 +1,520 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220914114940_addedCart2")] + partial class addedCart2 + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.HasIndex("ProductId"); + + b.ToTable("ShoppingCarts"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220914114940_addedCart2.cs b/XYZStore.DataAccess/Migrations/20220914114940_addedCart2.cs new file mode 100644 index 0000000..f046856 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220914114940_addedCart2.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class addedCart2 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220919073521_AddedOrderHeaderAndDetailsToDb.Designer.cs b/XYZStore.DataAccess/Migrations/20220919073521_AddedOrderHeaderAndDetailsToDb.Designer.cs new file mode 100644 index 0000000..e9348c0 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220919073521_AddedOrderHeaderAndDetailsToDb.Designer.cs @@ -0,0 +1,655 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220919073521_AddedOrderHeaderAndDetailsToDb")] + partial class AddedOrderHeaderAndDetailsToDb + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderDetails"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderHeader", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Carrier") + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderStatus") + .HasColumnType("nvarchar(max)"); + + b.Property("OrderTotal") + .HasColumnType("float"); + + b.Property("PaymentDate") + .HasColumnType("datetime2"); + + b.Property("PaymentDueDate") + .HasColumnType("datetime2"); + + b.Property("PaymentIntentId") + .HasColumnType("nvarchar(max)"); + + b.Property("PaymentStatus") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SessionId") + .HasColumnType("nvarchar(max)"); + + b.Property("ShippingDate") + .HasColumnType("datetime2"); + + b.Property("State") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TrackingNumber") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("OrderHeaders"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.HasIndex("ProductId"); + + b.ToTable("ShoppingCarts"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderDetail", b => + { + b.HasOne("XYZStore.Models.Models.OrderHeader", "OrderHeader") + .WithMany() + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OrderHeader"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderHeader", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220919073521_AddedOrderHeaderAndDetailsToDb.cs b/XYZStore.DataAccess/Migrations/20220919073521_AddedOrderHeaderAndDetailsToDb.cs new file mode 100644 index 0000000..340eac2 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220919073521_AddedOrderHeaderAndDetailsToDb.cs @@ -0,0 +1,101 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class AddedOrderHeaderAndDetailsToDb : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "OrderHeaders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ApplicationUserId = table.Column(type: "nvarchar(450)", nullable: false), + OrderDate = table.Column(type: "datetime2", nullable: false), + ShippingDate = table.Column(type: "datetime2", nullable: false), + OrderTotal = table.Column(type: "float", nullable: false), + OrderStatus = table.Column(type: "nvarchar(max)", nullable: true), + PaymentStatus = table.Column(type: "nvarchar(max)", nullable: true), + TrackingNumber = table.Column(type: "nvarchar(max)", nullable: true), + Carrier = table.Column(type: "nvarchar(max)", nullable: true), + PaymentDate = table.Column(type: "datetime2", nullable: false), + PaymentDueDate = table.Column(type: "datetime2", nullable: false), + SessionId = table.Column(type: "nvarchar(max)", nullable: true), + PaymentIntentId = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), + StreetAddress = table.Column(type: "nvarchar(max)", nullable: false), + City = table.Column(type: "nvarchar(max)", nullable: false), + State = table.Column(type: "nvarchar(max)", nullable: false), + PostalCode = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderHeaders", x => x.Id); + table.ForeignKey( + name: "FK_OrderHeaders_AspNetUsers_ApplicationUserId", + column: x => x.ApplicationUserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OrderDetails", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + OrderId = table.Column(type: "int", nullable: false), + ProductId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderDetails", x => x.Id); + table.ForeignKey( + name: "FK_OrderDetails_OrderHeaders_OrderId", + column: x => x.OrderId, + principalTable: "OrderHeaders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_OrderDetails_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_OrderDetails_OrderId", + table: "OrderDetails", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderDetails_ProductId", + table: "OrderDetails", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderHeaders_ApplicationUserId", + table: "OrderHeaders", + column: "ApplicationUserId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "OrderDetails"); + + migrationBuilder.DropTable( + name: "OrderHeaders"); + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220926124621_Test.Designer.cs b/XYZStore.DataAccess/Migrations/20220926124621_Test.Designer.cs new file mode 100644 index 0000000..7009c95 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220926124621_Test.Designer.cs @@ -0,0 +1,655 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using XYZStore.DataAccess; + +#nullable disable + +namespace XYZStore.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220926124621_Test")] + partial class Test + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + modelBuilder.Entity("XYZStore.Models.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDateTime") + .HasColumnType("datetime2"); + + b.Property("DisplayOrder") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("XYZStore.Models.CoverType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderDetails"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderHeader", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Carrier") + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderStatus") + .HasColumnType("nvarchar(max)"); + + b.Property("OrderTotal") + .HasColumnType("float"); + + b.Property("PaymentDate") + .HasColumnType("datetime2"); + + b.Property("PaymentDueDate") + .HasColumnType("datetime2"); + + b.Property("PaymentIntentId") + .HasColumnType("nvarchar(max)"); + + b.Property("PaymentStatus") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SessionId") + .HasColumnType("nvarchar(max)"); + + b.Property("ShippingDate") + .HasColumnType("datetime2"); + + b.Property("State") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TrackingNumber") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("OrderHeaders"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CoverTypeId") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Director") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IMDB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImageUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ListPrice") + .HasColumnType("float"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("Price10") + .HasColumnType("float"); + + b.Property("Price5") + .HasColumnType("float"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CoverTypeId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.HasIndex("ProductId"); + + b.ToTable("ShoppingCarts"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderDetail", b => + { + b.HasOne("XYZStore.Models.Models.OrderHeader", "OrderHeader") + .WithMany() + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OrderHeader"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderHeader", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.Product", b => + { + b.HasOne("XYZStore.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.CoverType", "CoverType") + .WithMany() + .HasForeignKey("CoverTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("CoverType"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/XYZStore.DataAccess/Migrations/20220926124621_Test.cs b/XYZStore.DataAccess/Migrations/20220926124621_Test.cs new file mode 100644 index 0000000..dfea9b4 --- /dev/null +++ b/XYZStore.DataAccess/Migrations/20220926124621_Test.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace XYZStore.Migrations +{ + public partial class Test : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/XYZStore.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs b/XYZStore.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs index e6f4cb1..8842c8a 100644 --- a/XYZStore.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/XYZStore.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs @@ -17,11 +17,215 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("ProductVersion", "6.0.9") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + 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("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.ToTable("AspNetUsers", (string)null); + + b.HasDiscriminator("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + + 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", (string)null); + }); + modelBuilder.Entity("XYZStore.Models.Category", b => { b.Property("Id") @@ -63,6 +267,143 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CoverType"); }); + modelBuilder.Entity("XYZStore.Models.Models.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderDetails"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderHeader", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Carrier") + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderStatus") + .HasColumnType("nvarchar(max)"); + + b.Property("OrderTotal") + .HasColumnType("float"); + + b.Property("PaymentDate") + .HasColumnType("datetime2"); + + b.Property("PaymentDueDate") + .HasColumnType("datetime2"); + + b.Property("PaymentIntentId") + .HasColumnType("nvarchar(max)"); + + b.Property("PaymentStatus") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SessionId") + .HasColumnType("nvarchar(max)"); + + b.Property("ShippingDate") + .HasColumnType("datetime2"); + + b.Property("State") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TrackingNumber") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("OrderHeaders"); + }); + modelBuilder.Entity("XYZStore.Models.Models.Product", b => { b.Property("Id") @@ -121,6 +462,143 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Products"); }); + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ApplicationUserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.HasIndex("ProductId"); + + b.ToTable("ShoppingCarts"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("nvarchar(max)"); + + b.Property("StreetAddress") + .HasColumnType("nvarchar(max)"); + + b.HasIndex("CompanyId"); + + b.HasDiscriminator().HasValue("ApplicationUser"); + }); + + 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", 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("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderDetail", b => + { + b.HasOne("XYZStore.Models.Models.OrderHeader", "OrderHeader") + .WithMany() + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OrderHeader"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.Models.OrderHeader", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + }); + modelBuilder.Entity("XYZStore.Models.Models.Product", b => { b.HasOne("XYZStore.Models.Category", "Category") @@ -139,6 +617,36 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("CoverType"); }); + + modelBuilder.Entity("XYZStore.Models.Models.ShoppingCart", b => + { + b.HasOne("XYZStore.Models.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("XYZStore.Models.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationUser"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("XYZStore.Models.ApplicationUser", b => + { + b.HasOne("XYZStore.Models.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + }); #pragma warning restore 612, 618 } } diff --git a/XYZStore.DataAccess/Repository/ApplicationUserRepository.cs b/XYZStore.DataAccess/Repository/ApplicationUserRepository.cs new file mode 100644 index 0000000..e7aa51d --- /dev/null +++ b/XYZStore.DataAccess/Repository/ApplicationUserRepository.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Models; + +namespace XYZStore.DataAccess.Repository +{ + public class ApplicationUserRepository : Repository, IApplicationUserRepository + { + private ApplicationDbContext _db; + + public ApplicationUserRepository(ApplicationDbContext db) : base(db) + { + _db = db; + } + + } +} diff --git a/XYZStore.DataAccess/Repository/CompanyRepository.cs b/XYZStore.DataAccess/Repository/CompanyRepository.cs new file mode 100644 index 0000000..a0b860c --- /dev/null +++ b/XYZStore.DataAccess/Repository/CompanyRepository.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository +{ + public class CompanyRepository : Repository, ICompanyRepository + { + private ApplicationDbContext _db; + + public CompanyRepository(ApplicationDbContext db) : base(db) + { + _db = db; + } + + public void Update(Company obj) + { + _db.Companies.Update(obj); + } + } +} diff --git a/XYZStore.DataAccess/Repository/IRepository/IApplicationUserRepository.cs b/XYZStore.DataAccess/Repository/IRepository/IApplicationUserRepository.cs new file mode 100644 index 0000000..92f3cd5 --- /dev/null +++ b/XYZStore.DataAccess/Repository/IRepository/IApplicationUserRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository.IRepository +{ + public interface IApplicationUserRepository : IRepository + { + + } +} diff --git a/XYZStore.DataAccess/Repository/IRepository/ICategoryRepository.cs b/XYZStore.DataAccess/Repository/IRepository/ICategoryRepository.cs index 49e2733..9ef502c 100644 --- a/XYZStore.DataAccess/Repository/IRepository/ICategoryRepository.cs +++ b/XYZStore.DataAccess/Repository/IRepository/ICategoryRepository.cs @@ -9,7 +9,8 @@ namespace XYZStore.DataAccess.Repository.IRepository { public interface ICategoryRepository : IRepository { - void Update(Category obj); - + void Update(Category obj); + } + } diff --git a/XYZStore.DataAccess/Repository/IRepository/ICompanyRepository.cs b/XYZStore.DataAccess/Repository/IRepository/ICompanyRepository.cs new file mode 100644 index 0000000..166620b --- /dev/null +++ b/XYZStore.DataAccess/Repository/IRepository/ICompanyRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository.IRepository +{ + public interface ICompanyRepository : IRepository + { + void Update(Company obj); + } +} diff --git a/XYZStore.DataAccess/Repository/IRepository/IOrderDetailRepository.cs b/XYZStore.DataAccess/Repository/IRepository/IOrderDetailRepository.cs new file mode 100644 index 0000000..f25cde3 --- /dev/null +++ b/XYZStore.DataAccess/Repository/IRepository/IOrderDetailRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository.IRepository +{ + public interface IOrderDetailRepository : IRepository + { + void Update(OrderDetail obj); + } +} diff --git a/XYZStore.DataAccess/Repository/IRepository/IOrderHeaderRepository.cs b/XYZStore.DataAccess/Repository/IRepository/IOrderHeaderRepository.cs new file mode 100644 index 0000000..1f3859f --- /dev/null +++ b/XYZStore.DataAccess/Repository/IRepository/IOrderHeaderRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository.IRepository +{ + public interface IOrderHeaderRepository : IRepository + { + void Update(OrderHeader obj); + void UpdateStatus(int id, string orderStatus, string? paymentStatus=null); + void UpdateStripePaymentID(int id, string sessionId, string paymentIntentId); + } +} diff --git a/XYZStore.DataAccess/Repository/IRepository/IRepository.cs b/XYZStore.DataAccess/Repository/IRepository/IRepository.cs index f465a6b..eef901c 100644 --- a/XYZStore.DataAccess/Repository/IRepository/IRepository.cs +++ b/XYZStore.DataAccess/Repository/IRepository/IRepository.cs @@ -9,8 +9,10 @@ namespace XYZStore.DataAccess.Repository.IRepository public interface IRepository where T : class { //T - Category - T GetFirstOrDefault(Expression> filter, string? includeProperties = null); - IEnumerable GetAll(string? includeProperties = null); + T GetFirstOrDefault(Expression> filter, + string? includeProperties = null, bool tracked = true); + IEnumerable GetAll(Expression>? filter=null, + string? includeProperties = null); void Add(T entity); void Remove(T entity); void RemoveRange(IEnumerable entity); diff --git a/XYZStore.DataAccess/Repository/IRepository/IShoppingCartRepository.cs b/XYZStore.DataAccess/Repository/IRepository/IShoppingCartRepository.cs new file mode 100644 index 0000000..eef5b86 --- /dev/null +++ b/XYZStore.DataAccess/Repository/IRepository/IShoppingCartRepository.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository.IRepository +{ + public interface IShoppingCartRepository: IRepository + { + int IncrementCount(ShoppingCart shoppingCart, int count); + int DecrementCount(ShoppingCart shoppingCart, int count); + } +} diff --git a/XYZStore.DataAccess/Repository/IRepository/IUnitOfWork.cs b/XYZStore.DataAccess/Repository/IRepository/IUnitOfWork.cs index b2570f3..fd25c9c 100644 --- a/XYZStore.DataAccess/Repository/IRepository/IUnitOfWork.cs +++ b/XYZStore.DataAccess/Repository/IRepository/IUnitOfWork.cs @@ -11,6 +11,12 @@ public interface IUnitOfWork ICategoryRepository Category { get; } ICoverTypeRepository CoverType { get; } IProductRepository Product { get; } + ICompanyRepository Company { get; } + IShoppingCartRepository ShoppingCart { get; } + IApplicationUserRepository ApplicationUser { get; } + IOrderDetailRepository OrderDetail { get; } + IOrderHeaderRepository OrderHeader { get; } + void Save(); } } diff --git a/XYZStore.DataAccess/Repository/OrderDetailRepository.cs b/XYZStore.DataAccess/Repository/OrderDetailRepository.cs new file mode 100644 index 0000000..bb97426 --- /dev/null +++ b/XYZStore.DataAccess/Repository/OrderDetailRepository.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository +{ + public class OrderDetailRepository : Repository, IOrderDetailRepository + { + private ApplicationDbContext _db; + + public OrderDetailRepository(ApplicationDbContext db) : base(db) + { + _db = db; + } + + public void Update(OrderDetail obj) + { + _db.OrderDetails.Update(obj); + } + } +} diff --git a/XYZStore.DataAccess/Repository/OrderHeaderRepository.cs b/XYZStore.DataAccess/Repository/OrderHeaderRepository.cs new file mode 100644 index 0000000..cce00b5 --- /dev/null +++ b/XYZStore.DataAccess/Repository/OrderHeaderRepository.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository +{ + public class OrderHeaderRepository : Repository, IOrderHeaderRepository + { + private ApplicationDbContext _db; + + public OrderHeaderRepository(ApplicationDbContext db) : base(db) + { + _db = db; + } + + public void Update(OrderHeader obj) + { + _db.OrderHeaders.Update(obj); + } + + public void UpdateStatus(int id, string orderStatus, string? paymentStatus = null) + { + var orderFromDb = _db.OrderHeaders.FirstOrDefault(u => u.Id == id); + if (orderFromDb != null) + { + orderFromDb.OrderStatus = orderStatus; + if (paymentStatus != null) + { + orderFromDb.PaymentStatus = paymentStatus; + } + } + } + public void UpdateStripePaymentID(int id, string sessionId, string paymentIntentId) + { + var orderFromDb = _db.OrderHeaders.FirstOrDefault(u => u.Id == id); + orderFromDb.PaymentDate = DateTime.Now; + orderFromDb.PaymentIntentId = paymentIntentId; + orderFromDb.SessionId = sessionId; + //orderFromDb.PaymentIntentId = paymentIntentId; + } + } +} diff --git a/XYZStore.DataAccess/Repository/Repository.cs b/XYZStore.DataAccess/Repository/Repository.cs index b8e2ebc..7a52e11 100644 --- a/XYZStore.DataAccess/Repository/Repository.cs +++ b/XYZStore.DataAccess/Repository/Repository.cs @@ -17,6 +17,7 @@ public class Repository : IRepository where T : class public Repository(ApplicationDbContext db) { _db = db; + //_db.ShoppingCarts.AsNoTracking(); //_db.Products.Include(u => u.Category).Include(u => u.CoverType); //_db.Products.Include(u => u.Category); this.dbSet = _db.Set(); @@ -27,37 +28,51 @@ public void Add(T entity) dbSet.Add(entity); } //IncludeProperties "Category,CoverType" - public IEnumerable GetAll(string? includeProperties = null) + public IEnumerable GetAll(Expression>? filter=null, string? includeProperties = null) { IQueryable query = dbSet; - if(includeProperties != null) + if(filter != null) { - foreach(var includeProp in includeProperties.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries)) + query = query.Where(filter); + } + if (includeProperties != null) + { + foreach(var includeProp in includeProperties.Split(new char[] {','}, + StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProp); } } return query.ToList(); } - public T GetFirstOrDefault(Expression> filter, string? includeProperties = null) + public T GetFirstOrDefault(Expression> filter, + string? includeProperties = null, bool tracked = true) { - IQueryable query = dbSet; + IQueryable query; + if (tracked) + { + query = dbSet; + } + else + { + query = dbSet.AsNoTracking(); + } + query = query.Where(filter); if (includeProperties != null) { - foreach (var includeProp in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + foreach (var includeProp in includeProperties.Split(new char[] { ',' }, + StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProp); } } return query.FirstOrDefault(); } - public void Remove(T entity) { dbSet.Remove(entity); } - public void RemoveRange(IEnumerable entity) { dbSet.RemoveRange(entity); diff --git a/XYZStore.DataAccess/Repository/ShoppingCartRepository.cs b/XYZStore.DataAccess/Repository/ShoppingCartRepository.cs new file mode 100644 index 0000000..e5b5b03 --- /dev/null +++ b/XYZStore.DataAccess/Repository/ShoppingCartRepository.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Models; +using XYZStore.Models.Models; + +namespace XYZStore.DataAccess.Repository +{ + public class ShoppingCartRepository : Repository, IShoppingCartRepository + { + private ApplicationDbContext _db; + + public ShoppingCartRepository(ApplicationDbContext db) : base(db) + { + _db = db; + } + + public int DecrementCount(ShoppingCart shoppingCart, int count) + { + shoppingCart.Count -= count; + return shoppingCart.Count; + } + + public int IncrementCount(ShoppingCart shoppingCart, int count) + { + shoppingCart.Count += count; + return shoppingCart.Count; + } + } +} diff --git a/XYZStore.DataAccess/Repository/UnitOfWork.cs b/XYZStore.DataAccess/Repository/UnitOfWork.cs index b93a97d..9c7b5b5 100644 --- a/XYZStore.DataAccess/Repository/UnitOfWork.cs +++ b/XYZStore.DataAccess/Repository/UnitOfWork.cs @@ -5,12 +5,13 @@ using System.Threading.Tasks; using XYZStore.DataAccess.Repository.IRepository; using XYZStore.Models; +using XYZStore.Models.Models; namespace XYZStore.DataAccess.Repository { public class UnitOfWork : IUnitOfWork { - private ApplicationDbContext _db; + private ApplicationDbContext _db; public UnitOfWork(ApplicationDbContext db) { @@ -18,13 +19,28 @@ public UnitOfWork(ApplicationDbContext db) Category = new CategoryRepository(_db); CoverType = new CoverTypeRepository(_db); Product = new ProductRepository(_db); + Company = new CompanyRepository(_db); + ApplicationUser = new ApplicationUserRepository(_db); + ShoppingCart = new ShoppingCartRepository(_db); + OrderHeader = new OrderHeaderRepository(_db); + OrderDetail = new OrderDetailRepository(_db); } public ICategoryRepository Category { get; private set; } public ICoverTypeRepository CoverType { get; private set; } public IProductRepository Product { get; private set; } + public ICompanyRepository Company { get; private set; } + public IShoppingCartRepository ShoppingCart { get; private set; } + public IApplicationUserRepository ApplicationUser { get; private set; } + + public IOrderHeaderRepository OrderHeader { get; private set; } + + public IOrderDetailRepository OrderDetail { get; private set; } + public void Save() { _db.SaveChanges(); } } + + } diff --git a/XYZStore.DataAccess/XYZStore.DataAccess.csproj b/XYZStore.DataAccess/XYZStore.DataAccess.csproj index 474f5bf..cb7aad4 100644 --- a/XYZStore.DataAccess/XYZStore.DataAccess.csproj +++ b/XYZStore.DataAccess/XYZStore.DataAccess.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,18 +7,22 @@ - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/XYZStore.Models/ApplicationUser.cs b/XYZStore.Models/ApplicationUser.cs new file mode 100644 index 0000000..5266e6f --- /dev/null +++ b/XYZStore.Models/ApplicationUser.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models.Models; + +namespace XYZStore.Models +{ + public class ApplicationUser : IdentityUser + { + [Required] + public string Name { get; set; } + public string? StreetAddress { get; set; } + public string? City { get; set; } + public string? State { get; set; } + public string? PostalCode { get; set; } + public int? CompanyId { get; set; } + [ForeignKey("CompanyId")] + [ValidateNever] + public Company Company { get; set; } + } +} diff --git a/XYZStore.Models/Models/Company.cs b/XYZStore.Models/Models/Company.cs new file mode 100644 index 0000000..ad7584d --- /dev/null +++ b/XYZStore.Models/Models/Company.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace XYZStore.Models.Models +{ + public class Company + { + public int Id { get; set; } + [Required] + public string Name { get; set; } + public string? StreetAddress { get; set; } + public string? City { get; set; } + public string? State { get; set; } + public string? PostalCode { get; set; } + public string? PhoneNumber { get; set; } + } +} diff --git a/XYZStore.Models/Models/OrderDetail.cs b/XYZStore.Models/Models/OrderDetail.cs new file mode 100644 index 0000000..c06e482 --- /dev/null +++ b/XYZStore.Models/Models/OrderDetail.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + + +namespace XYZStore.Models.Models +{ + public class OrderDetail + { + public int Id { get; set; } + [Required] + public int OrderId { get; set; } + [ForeignKey("OrderId")] + [ValidateNever] + public OrderHeader OrderHeader { get; set; } + [Required] + public int ProductId { get; set; } + [ForeignKey("ProductId")] + [ValidateNever] + public Product Product { get; set; } + public int Count { get; set; } + public double Price { get; set; } + + } +} diff --git a/XYZStore.Models/Models/OrderHeader.cs b/XYZStore.Models/Models/OrderHeader.cs new file mode 100644 index 0000000..a125071 --- /dev/null +++ b/XYZStore.Models/Models/OrderHeader.cs @@ -0,0 +1,44 @@ +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace XYZStore.Models.Models +{ + public class OrderHeader + { + public int Id { get; set; } + public string ApplicationUserId { get; set; } + [ForeignKey("ApplicationUserId")] + [ValidateNever] + public ApplicationUser ApplicationUser { get; set; } + [Required] + public DateTime OrderDate { get; set; } + public DateTime ShippingDate { get; set; } + public double OrderTotal { get; set; } + public string? OrderStatus { get; set; } + public string? PaymentStatus { get; set; } + public string? TrackingNumber { get; set; } + public string? Carrier { get; set; } + public DateTime PaymentDate { get; set; } + public DateTime PaymentDueDate { get; set; } + public string? SessionId { get; set; } + public string? PaymentIntentId { get; set; } + [Required] + public string PhoneNumber { get; set; } + [Required] + public string StreetAddress { get; set; } + [Required] + public string City { get; set; } + [Required] + public string State { get; set; } + [Required] + public string PostalCode { get; set; } + [Required] + public string Name { get; set; } + } +} diff --git a/XYZStore.Models/Models/ShoppingCart.cs b/XYZStore.Models/Models/ShoppingCart.cs new file mode 100644 index 0000000..0fb0f36 --- /dev/null +++ b/XYZStore.Models/Models/ShoppingCart.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace XYZStore.Models.Models +{ + public class ShoppingCart + { + public int Id { get; set; } + + public int ProductId { get; set; } + [ForeignKey("ProductId")] + public Product Product { get; set; } + [Range(1, 1000, ErrorMessage = "Please enter a value between 1 and 1000")] + public int Count { get; set; } + public string ApplicationUserId { get; set; } + [ForeignKey("ApplicationUserId")] + public ApplicationUser ApplicationUser { get; set; } + [NotMapped] + public double Price { get; set; } + } +} diff --git a/XYZStore.Models/ViewModels/OrderVM.cs b/XYZStore.Models/ViewModels/OrderVM.cs new file mode 100644 index 0000000..c62fcf0 --- /dev/null +++ b/XYZStore.Models/ViewModels/OrderVM.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models.Models; + +namespace XYZStore.Models.ViewModels +{ + public class OrderVM + { + public OrderHeader OrderHeader { get; set; } + public IEnumerable OrderDetail { get; set; } + } +} diff --git a/XYZStore.Models/ViewModels/ShoppingCart.cs b/XYZStore.Models/ViewModels/ShoppingCart.cs deleted file mode 100644 index ae8561a..0000000 --- a/XYZStore.Models/ViewModels/ShoppingCart.cs +++ /dev/null @@ -1,16 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.ComponentModel.DataAnnotations; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; - -//namespace XYZStore.Models.ViewModels -//{ -// public class ShoppingCart -// { -// public Product Product { get; set; } -// [Range(1,1000,ErrorMessage ="Please enter a value between 1 and 1000")] -// public int Count { get; set; } -// } -//} diff --git a/XYZStore.Models/ViewModels/ShoppingCartVM.cs b/XYZStore.Models/ViewModels/ShoppingCartVM.cs new file mode 100644 index 0000000..fca8064 --- /dev/null +++ b/XYZStore.Models/ViewModels/ShoppingCartVM.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XYZStore.Models.Models; + +namespace XYZStore.Models.ViewModels +{ + public class ShoppingCartVM + { + public IEnumerable ListCart { get; set; } + public OrderHeader OrderHeader { get; set; } + } +} diff --git a/XYZStore.Models/XYZStore.Models.csproj b/XYZStore.Models/XYZStore.Models.csproj index 91d6605..5bff030 100644 --- a/XYZStore.Models/XYZStore.Models.csproj +++ b/XYZStore.Models/XYZStore.Models.csproj @@ -7,9 +7,12 @@ + - + + + diff --git a/XYZStore.Utility/EmailSender.cs b/XYZStore.Utility/EmailSender.cs new file mode 100644 index 0000000..7e2e411 --- /dev/null +++ b/XYZStore.Utility/EmailSender.cs @@ -0,0 +1,52 @@ +using MailKit.Net.Smtp; +using Microsoft.AspNetCore.Identity.UI.Services; +using Microsoft.Extensions.Configuration; +using MimeKit; +using SendGrid; +using SendGrid.Helpers.Mail; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace XYZStore.Utility +{ + public class EmailSender : IEmailSender + { + public string SendGridSecret { get; set; } + + public EmailSender(IConfiguration _config) + { + SendGridSecret = _config.GetValue("SendGrid:SecretKey"); + } + + public Task SendEmailAsync(string email, string subject, string htmlMessage) + { + //var emailToSend = new MimeMessage(); + //emailToSend.From.Add(MailboxAddress.Parse("Hammargren85@Outlook.Com")); + //emailToSend.To.Add(MailboxAddress.Parse(email)); + //emailToSend.Subject = subject; + //emailToSend.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = htmlMessage }; + + ////Send email + //using (var emailClient = new SmtpClient()) + //{ + // emailClient.Connect("smtp-mail.outlook.com", 587, MailKit.Security.SecureSocketOptions.StartTls); + // emailClient.Authenticate("Hammargren85@Outlook.Com", "ABC123abc%"); + // emailClient.Send(emailToSend); + // emailClient.Disconnect(true); + + // return Task.CompletedTask; + + var client = new SendGridClient(SendGridSecret); + var from = new EmailAddress("Hammargren85@outlook.com", "XYZStore-Movie"); + var to = new EmailAddress(email); + var msg = MailHelper.CreateSingleEmail(from, to, subject, "", htmlMessage); + + return client.SendEmailAsync(msg); + + + } + } +} \ No newline at end of file diff --git a/XYZStore.Utility/SD.cs b/XYZStore.Utility/SD.cs index 118ca90..14ca755 100644 --- a/XYZStore.Utility/SD.cs +++ b/XYZStore.Utility/SD.cs @@ -8,6 +8,23 @@ namespace XYZStore.Utility { public static class SD { + public const string Role_User_Indi = "Individual"; + public const string Role_User_Comp = "Company"; + public const string Role_Admin = "Admin"; + public const string Role_Employee = "Employee"; + public const string StatusPending = "Pending"; + public const string StatusApproved = "Approved"; + public const string StatusInProcess = "Processing"; + public const string StatusShipped = "Shipped"; + public const string StatusCancelled = "Cancelled"; + public const string StatusRefunded = "Refunded"; + + public const string PaymentStatusPending = "Pending"; + public const string PaymentStatusApproved = "Approved"; + public const string PaymentStatusDelayedPayment = "ApprovedForDelayedPayment"; + public const string PaymentStatusRejected = "Rejected"; + + public const string SessionCart = "SessionShoppingCart"; } } diff --git a/XYZStore.Utility/StripeSettings.cs b/XYZStore.Utility/StripeSettings.cs new file mode 100644 index 0000000..f7203c7 --- /dev/null +++ b/XYZStore.Utility/StripeSettings.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace XYZStore.Utility +{ + public class StripeSettings + { + public string SecretKey { get; set; } + public string PublishableKey { get; set; } + } +} diff --git a/XYZStore.Utility/XYZStore.Utility.csproj b/XYZStore.Utility/XYZStore.Utility.csproj index 39f3134..fb55795 100644 --- a/XYZStore.Utility/XYZStore.Utility.csproj +++ b/XYZStore.Utility/XYZStore.Utility.csproj @@ -7,8 +7,12 @@ - + + + + + diff --git a/XYZStore/Areas/Admin/Controllers/CategoryController.cs b/XYZStore/Areas/Admin/Controllers/CategoryController.cs index a735b39..1597b0c 100644 --- a/XYZStore/Areas/Admin/Controllers/CategoryController.cs +++ b/XYZStore/Areas/Admin/Controllers/CategoryController.cs @@ -3,10 +3,13 @@ using XYZStore.Models; using System.Linq; using XYZStore.DataAccess.Repository.IRepository; +using Microsoft.AspNetCore.Authorization; +using XYZStore.Utility; namespace XYZStore.Areas.Admin.Controllers; [Area("Admin")] +[Authorize(Roles = SD.Role_Admin)] public class CategoryController : Controller { private readonly IUnitOfWork _unitOfWork; diff --git a/XYZStore/Areas/Admin/Controllers/CompanyController.cs b/XYZStore/Areas/Admin/Controllers/CompanyController.cs new file mode 100644 index 0000000..985fcc2 --- /dev/null +++ b/XYZStore/Areas/Admin/Controllers/CompanyController.cs @@ -0,0 +1,88 @@ +using Microsoft.AspNetCore.Mvc; +using XYZStore.DataAccess; +using XYZStore.Models; +using System.Linq; +using XYZStore.DataAccess.Repository.IRepository; +using System.Collections.Generic; +using XYZStore.Models.Models; +using Microsoft.AspNetCore.Mvc.Rendering; +using XYZStore.Models.ViewModels; +using Microsoft.AspNetCore.Authorization; +using XYZStore.Utility; + +namespace XYZStore.Areas.Admin.Controllers; + +[Area("Admin")] +[Authorize(Roles = SD.Role_Admin)] +public class CompanyController : Controller +{ + private readonly IUnitOfWork _unitOfWork; + + public CompanyController(IUnitOfWork unitOfWork) + { + _unitOfWork = unitOfWork; + } + public IActionResult Index() + { + return View(); + } + //GET + public IActionResult Upsert(int? id) + { + Company company = new(); + if (id==null || id == 0) + { + return View(company); + } + else + { + company =_unitOfWork.Company.GetFirstOrDefault(u => u.Id == id); + return View(company); + } + } + //POST + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Upsert(Company obj,IFormFile? file) + { + if (ModelState.IsValid) + { + if (obj.Id == 0) + { + _unitOfWork.Company.Add(obj); + TempData["success"] = "Company Created Successfully!"; + } + else + { + TempData["success"] = "Company Updated Successfully!"; + _unitOfWork.Company.Update(obj); + } + _unitOfWork.Save(); + + return RedirectToAction("Index"); + } + return View(obj); + } + + #region API CALLS + [HttpGet] + public IActionResult GetAll() + { + var companyList = _unitOfWork.Company.GetAll(); + return Json(new { data = companyList }); + } + //POST + [HttpDelete] + public IActionResult Delete(int? id) + { + var obj = _unitOfWork.Company.GetFirstOrDefault(u => u.Id == id); + if (obj == null) + { + return Json(new { success = false, message = "Error while deleting" }); + } + _unitOfWork.Company.Remove(obj); + _unitOfWork.Save(); + return Json(new { success = true, message = "Delete Successfully!" }); + } + #endregion +} diff --git a/XYZStore/Areas/Admin/Controllers/CoverTypeController.cs b/XYZStore/Areas/Admin/Controllers/CoverTypeController.cs index 9b67437..26b0e76 100644 --- a/XYZStore/Areas/Admin/Controllers/CoverTypeController.cs +++ b/XYZStore/Areas/Admin/Controllers/CoverTypeController.cs @@ -4,10 +4,13 @@ using System.Linq; using XYZStore.DataAccess.Repository.IRepository; using System.Collections.Generic; +using Microsoft.AspNetCore.Authorization; +using XYZStore.Utility; namespace XYZStore.Areas.Admin.Controllers; [Area("Admin")] +[Authorize(Roles = SD.Role_Admin)] public class CoverTypeController : Controller { private readonly IUnitOfWork _unitOfWork; diff --git a/XYZStore/Areas/Admin/Controllers/OrderController.cs b/XYZStore/Areas/Admin/Controllers/OrderController.cs new file mode 100644 index 0000000..1e90c58 --- /dev/null +++ b/XYZStore/Areas/Admin/Controllers/OrderController.cs @@ -0,0 +1,234 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Stripe; +using Stripe.Checkout; +using System.Security.Claims; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Models.Models; +using XYZStore.Models.ViewModels; +using XYZStore.Utility; + +namespace XYZStore.Areas.Admin.Controllers +{ + [Area("Admin")] + [Authorize] + public class OrderController : Controller + { + private readonly IUnitOfWork _unitOfWork; + [BindProperty] + public OrderVM OrderVM { get; set; } + + public OrderController(IUnitOfWork unitOfWork) + { + _unitOfWork = unitOfWork; + } + public IActionResult Index() + { + return View(); + } + + public IActionResult Details(int orderId) + { + OrderVM = new OrderVM() + { + OrderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == orderId, includeProperties: "ApplicationUser"), + OrderDetail = _unitOfWork.OrderDetail.GetAll(u => u.OrderId == orderId, includeProperties: "Product"), + }; + return View(OrderVM); + } + + [ActionName("Details")] + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult DetailsPayNow() + { + OrderVM.OrderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == OrderVM.OrderHeader.Id, includeProperties: "ApplicationUser"); + OrderVM.OrderDetail = _unitOfWork.OrderDetail.GetAll(u => u.OrderId == OrderVM.OrderHeader.Id, includeProperties: "Product"); + + //Stripe Settings + var domain = "https://localhost:44340/"; + var options = new SessionCreateOptions + + { + PaymentMethodTypes = new List + { + "card", + }, + + LineItems = new List(), + Mode = "payment", + SuccessUrl = domain + $"admin/order/PaymentConfirmation?orderHeaderid={OrderVM.OrderHeader.Id}", + CancelUrl = domain + $"admin/order/details?orderId={OrderVM.OrderHeader.Id}", + }; + foreach (var item in OrderVM.OrderDetail) + { + var sessionLineItem = new SessionLineItemOptions + { + PriceData = new SessionLineItemPriceDataOptions + { + UnitAmount = (long)(item.Price * 100), + Currency = "sek", + ProductData = new SessionLineItemPriceDataProductDataOptions + { + Name = item.Product.Title + }, + }, + Quantity = item.Count, + }; + options.LineItems.Add(sessionLineItem); + } + + var service = new SessionService(); + Session session = service.Create(options); + + _unitOfWork.OrderHeader.UpdateStripePaymentID(OrderVM.OrderHeader.Id, session.Id, session.PaymentIntentId); + _unitOfWork.Save(); + Response.Headers.Add("Location", session.Url); + return new StatusCodeResult(303); + } + + public IActionResult PaymentConfirmation(int orderHeaderid) + { + OrderHeader orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == orderHeaderid); + + if (orderHeader.PaymentStatus == SD.PaymentStatusDelayedPayment) + { + var service = new SessionService(); + Session session = service.Get(orderHeader.SessionId); + + //check the stripe status + if (session.PaymentStatus.ToLower() == "paid") + { + _unitOfWork.OrderHeader.UpdateStatus(orderHeaderid, orderHeader.OrderStatus, SD.PaymentStatusApproved); + _unitOfWork.Save(); + } + } + return View(orderHeaderid); + } + + + [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] + [ValidateAntiForgeryToken] + public IActionResult UpdateOrderDetail() + { + var orderHeaderFromDb = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == OrderVM.OrderHeader.Id, tracked:false); + orderHeaderFromDb.Name = OrderVM.OrderHeader.Name; + orderHeaderFromDb.PhoneNumber = OrderVM.OrderHeader.PhoneNumber; + orderHeaderFromDb.StreetAddress = OrderVM.OrderHeader.StreetAddress; + orderHeaderFromDb.City = OrderVM.OrderHeader.City; + orderHeaderFromDb.State = OrderVM.OrderHeader.State; + orderHeaderFromDb.PostalCode = OrderVM.OrderHeader.PostalCode; + if (OrderVM.OrderHeader.Carrier != null) + { + orderHeaderFromDb.Carrier = OrderVM.OrderHeader.Carrier; + } + if (orderHeaderFromDb.TrackingNumber != null) + { + orderHeaderFromDb.TrackingNumber = OrderVM.OrderHeader.TrackingNumber; + } + _unitOfWork.OrderHeader.Update(orderHeaderFromDb); + _unitOfWork.Save(); + TempData["success"] = "Order Details Updated Succesfully!"; + return RedirectToAction("Details","Order",new { orderId = orderHeaderFromDb.Id }); + } + + [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] + [ValidateAntiForgeryToken] + public IActionResult StartProcessing() + { + + _unitOfWork.OrderHeader.UpdateStatus(OrderVM.OrderHeader.Id, SD.StatusInProcess); + _unitOfWork.Save(); + TempData["success"] = "Order Status Updated Succesfully!"; + return RedirectToAction("Details", "Order", new { orderId = OrderVM.OrderHeader.Id }); + } + + [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] + [ValidateAntiForgeryToken] + public IActionResult ShipOrder() + { + var orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == OrderVM.OrderHeader.Id, tracked: false); + orderHeader.TrackingNumber = OrderVM.OrderHeader.TrackingNumber; + orderHeader.Carrier = OrderVM.OrderHeader.Carrier; + orderHeader.OrderStatus = SD.StatusShipped; + orderHeader.ShippingDate = DateTime.Now; + if (orderHeader.PaymentStatus == SD.PaymentStatusDelayedPayment) + { + orderHeader.PaymentDueDate = DateTime.Now.AddDays(30); + } + _unitOfWork.OrderHeader.Update(orderHeader); + _unitOfWork.Save(); + TempData["success"] = "Order Shipped Succesfully!"; + return RedirectToAction("Details", "Order", new { orderId = OrderVM.OrderHeader.Id }); + } + + [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] + [ValidateAntiForgeryToken] + public IActionResult CancelOrder() + { + var orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == OrderVM.OrderHeader.Id, tracked: false); + if (orderHeader.PaymentStatus == SD.PaymentStatusApproved) + { + var options = new RefundCreateOptions + { + Reason = RefundReasons.RequestedByCustomer, + PaymentIntent = orderHeader.PaymentIntentId + }; + + var service = new RefundService(); + Refund refund = service.Create(options); + + _unitOfWork.OrderHeader.UpdateStatus(orderHeader.Id, SD.StatusCancelled, SD.StatusRefunded); + } + else + { + _unitOfWork.OrderHeader.UpdateStatus(orderHeader.Id, SD.StatusCancelled, SD.StatusCancelled); + } + + _unitOfWork.Save(); + + TempData["success"] = "Order Cancelled Succesfully!"; + return RedirectToAction("Details", "Order", new { orderId = OrderVM.OrderHeader.Id }); + } + #region API CALLS + [HttpGet] + public IActionResult GetAll(string status) + { + IEnumerable orderHeaders; + + if(User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) { + orderHeaders = _unitOfWork.OrderHeader.GetAll(includeProperties: "ApplicationUser"); + } + else + { + var claimsIdentity = (ClaimsIdentity)User.Identity; + var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); + orderHeaders = _unitOfWork.OrderHeader.GetAll(u => u.ApplicationUserId == + claim.Value, includeProperties: "ApplicationUser"); + } + switch (status) + { + case "pending": + orderHeaders = orderHeaders.Where(u => u.PaymentStatus == SD.PaymentStatusDelayedPayment); + break; + case "inprocess": + orderHeaders = orderHeaders.Where(u => u.OrderStatus == SD.StatusInProcess); + break; + case "completed": + orderHeaders = orderHeaders.Where(u => u.OrderStatus == SD.StatusShipped); + break; + case "approved": + orderHeaders = orderHeaders.Where(u => u.OrderStatus == SD.StatusApproved); + break; + default: + break; + } + return Json(new { data = orderHeaders }); + } + #endregion + } +} diff --git a/XYZStore/Areas/Admin/Controllers/ProductController.cs b/XYZStore/Areas/Admin/Controllers/ProductController.cs index c391d2f..45caede 100644 --- a/XYZStore/Areas/Admin/Controllers/ProductController.cs +++ b/XYZStore/Areas/Admin/Controllers/ProductController.cs @@ -7,10 +7,13 @@ using XYZStore.Models.Models; using Microsoft.AspNetCore.Mvc.Rendering; using XYZStore.Models.ViewModels; +using Microsoft.AspNetCore.Authorization; +using XYZStore.Utility; namespace XYZStore.Areas.Admin.Controllers; [Area("Admin")] +[Authorize(Roles = SD.Role_Admin)] public class ProductController : Controller { private readonly IUnitOfWork _unitOfWork; diff --git a/XYZStore/Areas/Admin/Views/Company/Index.cshtml b/XYZStore/Areas/Admin/Views/Company/Index.cshtml new file mode 100644 index 0000000..2fcccd5 --- /dev/null +++ b/XYZStore/Areas/Admin/Views/Company/Index.cshtml @@ -0,0 +1,28 @@ +
+
+
+

Company List

+
+ +
+

+ + + + + + + + + + + +
NameAddressCityStatePhoneNumber
+
+@section Scripts{ + +} \ No newline at end of file diff --git a/XYZStore/Areas/Admin/Views/Company/Upsert.cshtml b/XYZStore/Areas/Admin/Views/Company/Upsert.cshtml new file mode 100644 index 0000000..cd43c88 --- /dev/null +++ b/XYZStore/Areas/Admin/Views/Company/Upsert.cshtml @@ -0,0 +1,64 @@ +@model XYZStore.Models.Models.Company + +
+ + +
+
+
+
+

@(Model.Id != 0 ? "Update" : "Create") Company

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ @if (Model.Id != 0) + { + + } + else + { + + } + + Back To List + +
+
+
+
+
+@section Scripts{ +@{ + + } +} diff --git a/XYZStore/Areas/Admin/Views/Order/Details.cshtml b/XYZStore/Areas/Admin/Views/Order/Details.cshtml new file mode 100644 index 0000000..14ade0e --- /dev/null +++ b/XYZStore/Areas/Admin/Views/Order/Details.cshtml @@ -0,0 +1,291 @@ +@model XYZStore.Models.ViewModels.OrderVM +@using XYZStore.Utility + +
+ +
+
+
+
+
+
+   Order Summary +
+ +
+
+
+
+
+
+
+

+ PickUp Details: +

+
+
+
Name
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
Phone
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
Address
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
City
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
State
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
Zip Code
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
Email
+
+ +
+
+
+
Order Date
+
+ +
+
+
+
Carrier
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
Tracking
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + + + } + else + { + + } +
+
+
+
Shipping Date
+
+ +
+
+ @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { +
+
Session ID
+
+ +
+
+
+
Payment Intent ID
+
+ +
+
+ } +
+ @if (Model.OrderHeader.SessionId == null) + { +
Payment Due Date
+
+ +
+ } + else + { +
Payment Date
+
+ +
+ } +
+
+
Payment Status
+
+ +
+
+ + + +
+
+

+ Order Summary +

+ +
    + @foreach (var detail in Model.OrderDetail) + { +
  • +
    +
    + +
    @detail.Product.Title
    + Price : @detail.Price.ToString("c") + Quantity : @detail.Count +
    +
    +

    @((detail.Count * detail.Price).ToString("c"))

    +
    +
    +
  • + } +
  • +
    +
    +
    TOTAL
    +
    +
    +
    @Model.OrderHeader.OrderTotal.ToString("c")
    +
    +
    +
  • +
+ @if (Model.OrderHeader.PaymentStatus == SD.PaymentStatusDelayedPayment && + Model.OrderHeader.OrderStatus == SD.StatusShipped) + { + + } + @if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) + { + if (Model.OrderHeader.OrderStatus == SD.StatusApproved) + { + + } + if (Model.OrderHeader.OrderStatus == SD.StatusInProcess) + { + + } + @if (Model.OrderHeader.OrderStatus != SD.StatusRefunded && + Model.OrderHeader.OrderStatus != SD.StatusCancelled && + Model.OrderHeader.OrderStatus != SD.StatusShipped) + { + + } + } +
+
+
+
+
+
+
+ +@section Scripts { + + + +} \ No newline at end of file diff --git a/XYZStore/Areas/Admin/Views/Order/Index.cshtml b/XYZStore/Areas/Admin/Views/Order/Index.cshtml new file mode 100644 index 0000000..458af86 --- /dev/null +++ b/XYZStore/Areas/Admin/Views/Order/Index.cshtml @@ -0,0 +1,75 @@ +@{ + var status = Context.Request.Query["status"]; + var pending = "text-primary"; + var inprocess = "text-primary"; + var completed = "text-primary"; + var approved = "text-primary"; + var all = "text-primary"; + + switch (status) + { + case "pending": + pending = "active text-white"; + break; + case "inprocess": + inprocess = "active text-white"; + break; + case "completed": + completed = "active text-white"; + break; + case "approved": + approved = "active text-white"; + break; + default : + all = "active text-white"; + break; + } +} +
+ +

+ + + + + + + + + + + + +
IdNamePhone NumberEmailStatusTotal
+
+@section Scripts{ + +} \ No newline at end of file diff --git a/XYZStore/Areas/Admin/Views/Order/PaymentConfirmation.cshtml b/XYZStore/Areas/Admin/Views/Order/PaymentConfirmation.cshtml new file mode 100644 index 0000000..edee7ac --- /dev/null +++ b/XYZStore/Areas/Admin/Views/Order/PaymentConfirmation.cshtml @@ -0,0 +1,14 @@ +@model int + +
+
+

Payment Succesfull!

+ Order Number is : @Model

+ +
+
+
+ Payment has been placed successfully!
+ Back to Order Details +
+
diff --git a/XYZStore/Areas/Admin/Views/Product/Upsert.cshtml b/XYZStore/Areas/Admin/Views/Product/Upsert.cshtml index 80ccc91..c099c34 100644 --- a/XYZStore/Areas/Admin/Views/Product/Upsert.cshtml +++ b/XYZStore/Areas/Admin/Views/Product/Upsert.cshtml @@ -23,7 +23,7 @@
- +
@@ -101,12 +101,14 @@ } +} diff --git a/XYZStore/Areas/Identity/Pages/Account/Register.cshtml.cs b/XYZStore/Areas/Identity/Pages/Account/Register.cshtml.cs new file mode 100644 index 0000000..c9a239b --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -0,0 +1,248 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +#nullable disable + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI.Services; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.WebUtilities; +using Microsoft.Extensions.Logging; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Models; +using XYZStore.Utility; + +namespace XYZStore.Areas.Identity.Pages.Account +{ + public class RegisterModel : PageModel + { + private readonly SignInManager _signInManager; + private readonly UserManager _userManager; + private readonly IUserStore _userStore; + private readonly IUserEmailStore _emailStore; + private readonly ILogger _logger; + private readonly IEmailSender _emailSender; + private readonly RoleManager _roleManager; + private readonly IUnitOfWork _unitOfWork; + + public RegisterModel( + UserManager userManager, + IUserStore userStore, + SignInManager signInManager, + ILogger logger, + IEmailSender emailSender, + RoleManager roleManager, + IUnitOfWork unitOfWork) + { + _unitOfWork = unitOfWork; + _roleManager = roleManager; + _userManager = userManager; + _userStore = userStore; + _emailStore = GetEmailStore(); + _signInManager = signInManager; + _logger = logger; + _emailSender = emailSender; + + } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [BindProperty] + public InputModel Input { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public string ReturnUrl { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public IList ExternalLogins { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public class InputModel + { + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [Required] + [EmailAddress] + [Display(Name = "Email")] + public string Email { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [Required] + [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] + [DataType(DataType.Password)] + [Display(Name = "Password")] + public string Password { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [DataType(DataType.Password)] + [Display(Name = "Confirm password")] + [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] + public string ConfirmPassword { get; set; } + + [Required] + public string Name { get; set; } + public string? StreetAddress { get; set; } + public string? City { get; set; } + public string? State { get; set; } + public string? PostalCode { get; set; } + public string? PhoneNumber { get; set; } + public string? Role { get; set; } + public int? CompanyId { get; set; } + + [ValidateNever] + public IEnumerable RoleList { get; set; } + [ValidateNever] + public IEnumerable CompanyList { get; set; } + } + + + public async Task OnGetAsync(string returnUrl = null) + { + + ReturnUrl = returnUrl; + ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); + Input = new InputModel() + { + RoleList = _roleManager.Roles.Select(x => x.Name).Select(i => new SelectListItem + { + Text = i, + Value = i + }), + CompanyList = _unitOfWork.Company.GetAll().Select(i => new SelectListItem + { + Text = i.Name, + Value = i.Id.ToString() + }), + }; + } + public async Task OnPostAsync(string returnUrl = null) + { + returnUrl ??= Url.Content("~/"); + ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); + if (ModelState.IsValid) + { + var user = CreateUser(); + + await _userStore.SetUserNameAsync(user, Input.Email, CancellationToken.None); + await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None); + + user.StreetAddress = Input.StreetAddress; + user.City = Input.City; + user.State = Input.State; + user.PostalCode = Input.PostalCode; + user.Name = Input.Name; + user.PhoneNumber = Input.PhoneNumber; + + if(Input.Role == SD.Role_User_Comp) { + user.CompanyId = Input.CompanyId; + } + + var result = await _userManager.CreateAsync(user, Input.Password); + + if (result.Succeeded) + { + _logger.LogInformation("User created a new account with password."); + + if(Input.Role == null) { + await _userManager.AddToRoleAsync(user, SD.Role_User_Indi); + } + else + { + await _userManager.AddToRoleAsync(user, Input.Role); + } + + var userId = await _userManager.GetUserIdAsync(user); + var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); + code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); + var callbackUrl = Url.Page( + "/Account/ConfirmEmail", + pageHandler: null, + values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl }, + protocol: Request.Scheme); + + await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", + $"Please confirm your account by clicking here."); + + if (_userManager.Options.SignIn.RequireConfirmedAccount) + { + return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }); + } + else + { + if (User.IsInRole(SD.Role_Admin)) + { + TempData["success"] = "New User Created Successfully!"; + } + else + { + await _signInManager.SignInAsync(user, isPersistent: false); + + } + return LocalRedirect(returnUrl); + } + } + foreach (var error in result.Errors) + { + ModelState.AddModelError(string.Empty, error.Description); + } + } + + // If we got this far, something failed, redisplay form + return Page(); + } + + private ApplicationUser CreateUser() + { + try + { + return Activator.CreateInstance(); + } + catch + { + throw new InvalidOperationException($"Can't create an instance of '{nameof(IdentityUser)}'. " + + $"Ensure that '{nameof(IdentityUser)}' is not an abstract class and has a parameterless constructor, or alternatively " + + $"override the register page in /Areas/Identity/Pages/Account/Register.cshtml"); + } + } + + private IUserEmailStore GetEmailStore() + { + if (!_userManager.SupportsUserEmail) + { + throw new NotSupportedException("The default UI requires a user store with email support."); + } + return (IUserEmailStore)_userStore; + } + } +} diff --git a/XYZStore/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml b/XYZStore/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml new file mode 100644 index 0000000..d3e7f61 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml @@ -0,0 +1,23 @@ +@page +@model RegisterConfirmationModel +@{ + ViewData["Title"] = "Register confirmation"; +} + +

@ViewData["Title"]

+@{ + if (@Model.DisplayConfirmAccountLink) + { +

+ This app does not currently have a real email sender registered, see these docs for how to configure a real email sender. + Normally this would be emailed: Click here to confirm your account +

+ } + else + { +

+ Please check your email to confirm your account. +

+ } +} + diff --git a/XYZStore/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs b/XYZStore/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs new file mode 100644 index 0000000..ae999c7 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs @@ -0,0 +1,79 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +#nullable disable + +using System; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI.Services; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.WebUtilities; + +namespace XYZStore.Areas.Identity.Pages.Account +{ + [AllowAnonymous] + public class RegisterConfirmationModel : PageModel + { + private readonly UserManager _userManager; + private readonly IEmailSender _sender; + + public RegisterConfirmationModel(UserManager userManager, IEmailSender sender) + { + _userManager = userManager; + _sender = sender; + } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public string Email { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public bool DisplayConfirmAccountLink { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public string EmailConfirmationUrl { get; set; } + + public async Task OnGetAsync(string email, string returnUrl = null) + { + if (email == null) + { + return RedirectToPage("/Index"); + } + returnUrl = returnUrl ?? Url.Content("~/"); + + var user = await _userManager.FindByEmailAsync(email); + if (user == null) + { + return NotFound($"Unable to load user with email '{email}'."); + } + + Email = email; + // Once you add a real email sender, you should remove this code that lets you confirm the account + DisplayConfirmAccountLink = true; + if (DisplayConfirmAccountLink) + { + var userId = await _userManager.GetUserIdAsync(user); + var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); + code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); + EmailConfirmationUrl = Url.Page( + "/Account/ConfirmEmail", + pageHandler: null, + values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl }, + protocol: Request.Scheme); + } + + return Page(); + } + } +} diff --git a/XYZStore/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml b/XYZStore/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml new file mode 100644 index 0000000..ccce148 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml @@ -0,0 +1,26 @@ +@page +@model ResendEmailConfirmationModel +@{ + ViewData["Title"] = "Resend email confirmation"; +} + +

@ViewData["Title"]

+

Enter your email.

+
+
+
+
+
+
+ + + +
+ +
+
+
+ +@section Scripts { + +} diff --git a/XYZStore/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml.cs b/XYZStore/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml.cs new file mode 100644 index 0000000..b324100 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml.cs @@ -0,0 +1,88 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +#nullable disable + +using System; +using System.ComponentModel.DataAnnotations; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI.Services; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.WebUtilities; + +namespace XYZStore.Areas.Identity.Pages.Account +{ + [AllowAnonymous] + public class ResendEmailConfirmationModel : PageModel + { + private readonly UserManager _userManager; + private readonly IEmailSender _emailSender; + + public ResendEmailConfirmationModel(UserManager userManager, IEmailSender emailSender) + { + _userManager = userManager; + _emailSender = emailSender; + } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [BindProperty] + public InputModel Input { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public class InputModel + { + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [Required] + [EmailAddress] + public string Email { get; set; } + } + + public void OnGet() + { + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + var user = await _userManager.FindByEmailAsync(Input.Email); + if (user == null) + { + ModelState.AddModelError(string.Empty, "Verification email sent. Please check your email."); + return Page(); + } + + var userId = await _userManager.GetUserIdAsync(user); + var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); + code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); + var callbackUrl = Url.Page( + "/Account/ConfirmEmail", + pageHandler: null, + values: new { userId = userId, code = code }, + protocol: Request.Scheme); + await _emailSender.SendEmailAsync( + Input.Email, + "Confirm your email", + $"Please confirm your account by clicking here."); + + ModelState.AddModelError(string.Empty, "Verification email sent. Please check your email."); + return Page(); + } + } +} diff --git a/XYZStore/Areas/Identity/Pages/Account/ResetPassword.cshtml b/XYZStore/Areas/Identity/Pages/Account/ResetPassword.cshtml new file mode 100644 index 0000000..d8114b6 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/ResetPassword.cshtml @@ -0,0 +1,37 @@ +@page +@model ResetPasswordModel +@{ + ViewData["Title"] = "Reset password"; +} + +

@ViewData["Title"]

+

Reset your password.

+
+
+
+
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+ +
+
+
+ +@section Scripts { + +} diff --git a/XYZStore/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs b/XYZStore/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs new file mode 100644 index 0000000..aec7a3d --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs @@ -0,0 +1,117 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +#nullable disable + +using System; +using System.ComponentModel.DataAnnotations; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.WebUtilities; + +namespace XYZStore.Areas.Identity.Pages.Account +{ + public class ResetPasswordModel : PageModel + { + private readonly UserManager _userManager; + + public ResetPasswordModel(UserManager userManager) + { + _userManager = userManager; + } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [BindProperty] + public InputModel Input { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public class InputModel + { + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [Required] + [EmailAddress] + public string Email { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [Required] + [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] + [DataType(DataType.Password)] + public string Password { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [DataType(DataType.Password)] + [Display(Name = "Confirm password")] + [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] + public string ConfirmPassword { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [Required] + public string Code { get; set; } + + } + + public IActionResult OnGet(string code = null) + { + if (code == null) + { + return BadRequest("A code must be supplied for password reset."); + } + else + { + Input = new InputModel + { + Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)) + }; + return Page(); + } + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + var user = await _userManager.FindByEmailAsync(Input.Email); + if (user == null) + { + // Don't reveal that the user does not exist + return RedirectToPage("./ResetPasswordConfirmation"); + } + + var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password); + if (result.Succeeded) + { + return RedirectToPage("./ResetPasswordConfirmation"); + } + + foreach (var error in result.Errors) + { + ModelState.AddModelError(string.Empty, error.Description); + } + return Page(); + } + } +} diff --git a/XYZStore/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml b/XYZStore/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml new file mode 100644 index 0000000..c52552f --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml @@ -0,0 +1,10 @@ +@page +@model ResetPasswordConfirmationModel +@{ + ViewData["Title"] = "Reset password confirmation"; +} + +

@ViewData["Title"]

+

+ Your password has been reset. Please click here to log in. +

diff --git a/XYZStore/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs b/XYZStore/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs new file mode 100644 index 0000000..a7577f0 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +#nullable disable + +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace XYZStore.Areas.Identity.Pages.Account +{ + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [AllowAnonymous] + public class ResetPasswordConfirmationModel : PageModel + { + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public void OnGet() + { + } + } +} diff --git a/XYZStore/Areas/Identity/Pages/Account/_StatusMessage.cshtml b/XYZStore/Areas/Identity/Pages/Account/_StatusMessage.cshtml new file mode 100644 index 0000000..c898543 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/_StatusMessage.cshtml @@ -0,0 +1,10 @@ +@model string + +@if (!String.IsNullOrEmpty(Model)) +{ + var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success"; + +} diff --git a/XYZStore/Areas/Identity/Pages/Account/_ViewImports.cshtml b/XYZStore/Areas/Identity/Pages/Account/_ViewImports.cshtml new file mode 100644 index 0000000..fdae941 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Account/_ViewImports.cshtml @@ -0,0 +1 @@ +@using XYZStore.Areas.Identity.Pages.Account \ No newline at end of file diff --git a/XYZStore/Areas/Identity/Pages/Error.cshtml b/XYZStore/Areas/Identity/Pages/Error.cshtml new file mode 100644 index 0000000..b1f3143 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Error.cshtml @@ -0,0 +1,23 @@ +@page +@model ErrorModel +@{ + ViewData["Title"] = "Error"; +} + +

Error.

+

An error occurred while processing your request.

+ +@if (Model.ShowRequestId) +{ +

+ Request ID: @Model.RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. +

diff --git a/XYZStore/Areas/Identity/Pages/Error.cshtml.cs b/XYZStore/Areas/Identity/Pages/Error.cshtml.cs new file mode 100644 index 0000000..5540b5f --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/Error.cshtml.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +#nullable disable + +using System.Diagnostics; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace XYZStore.Areas.Identity.Pages +{ + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + [AllowAnonymous] + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public class ErrorModel : PageModel + { + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public string RequestId { get; set; } + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + /// + /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used + /// directly from your code. This API may change or be removed in future releases. + /// + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } +} diff --git a/XYZStore/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml b/XYZStore/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..efa2d88 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/XYZStore/Areas/Identity/Pages/_ViewImports.cshtml b/XYZStore/Areas/Identity/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..7e6cd1b --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using Microsoft.AspNetCore.Identity +@using XYZStore.Areas.Identity +@using XYZStore.Areas.Identity.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/XYZStore/Areas/Identity/Pages/_ViewStart.cshtml b/XYZStore/Areas/Identity/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..94fd419 --- /dev/null +++ b/XYZStore/Areas/Identity/Pages/_ViewStart.cshtml @@ -0,0 +1,4 @@ + +@{ + Layout = "/Views/Shared/_Layout.cshtml"; +} diff --git a/XYZStore/Program.cs b/XYZStore/Program.cs index b79e7a6..506f87e 100644 --- a/XYZStore/Program.cs +++ b/XYZStore/Program.cs @@ -2,6 +2,11 @@ using XYZStore.DataAccess; using XYZStore.DataAccess.Repository; using XYZStore.DataAccess.Repository.IRepository; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI.Services; +using XYZStore.Utility; +using Stripe; +using XYZStore.DataAccess.DbInitializer; var builder = WebApplication.CreateBuilder(args); @@ -10,8 +15,31 @@ builder.Services.AddDbContext(options => options.UseSqlServer( builder.Configuration.GetConnectionString("DefaultConnection") )); +builder.Services.Configure(builder.Configuration.GetSection("Stripe")); +builder.Services.AddIdentity().AddDefaultTokenProviders() +.AddEntityFrameworkStores(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddSingleton(); builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); +builder.Services.AddAuthentication().AddFacebook(options => +{ + options.AppId = "1231392804373482"; + options.AppSecret = "005bb0e42ea676f42c79b985763deb0d"; +}); +builder.Services.ConfigureApplicationCookie(options => +{ + options.LoginPath = $"/Identity/Account/Login"; + options.LogoutPath = $"/Identity/Account/Logout"; + options.AccessDeniedPath = $"/IdentityAccount/AccessDenied"; +}); +builder.Services.AddDistributedMemoryCache(); +builder.Services.AddSession(options => +{ + options.IdleTimeout = TimeSpan.FromMinutes(100); + options.Cookie.HttpOnly = true; + options.Cookie.IsEssential = true; +}); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -27,10 +55,26 @@ app.UseRouting(); -app.UseAuthorization(); +StripeConfiguration.ApiKey = builder.Configuration.GetSection("Stripe:SecretKey").Get(); +SeedDatabase(); +//StripeConfiguration.ApiKey = builder.Configuration.GetSection("Stripe:PublishableKey").Get(); +app.UseAuthentication(); +app.UseSession(); +app.UseAuthorization(); +app.MapRazorPages(); app.MapControllerRoute( name: "default", pattern: "{area=Customer}/{controller=Home}/{action=Index}/{id?}"); app.Run(); + + +void SeedDatabase() +{ + using (var scope = app.Services.CreateScope()) + { + var dbInitializer = scope.ServiceProvider.GetRequiredService(); + dbInitializer.Initialize(); + } +} \ No newline at end of file diff --git a/XYZStore/ViewComponents/ShoppingCartViewComponent.cs b/XYZStore/ViewComponents/ShoppingCartViewComponent.cs new file mode 100644 index 0000000..ca14213 --- /dev/null +++ b/XYZStore/ViewComponents/ShoppingCartViewComponent.cs @@ -0,0 +1,46 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Security.Claims; +using XYZStore.DataAccess.Repository.IRepository; +using XYZStore.Utility; +using System.Threading.Tasks; +using System.Linq; + + +namespace XYZStore.ViewComponents +{ + public class ShoppingCartViewComponent : ViewComponent + { + private readonly IUnitOfWork _unitOfWork; + + public ShoppingCartViewComponent(IUnitOfWork unitOfWork) + { + _unitOfWork = unitOfWork; + } + + public async Task InvokeAsync() + { + + var claimsIdentity = (ClaimsIdentity)User.Identity; + var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); + if (claim != null) + { + if(HttpContext.Session.GetInt32(SD.SessionCart) != null) + { + return View(HttpContext.Session.GetInt32(SD.SessionCart)); + } + else + { + HttpContext.Session.SetInt32(SD.SessionCart, + _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value).ToList().Count); + return View(HttpContext.Session.GetInt32(SD.SessionCart)); + } + } + else + { + HttpContext.Session.Clear(); + return View(0); + } + } + } +} diff --git a/XYZStore/Views/Shared/Components/ShoppingCart/Default.cshtml b/XYZStore/Views/Shared/Components/ShoppingCart/Default.cshtml new file mode 100644 index 0000000..45b71b9 --- /dev/null +++ b/XYZStore/Views/Shared/Components/ShoppingCart/Default.cshtml @@ -0,0 +1,3 @@ +@model int + +   (@Model) \ No newline at end of file diff --git a/XYZStore/Views/Shared/_Layout.cshtml b/XYZStore/Views/Shared/_Layout.cshtml index b7b12a7..ade9b96 100644 --- a/XYZStore/Views/Shared/_Layout.cshtml +++ b/XYZStore/Views/Shared/_Layout.cshtml @@ -1,4 +1,7 @@ - +@using Microsoft.AspNetCore.Http +@using XYZStore.Utility +@inject IHttpContextAccessor HttpContextAccessor + @@ -20,22 +23,37 @@