diff --git a/WebStore.DAL/Class1.cs b/WebStore.DAL/Class1.cs new file mode 100644 index 0000000..065e639 --- /dev/null +++ b/WebStore.DAL/Class1.cs @@ -0,0 +1,8 @@ +using System; + +namespace WebStore.DAL +{ + public class Class1 + { + } +} diff --git a/WebStore.DAL/Context/WebStoreDB.cs b/WebStore.DAL/Context/WebStoreDB.cs new file mode 100644 index 0000000..b3ea0d8 --- /dev/null +++ b/WebStore.DAL/Context/WebStoreDB.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using WebStore.Domain.Entities; +using WebStore.Domain.Entities.Identity; + +namespace WebStore.DAL.Context +{ + // Консоль диспетчера пакетов + // 1. Переориентировать её на WebStore.DB + // 2. Выполнить Add-Migration Initial + // 3. Выполнить Update-Database + public class WebStoreDB : IdentityDbContext + { + public DbSet Products { get; set; } + + public DbSet
Sections { get; set; } + + public DbSet Brands { get; set; } + + public DbSet Employees { get; set; } + + public WebStoreDB(DbContextOptions Options) : base(Options) { } + } +} diff --git a/WebStore.DAL/Migrations/20200707170754_Initial.Designer.cs b/WebStore.DAL/Migrations/20200707170754_Initial.Designer.cs new file mode 100644 index 0000000..0c286bd --- /dev/null +++ b/WebStore.DAL/Migrations/20200707170754_Initial.Designer.cs @@ -0,0 +1,124 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebStore.DAL.Context; + +namespace WebStore.DAL.Migrations +{ + [DbContext(typeof(WebStoreDB))] + [Migration("20200707170754_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("WebStore.Domain.Entities.Brand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductBrands"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BrandId") + .HasColumnType("int"); + + b.Property("ImageUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("SectionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BrandId"); + + b.HasIndex("SectionId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("ProductSections"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.HasOne("WebStore.Domain.Entities.Brand", "Brand") + .WithMany("Products") + .HasForeignKey("BrandId"); + + b.HasOne("WebStore.Domain.Entities.Section", "Section") + .WithMany("Products") + .HasForeignKey("SectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.HasOne("WebStore.Domain.Entities.Section", "ParentSection") + .WithMany() + .HasForeignKey("ParentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebStore.DAL/Migrations/20200707170754_Initial.cs b/WebStore.DAL/Migrations/20200707170754_Initial.cs new file mode 100644 index 0000000..88424d6 --- /dev/null +++ b/WebStore.DAL/Migrations/20200707170754_Initial.cs @@ -0,0 +1,102 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace WebStore.DAL.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ProductBrands", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: false), + Order = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProductBrands", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ProductSections", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: false), + Order = table.Column(nullable: false), + ParentId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ProductSections", x => x.Id); + table.ForeignKey( + name: "FK_ProductSections_ProductSections_ParentId", + column: x => x.ParentId, + principalTable: "ProductSections", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: false), + Order = table.Column(nullable: false), + SectionId = table.Column(nullable: false), + BrandId = table.Column(nullable: true), + ImageUrl = table.Column(nullable: true), + Price = table.Column(type: "decimal(18,2)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.Id); + table.ForeignKey( + name: "FK_Products_ProductBrands_BrandId", + column: x => x.BrandId, + principalTable: "ProductBrands", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Products_ProductSections_SectionId", + column: x => x.SectionId, + principalTable: "ProductSections", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Products_BrandId", + table: "Products", + column: "BrandId"); + + migrationBuilder.CreateIndex( + name: "IX_Products_SectionId", + table: "Products", + column: "SectionId"); + + migrationBuilder.CreateIndex( + name: "IX_ProductSections_ParentId", + table: "ProductSections", + column: "ParentId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Products"); + + migrationBuilder.DropTable( + name: "ProductBrands"); + + migrationBuilder.DropTable( + name: "ProductSections"); + } + } +} diff --git a/WebStore.DAL/Migrations/20200710162318_EmployeeAdded.Designer.cs b/WebStore.DAL/Migrations/20200710162318_EmployeeAdded.Designer.cs new file mode 100644 index 0000000..b8596be --- /dev/null +++ b/WebStore.DAL/Migrations/20200710162318_EmployeeAdded.Designer.cs @@ -0,0 +1,152 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebStore.DAL.Context; + +namespace WebStore.DAL.Migrations +{ + [DbContext(typeof(WebStoreDB))] + [Migration("20200710162318_EmployeeAdded")] + partial class EmployeeAdded + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("WebStore.Domain.Entities.Brand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductBrands"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("EmployementDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BrandId") + .HasColumnType("int"); + + b.Property("ImageUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("SectionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BrandId"); + + b.HasIndex("SectionId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("ProductSections"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.HasOne("WebStore.Domain.Entities.Brand", "Brand") + .WithMany("Products") + .HasForeignKey("BrandId"); + + b.HasOne("WebStore.Domain.Entities.Section", "Section") + .WithMany("Products") + .HasForeignKey("SectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.HasOne("WebStore.Domain.Entities.Section", "ParentSection") + .WithMany() + .HasForeignKey("ParentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebStore.DAL/Migrations/20200710162318_EmployeeAdded.cs b/WebStore.DAL/Migrations/20200710162318_EmployeeAdded.cs new file mode 100644 index 0000000..945400f --- /dev/null +++ b/WebStore.DAL/Migrations/20200710162318_EmployeeAdded.cs @@ -0,0 +1,34 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace WebStore.DAL.Migrations +{ + public partial class EmployeeAdded : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: false), + Surname = table.Column(nullable: true), + Patronymic = table.Column(nullable: true), + Age = table.Column(nullable: false), + EmployementDate = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Employees"); + } + } +} diff --git a/WebStore.DAL/Migrations/20200710165023_Identity.Designer.cs b/WebStore.DAL/Migrations/20200710165023_Identity.Designer.cs new file mode 100644 index 0000000..0d402c3 --- /dev/null +++ b/WebStore.DAL/Migrations/20200710165023_Identity.Designer.cs @@ -0,0 +1,405 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebStore.DAL.Context; + +namespace WebStore.DAL.Migrations +{ + [DbContext(typeof(WebStoreDB))] + [Migration("20200710165023_Identity")] + partial class Identity + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Brand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductBrands"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("EmployementDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Identity.Role", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Identity.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasColumnType("nvarchar(256)") + .HasMaxLength(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") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BrandId") + .HasColumnType("int"); + + b.Property("ImageUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("SectionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BrandId"); + + b.HasIndex("SectionId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("ProductSections"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.HasOne("WebStore.Domain.Entities.Brand", "Brand") + .WithMany("Products") + .HasForeignKey("BrandId"); + + b.HasOne("WebStore.Domain.Entities.Section", "Section") + .WithMany("Products") + .HasForeignKey("SectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.HasOne("WebStore.Domain.Entities.Section", "ParentSection") + .WithMany() + .HasForeignKey("ParentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebStore.DAL/Migrations/20200710165023_Identity.cs b/WebStore.DAL/Migrations/20200710165023_Identity.cs new file mode 100644 index 0000000..6532160 --- /dev/null +++ b/WebStore.DAL/Migrations/20200710165023_Identity.cs @@ -0,0 +1,221 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace WebStore.DAL.Migrations +{ + public partial class Identity : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + PasswordHash = table.Column(nullable: true), + SecurityStamp = table.Column(nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false), + TwoFactorEnabled = table.Column(nullable: false), + LockoutEnd = table.Column(nullable: true), + LockoutEnabled = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RoleId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(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(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(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(nullable: false), + ProviderKey = table.Column(nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(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(nullable: false), + RoleId = table.Column(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(nullable: false), + LoginProvider = table.Column(nullable: false), + Name = table.Column(nullable: false), + Value = table.Column(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/WebStore.DAL/Migrations/WebStoreDBModelSnapshot.cs b/WebStore.DAL/Migrations/WebStoreDBModelSnapshot.cs new file mode 100644 index 0000000..6367a59 --- /dev/null +++ b/WebStore.DAL/Migrations/WebStoreDBModelSnapshot.cs @@ -0,0 +1,403 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebStore.DAL.Context; + +namespace WebStore.DAL.Migrations +{ + [DbContext(typeof(WebStoreDB))] + partial class WebStoreDBModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Brand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductBrands"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("EmployementDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Identity.Role", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Identity.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasColumnType("nvarchar(256)") + .HasMaxLength(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") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BrandId") + .HasColumnType("int"); + + b.Property("ImageUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("SectionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BrandId"); + + b.HasIndex("SectionId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("ProductSections"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("WebStore.Domain.Entities.Identity.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Product", b => + { + b.HasOne("WebStore.Domain.Entities.Brand", "Brand") + .WithMany("Products") + .HasForeignKey("BrandId"); + + b.HasOne("WebStore.Domain.Entities.Section", "Section") + .WithMany("Products") + .HasForeignKey("SectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("WebStore.Domain.Entities.Section", b => + { + b.HasOne("WebStore.Domain.Entities.Section", "ParentSection") + .WithMany() + .HasForeignKey("ParentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebStore.DAL/WebStore.DAL.csproj b/WebStore.DAL/WebStore.DAL.csproj new file mode 100644 index 0000000..eb30744 --- /dev/null +++ b/WebStore.DAL/WebStore.DAL.csproj @@ -0,0 +1,19 @@ + + + + netstandard2.1 + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/WebStore.sln b/WebStore.sln index e9f8283..09bd34d 100644 --- a/WebStore.sln +++ b/WebStore.sln @@ -5,7 +5,9 @@ VisualStudioVersion = 16.0.30204.135 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebStore", "WebStore\WebStore.csproj", "{B502168C-6D9F-464B-96CD-A70F53CBA0BD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Webstore.Domain", "Webstore.Domain\Webstore.Domain.csproj", "{F8D311D4-D2AA-4B28-833D-3F9D0FA13493}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Webstore.Domain", "Webstore.Domain\Webstore.Domain.csproj", "{F8D311D4-D2AA-4B28-833D-3F9D0FA13493}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebStore.DAL", "WebStore.DAL\WebStore.DAL.csproj", "{773548F8-016A-4D50-ABE2-534294F85BAB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +23,10 @@ Global {F8D311D4-D2AA-4B28-833D-3F9D0FA13493}.Debug|Any CPU.Build.0 = Debug|Any CPU {F8D311D4-D2AA-4B28-833D-3F9D0FA13493}.Release|Any CPU.ActiveCfg = Release|Any CPU {F8D311D4-D2AA-4B28-833D-3F9D0FA13493}.Release|Any CPU.Build.0 = Release|Any CPU + {773548F8-016A-4D50-ABE2-534294F85BAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {773548F8-016A-4D50-ABE2-534294F85BAB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {773548F8-016A-4D50-ABE2-534294F85BAB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {773548F8-016A-4D50-ABE2-534294F85BAB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WebStore/Components/UserInfoViewComponent.cs b/WebStore/Components/UserInfoViewComponent.cs new file mode 100644 index 0000000..5198ac8 --- /dev/null +++ b/WebStore/Components/UserInfoViewComponent.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebStore.Components +{ + public class UserInfoViewComponent : ViewComponent + { + public IViewComponentResult Invoke() => User.Identity?.IsAuthenticated == true + ? View("UserInfo") + : View(); + } +} diff --git a/WebStore/Controllers/AccountController.cs b/WebStore/Controllers/AccountController.cs new file mode 100644 index 0000000..608aac2 --- /dev/null +++ b/WebStore/Controllers/AccountController.cs @@ -0,0 +1,86 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using WebStore.Domain.Entities.Identity; +using WebStore.ViewModels.Identity; + +namespace WebStore.Controllers +{ + public class AccountController : Controller + { + private readonly UserManager _UserManager; + private readonly SignInManager _SignInManager; + + public AccountController(UserManager UserManager, SignInManager SignInManager) + { + _UserManager = UserManager; + _SignInManager = SignInManager; + } + + #region Процесс регистрации нового пользвоателя + + public IActionResult Register() => View(new RegisterUserViewModel()); + + [HttpPost, ValidateAntiForgeryToken] + public async Task Register(RegisterUserViewModel Model) + { + if (!ModelState.IsValid) return View(Model); + + var user = new User + { + UserName = Model.UserName + }; + + var registration_result = await _UserManager.CreateAsync(user, Model.Password); + if (registration_result.Succeeded) + { + await _SignInManager.SignInAsync(user, false); + return RedirectToAction("Index", "Home"); + } + + foreach (var error in registration_result.Errors) + ModelState.AddModelError(string.Empty, error.Description); + + return View(Model); + } + + #endregion + + #region Процесс входа пользователя в систему + + public IActionResult Login(string ReturnUrl) => View(new LoginViewModel { ReturnUrl = ReturnUrl }); + + [HttpPost, ValidateAntiForgeryToken] + public async Task Login(LoginViewModel Model) + { + if (!ModelState.IsValid) return View(Model); + + var login_result = await _SignInManager.PasswordSignInAsync( + Model.UserName, + Model.Password, + Model.RememberMe, + false); + + if (login_result.Succeeded) + { + if (Url.IsLocalUrl(Model.ReturnUrl)) + return Redirect(Model.ReturnUrl); + return RedirectToAction("Index", "Home"); + } + + ModelState.AddModelError(string.Empty, "Неверное имя пользователя или пароль!"); + + return View(Model); + } + + #endregion + + public async Task Logout() + { + await _SignInManager.SignOutAsync(); + return RedirectToAction("Index", "Home"); + } + + public IActionResult AccessDenied() => View(); + } +} diff --git a/WebStore/Controllers/CatalogController.cs b/WebStore/Controllers/CatalogController.cs index 2867024..e69ca28 100644 --- a/WebStore/Controllers/CatalogController.cs +++ b/WebStore/Controllers/CatalogController.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Linq; using Microsoft.AspNetCore.Mvc; using WebStore.Domain; using WebStore.Infrastructure.Interfaces; +using WebStore.Infrastructure.Mapping; using WebStore.ViewModels; namespace WebStore.Controllers @@ -29,14 +27,7 @@ public IActionResult Shop(int? BrandId, int? SectionId) { SectionId = SectionId, BrandId = BrandId, - Products = products.Select(p => new ProductViewModel - { - Id = p.Id, - Name = p.Name, - Order = p.Order, - Price = p.Price, - ImageUrl = p.ImageUrl - }).OrderBy(p => p.Order) + Products = products.ToView().OrderBy(p => p.Order) }); } } diff --git a/WebStore/Controllers/EmployeesController.cs b/WebStore/Controllers/EmployeesController.cs index 94975ef..366f9fb 100644 --- a/WebStore/Controllers/EmployeesController.cs +++ b/WebStore/Controllers/EmployeesController.cs @@ -1,8 +1,9 @@ using System; using System.Linq; using Microsoft.AspNetCore.Mvc; +using WebStore.Domain.Entities; using WebStore.Infrastructure.Interfaces; -using WebStore.Models; +using WebStore.Infrastructure.Mapping; using WebStore.ViewModels; namespace WebStore.Controllers @@ -15,15 +16,7 @@ public class EmployeesController : Controller public EmployeesController(IEmployeesData EmployeesData) => _EmployeesData = EmployeesData; //[Route("All")] - public IActionResult Index() => View(_EmployeesData.Get().Select(employee => new EmployeesViewModel - { - Id = employee.Id, - FirstName = employee.Name, - LastName = employee.Surname, - Patronymic = employee.Patronymic, - Age = employee.Age, - EmployementDate = employee.EmployementDate - })); + public IActionResult Index() => View(_EmployeesData.Get().ToView()); //[Route("User-{id}")] public IActionResult Details(int id) @@ -32,15 +25,7 @@ public IActionResult Details(int id) if (employee is null) return NotFound(); - return View(new EmployeesViewModel - { - Id = employee.Id, - FirstName = employee.Name, - LastName = employee.Surname, - Patronymic = employee.Patronymic, - Age = employee.Age, - EmployementDate = employee.EmployementDate - }); + return View(employee.ToView()); } #region Edit @@ -56,15 +41,7 @@ public IActionResult Edit(int? id) if (employee is null) return NotFound(); - return View(new EmployeesViewModel - { - Id = employee.Id, - FirstName = employee.Name, - LastName = employee.Surname, - Patronymic = employee.Patronymic, - Age = employee.Age, - EmployementDate = employee.EmployementDate - }); + return View(employee.ToView()); } [HttpPost] @@ -82,20 +59,10 @@ public IActionResult Edit(EmployeesViewModel Model) if (!ModelState.IsValid) return View(Model); - var employee = new Employee - { - Id = Model.Id, - Surname = Model.LastName, - Name = Model.FirstName, - Patronymic = Model.Patronymic, - Age = Model.Age, - EmployementDate = Model.EmployementDate - }; - if (Model.Id == 0) - _EmployeesData.Add(employee); + _EmployeesData.Add(Model.FromView()); else - _EmployeesData.Edit(employee); + _EmployeesData.Edit(Model.FromView()); _EmployeesData.SaveChanges(); @@ -115,15 +82,7 @@ public IActionResult Delete(int id) if (employee is null) return NotFound(); - return View(new EmployeesViewModel - { - Id = employee.Id, - FirstName = employee.Name, - LastName = employee.Surname, - Patronymic = employee.Patronymic, - Age = employee.Age, - EmployementDate = employee.EmployementDate - }); + return View(employee.ToView()); } [HttpPost] diff --git a/WebStore/Controllers/HomeController.cs b/WebStore/Controllers/HomeController.cs index 10c6e1f..2182f18 100644 --- a/WebStore/Controllers/HomeController.cs +++ b/WebStore/Controllers/HomeController.cs @@ -20,10 +20,11 @@ public IActionResult Throw(string id) => public IActionResult ContactUs() => View(); - public IActionResult Login() => View(); - public IActionResult ProductDetails() => View(); public IActionResult Error404() => View(); + + [ActionName("Content")] + public IActionResult GetContent(string Id) => Content($"Content-123: {Id}"); } } diff --git a/WebStore/Data/TestData.cs b/WebStore/Data/TestData.cs index 784d67c..99326bd 100644 --- a/WebStore/Data/TestData.cs +++ b/WebStore/Data/TestData.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using WebStore.Domain.Entities; -using WebStore.Models; namespace WebStore.Data { diff --git a/WebStore/Data/WebStoreDBInitializer.cs b/WebStore/Data/WebStoreDBInitializer.cs new file mode 100644 index 0000000..43fc3f7 --- /dev/null +++ b/WebStore/Data/WebStoreDBInitializer.cs @@ -0,0 +1,141 @@ +using System.Linq; +using Microsoft.EntityFrameworkCore; +using WebStore.DAL.Context; + +namespace WebStore.Data +{ + public class WebStoreDBInitializer + { + private readonly WebStoreDB _db; + + public WebStoreDBInitializer(WebStoreDB db) => _db = db; + + public void Initialize() + { + var db = _db.Database; + + //if(db.EnsureDeleted()) + // if(!db.EnsureCreated()) + // throw new InvalidOperationException("Ошибка при создании БД"); + + db.Migrate(); + + InitializeProducts(); + InitializeEmployees(); + } + + private void InitializeProducts() + { + if (_db.Products.Any()) return; + + var db = _db.Database; + using (db.BeginTransaction()) + { + _db.Sections.AddRange(TestData.Sections); + + db.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[ProductSections] ON"); + _db.SaveChanges(); + db.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[ProductSections] OFF"); + + db.CommitTransaction(); + } + + using (db.BeginTransaction()) + { + _db.Brands.AddRange(TestData.Brands); + + db.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[ProductBrands] ON"); + _db.SaveChanges(); + db.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[ProductBrands] OFF"); + + db.CommitTransaction(); + } + + using (db.BeginTransaction()) + { + _db.Products.AddRange(TestData.Products); + + db.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Products] ON"); + _db.SaveChanges(); + db.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Products] OFF"); + + db.CommitTransaction(); + } + + //var products = TestData.Products; + //var sections = TestData.Sections; + //var brands = TestData.Brands; + + //var product_section = products.Join( + // sections, + // p => p.SectionId, + // s => s.Id, + // (product, section) => (product, section)); + + //foreach (var (product, section) in product_section) + //{ + // product.Section = section; + // product.SectionId = 0; + //} + + //var product_brand = products.Join( + // brands, + // p => p.BrandId, + // b => b.Id, + // (product, brand) => (product, brand)); + + //foreach (var (product, brand) in product_brand) + //{ + // product.Brand = brand; + // product.BrandId = null; + //} + + //foreach (var product in products) + // product.Id = 0; + + //var child_sections = sections.Join( + // sections, + // child => child.ParentId, + // parent => parent.Id, + // (child, parent) => (child, parent)); + + //foreach (var (child, parent) in child_sections) + //{ + // child.ParentSection = parent; + // child.ParentId = null; + //} + + //foreach (var section in sections) + // section.Id = 0; + + //foreach (var brand in brands) + // brand.Id = 0; + + + //using (db.BeginTransaction()) + //{ + // _db.Sections.AddRange(sections); + // _db.Brands.AddRange(brands); + // _db.Products.AddRange(products); + // _db.SaveChanges(); + // db.CommitTransaction(); + //} + } + + private void InitializeEmployees() + { + if(_db.Employees.Any()) return; + + using (_db.Database.BeginTransaction()) + { + TestData.Employees.ForEach(employee => employee.Id = 0); + + _db.Employees.AddRange(TestData.Employees); + + _db.SaveChanges(); + + _db.Database.CommitTransaction(); + } + } + } +} diff --git a/WebStore/Infrastructure/Interfaces/IEmployeesData.cs b/WebStore/Infrastructure/Interfaces/IEmployeesData.cs index 8af4026..edf12cd 100644 --- a/WebStore/Infrastructure/Interfaces/IEmployeesData.cs +++ b/WebStore/Infrastructure/Interfaces/IEmployeesData.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using WebStore.Models; +using WebStore.Domain.Entities; namespace WebStore.Infrastructure.Interfaces { diff --git a/WebStore/Infrastructure/Mapping/EmployeeMapper.cs b/WebStore/Infrastructure/Mapping/EmployeeMapper.cs new file mode 100644 index 0000000..0e95c29 --- /dev/null +++ b/WebStore/Infrastructure/Mapping/EmployeeMapper.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Linq; +using WebStore.Domain.Entities; +using WebStore.ViewModels; + +namespace WebStore.Infrastructure.Mapping +{ + public static class EmployeeMapper + { + public static EmployeesViewModel ToView(this Employee employee) => new EmployeesViewModel + { + Id = employee.Id, + FirstName = employee.Name, + LastName = employee.Surname, + Patronymic = employee.Patronymic, + Age = employee.Age, + EmployementDate = employee.EmployementDate + }; + + public static IEnumerable ToView(this IEnumerable employees) => employees.Select(ToView); + + public static Employee FromView(this EmployeesViewModel Model) => new Employee + { + Id = Model.Id, + Surname = Model.LastName, + Name = Model.FirstName, + Patronymic = Model.Patronymic, + Age = Model.Age, + EmployementDate = Model.EmployementDate + }; + } +} diff --git a/WebStore/Infrastructure/Mapping/ProductMapper.cs b/WebStore/Infrastructure/Mapping/ProductMapper.cs new file mode 100644 index 0000000..7063105 --- /dev/null +++ b/WebStore/Infrastructure/Mapping/ProductMapper.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Linq; +using WebStore.Domain.Entities; +using WebStore.ViewModels; + +namespace WebStore.Infrastructure.Mapping +{ + public static class ProductMapper + { + public static ProductViewModel ToView(this Product p) => new ProductViewModel + { + Id = p.Id, + Name = p.Name, + Order = p.Order, + Price = p.Price, + ImageUrl = p.ImageUrl + }; + + public static IEnumerable ToView(this IEnumerable products) => products.Select(ToView); + } +} diff --git a/WebStore/Infrastructure/Middleware/TestMiddleware.cs b/WebStore/Infrastructure/Middleware/TestMiddleware.cs index a8ccfc3..dc0d533 100644 --- a/WebStore/Infrastructure/Middleware/TestMiddleware.cs +++ b/WebStore/Infrastructure/Middleware/TestMiddleware.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; namespace WebStore.Infrastructure.Middleware diff --git a/WebStore/Infrastructure/Services/InMemory/InMemoryEmployeesData.cs b/WebStore/Infrastructure/Services/InMemory/InMemoryEmployeesData.cs new file mode 100644 index 0000000..604c32a --- /dev/null +++ b/WebStore/Infrastructure/Services/InMemory/InMemoryEmployeesData.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using WebStore.Data; +using WebStore.Domain.Entities; +using WebStore.Infrastructure.Interfaces; + +namespace WebStore.Infrastructure.Services.InMemory +{ + public class InMemoryEmployeesData : IEmployeesData + { + private readonly List _Employees = TestData.Employees; + + public IEnumerable Get() => _Employees; + + public Employee GetById(int id) => _Employees.FirstOrDefault(e => e.Id == id); + + public int Add(Employee employee) + { + if(employee is null) + throw new ArgumentNullException(nameof(employee)); + + if (_Employees.Contains(employee)) return employee.Id; + + employee.Id = _Employees.Count == 0 ? 1 : _Employees.Max(e => e.Id) + 1; + _Employees.Add(employee); + return employee.Id; + } + + public void Edit(Employee employee) + { + if (employee is null) + throw new ArgumentNullException(nameof(employee)); + + if(_Employees.Contains(employee)) return; + + var db_employee = GetById(employee.Id); + if(db_employee is null) return; + + db_employee.Name = employee.Name; + db_employee.Surname = employee.Surname; + db_employee.Patronymic = employee.Patronymic; + db_employee.Age = employee.Age; + } + + public bool Delete(int id) => _Employees.RemoveAll(e => e.Id == id) > 0; + + public void SaveChanges() { } + } +} diff --git a/WebStore/Infrastructure/Services/InMemory/InMemoryProductData.cs b/WebStore/Infrastructure/Services/InMemory/InMemoryProductData.cs new file mode 100644 index 0000000..04be29e --- /dev/null +++ b/WebStore/Infrastructure/Services/InMemory/InMemoryProductData.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Linq; +using WebStore.Data; +using WebStore.Domain; +using WebStore.Domain.Entities; +using WebStore.Infrastructure.Interfaces; + +namespace WebStore.Infrastructure.Services.InMemory +{ + public class InMemoryProductData : IProductData + { + public IEnumerable
GetSections() => TestData.Sections; + + public IEnumerable GetBrands() => TestData.Brands; + + public IEnumerable GetProducts(ProductFilter Filter = null) + { + var query = TestData.Products; + + if (Filter?.SectionId != null) + query = query.Where(product => product.SectionId == Filter.SectionId); + + if (Filter?.BrandId != null) + query = query.Where(product => product.BrandId == Filter.BrandId); + + return query; + } + } +} diff --git a/WebStore/Infrastructure/Services/InSQL/SqlEmployeesData.cs b/WebStore/Infrastructure/Services/InSQL/SqlEmployeesData.cs new file mode 100644 index 0000000..1c7cca5 --- /dev/null +++ b/WebStore/Infrastructure/Services/InSQL/SqlEmployeesData.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using WebStore.DAL.Context; +using WebStore.Domain.Entities; +using WebStore.Infrastructure.Interfaces; + +namespace WebStore.Infrastructure.Services.InSQL +{ + public class SqlEmployeesData : IEmployeesData + { + private readonly WebStoreDB _db; + + public SqlEmployeesData(WebStoreDB db) => _db = db; + + public IEnumerable Get() => _db.Employees; + + public Employee GetById(int id) => _db.Employees.Find(id); + + public int Add(Employee employee) + { + if(employee is null) throw new ArgumentNullException(nameof(employee)); + + _db.Add(employee); + //_db.Employees.Add(employee); + + return employee.Id; + } + + public void Edit(Employee employee) + { + if(employee is null) throw new ArgumentNullException(nameof(employee)); + + _db.Update(employee); + //_db.Employees.Update(employee); + } + + public bool Delete(int id) + { + var employee = GetById(id); + if (employee is null) + return false; + _db.Remove(employee); + //_db.Employees.Remove(employee); + return true; + } + + public void SaveChanges() => _db.SaveChanges(); + } +} diff --git a/WebStore/Infrastructure/Services/InSQL/SqlProductData.cs b/WebStore/Infrastructure/Services/InSQL/SqlProductData.cs new file mode 100644 index 0000000..15c0f4f --- /dev/null +++ b/WebStore/Infrastructure/Services/InSQL/SqlProductData.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore; +using WebStore.DAL.Context; +using WebStore.Domain; +using WebStore.Domain.Entities; +using WebStore.Infrastructure.Interfaces; + +namespace WebStore.Infrastructure.Services.InSQL +{ + public class SqlProductData : IProductData + { + private readonly WebStoreDB _db; + + public SqlProductData(WebStoreDB db) => _db = db; + + public IEnumerable
GetSections() => _db.Sections; + + public IEnumerable GetBrands() => _db.Brands; + + public IEnumerable GetProducts(ProductFilter Filter = null) + { + IQueryable query = _db.Products + .Include(product => product.Brand) + .Include(product => product.Section); + + if (Filter?.BrandId != null) + query = query.Where(product => product.BrandId == Filter.BrandId); + + if (Filter?.SectionId != null) + query = query.Where(product => product.SectionId == Filter.SectionId); + + return query/*.ToArray()*/; + } + } +} diff --git a/WebStore/Startup.cs b/WebStore/Startup.cs index 98e3120..f481b6e 100644 --- a/WebStore/Startup.cs +++ b/WebStore/Startup.cs @@ -2,11 +2,16 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using WebStore.DAL.Context; +using WebStore.Data; +using WebStore.Domain.Entities.Identity; using WebStore.Infrastructure.Interfaces; -using WebStore.Infrastructure.Services; +using WebStore.Infrastructure.Services.InSQL; namespace WebStore { @@ -21,39 +26,70 @@ public Startup(IConfiguration Configuration) public void ConfigureServices(IServiceCollection services) { + services.AddDbContext(opt => + opt.UseSqlServer(_Configuration.GetConnectionString("DefaultConnection"))); + services.AddTransient(); + + services.AddIdentity(opt => { }) + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + + services.Configure(opt => + { +#if DEBUG + opt.Password.RequiredLength = 3; + opt.Password.RequireDigit = false; + opt.Password.RequireLowercase = false; + opt.Password.RequireUppercase = false; + opt.Password.RequireNonAlphanumeric = false; + opt.Password.RequiredUniqueChars = 3; + +#endif + opt.User.RequireUniqueEmail = false; + opt.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + + opt.Lockout.AllowedForNewUsers = true; + opt.Lockout.MaxFailedAccessAttempts = 10; + opt.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10); + }); + + services.ConfigureApplicationCookie(opt => + { + opt.Cookie.Name = "WebStore-GB"; + opt.Cookie.HttpOnly = true; + opt.ExpireTimeSpan = TimeSpan.FromDays(10); + + opt.LoginPath = "/Account/Login"; + opt.LogoutPath = "/Account/Logout"; + opt.AccessDeniedPath = "/Account/AccessDenied"; + + opt.SlidingExpiration = true; + }); + services.AddControllersWithViews(opt => { //opt.Filters.Add(); //opt.Conventions.Add(); // / MVC- }).AddRazorRuntimeCompilation(); - services.AddScoped(); - services.AddScoped(); + //services.AddScoped(); + services.AddScoped(); + //services.AddScoped(); + services.AddScoped(); //services.AddTransient(); //services.AddScoped(); //services.AddSingleton(); } - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider services) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WebStoreDBInitializer db) { - //var employees1 = services.GetRequiredService(); - //var employees2 = services.GetRequiredService(); - - //var hash1 = employees1.GetHashCode(); - //var hash2 = employees2.GetHashCode(); - - //using (var scope = services.CreateScope()) - //{ - // var employees3 = scope.ServiceProvider.GetRequiredService(); - // var employees4 = scope.ServiceProvider.GetRequiredService(); - // var hash3 = employees3.GetHashCode(); - // var hash4 = employees3.GetHashCode(); - //} + db.Initialize(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); + app.UseBrowserLink(); } app.UseStaticFiles(); @@ -61,6 +97,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IService app.UseRouting(); + app.UseAuthentication(); + app.UseAuthorization(); + app.UseWelcomePage("/welcome"); //app.Use(async (context, next) => diff --git a/WebStore/ViewModels/Identity/LoginViewModel.cs b/WebStore/ViewModels/Identity/LoginViewModel.cs new file mode 100644 index 0000000..5a3292b --- /dev/null +++ b/WebStore/ViewModels/Identity/LoginViewModel.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Mvc; + +namespace WebStore.ViewModels.Identity +{ + public class LoginViewModel + { + [Required] + [MaxLength(256)] + [Display(Name = "Имя пользователя")] + public string UserName { get; set; } + + [Required] + [DataType(DataType.Password)] + [Display(Name = "Пароль")] + public string Password { get; set; } + + [Display(Name = "Запомнить меня")] + public bool RememberMe { get; set; } + + [HiddenInput(DisplayValue = false)] + public string ReturnUrl { get; set; } + } +} diff --git a/WebStore/ViewModels/Identity/RegisterUserViewModel.cs b/WebStore/ViewModels/Identity/RegisterUserViewModel.cs new file mode 100644 index 0000000..99ad81e --- /dev/null +++ b/WebStore/ViewModels/Identity/RegisterUserViewModel.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; + +namespace WebStore.ViewModels.Identity +{ + public class RegisterUserViewModel + { + [Required, MaxLength(256)] + [Display(Name = "Имя пользователя")] + public string UserName { get; set; } + + [Required] + [Display(Name = "Пароль")] + [DataType(DataType.Password)] + public string Password { get; set; } + + [Required] + [Display(Name = "Подтверждение пароля")] + [DataType(DataType.Password)] + [Compare(nameof(Password))] + public string PasswordConfirm { get; set; } + } +} diff --git a/WebStore/ViewModels/ProductViewModel.cs b/WebStore/ViewModels/ProductViewModel.cs index 4bcb12c..3897e19 100644 --- a/WebStore/ViewModels/ProductViewModel.cs +++ b/WebStore/ViewModels/ProductViewModel.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using WebStore.Domain.Entities.Base.Interfaces; +using WebStore.Domain.Entities.Base.Interfaces; namespace WebStore.ViewModels { diff --git a/WebStore/ViewModels/SectionViewModel.cs b/WebStore/ViewModels/SectionViewModel.cs index bd43d5b..ebfbfc3 100644 --- a/WebStore/ViewModels/SectionViewModel.cs +++ b/WebStore/ViewModels/SectionViewModel.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; using WebStore.Domain.Entities.Base.Interfaces; namespace WebStore.ViewModels diff --git a/WebStore/Views/Account/AccessDenied.cshtml b/WebStore/Views/Account/AccessDenied.cshtml new file mode 100644 index 0000000..9cf1ca1 --- /dev/null +++ b/WebStore/Views/Account/AccessDenied.cshtml @@ -0,0 +1,9 @@ +@{ + ViewData["Title"] = "AccessDenied"; + Layout = "_LayoutSimple"; +} + +
+

В доступе отказано!

+ На главную страницу! +
diff --git a/WebStore/Views/Account/Login.cshtml b/WebStore/Views/Account/Login.cshtml new file mode 100644 index 0000000..bd8ebf8 --- /dev/null +++ b/WebStore/Views/Account/Login.cshtml @@ -0,0 +1,37 @@ +@model WebStore.ViewModels.Identity.LoginViewModel + +@{ + ViewData["Title"] = "Вход в систему"; +} + +
+ +
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/WebStore/Views/Account/Register.cshtml b/WebStore/Views/Account/Register.cshtml new file mode 100644 index 0000000..d398862 --- /dev/null +++ b/WebStore/Views/Account/Register.cshtml @@ -0,0 +1,33 @@ +@model WebStore.ViewModels.Identity.RegisterUserViewModel + +@{ + ViewData["Title"] = "Регистрация нового пользователя"; +} + +
+ +
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/WebStore/Views/Home/Index.cshtml b/WebStore/Views/Home/Index.cshtml index bb4700d..20e98c1 100644 --- a/WebStore/Views/Home/Index.cshtml +++ b/WebStore/Views/Home/Index.cshtml @@ -1,17 +1,11 @@ @using WebStore.Infrastructure.Interfaces +@using WebStore.Infrastructure.Mapping @inject IProductData ProductData @{ var products = ProductData .GetProducts() .Take(6) - .Select(p => new ProductViewModel - { - Id = p.Id, - Name = p.Name, - Order = p.Order, - Price = p.Price, - ImageUrl = p.ImageUrl - }) + .ToView() .OrderBy(p => p.Order); } diff --git a/WebStore/Views/Home/Partial/_CategoryTab.cshtml b/WebStore/Views/Home/Partial/_CategoryTab.cshtml index 38e34cf..83db00b 100644 --- a/WebStore/Views/Home/Partial/_CategoryTab.cshtml +++ b/WebStore/Views/Home/Partial/_CategoryTab.cshtml @@ -18,7 +18,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -31,7 +31,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -44,9 +44,8 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину - @@ -57,9 +56,8 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину - @@ -73,9 +71,8 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину - @@ -86,9 +83,8 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину - @@ -99,7 +95,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -112,7 +108,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -128,7 +124,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -141,7 +137,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -154,7 +150,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -167,7 +163,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -183,7 +179,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -196,7 +192,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -209,7 +205,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -222,7 +218,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -238,7 +234,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -251,7 +247,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -264,7 +260,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину @@ -277,7 +273,7 @@

$56

Easy Polo Black Edition

- Add to cart + В корзину diff --git a/WebStore/Views/Shared/Components/UserInfo/Default.cshtml b/WebStore/Views/Shared/Components/UserInfo/Default.cshtml new file mode 100644 index 0000000..57d8708 --- /dev/null +++ b/WebStore/Views/Shared/Components/UserInfo/Default.cshtml @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/WebStore/Views/Shared/Components/UserInfo/UserInfo.cshtml b/WebStore/Views/Shared/Components/UserInfo/UserInfo.cshtml new file mode 100644 index 0000000..ea15078 --- /dev/null +++ b/WebStore/Views/Shared/Components/UserInfo/UserInfo.cshtml @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/WebStore/Views/Shared/Partial/_FeaturesItems.cshtml b/WebStore/Views/Shared/Partial/_FeaturesItems.cshtml index b79836f..b798c8e 100644 --- a/WebStore/Views/Shared/Partial/_FeaturesItems.cshtml +++ b/WebStore/Views/Shared/Partial/_FeaturesItems.cshtml @@ -34,8 +34,8 @@ diff --git a/WebStore/Views/Shared/Partial/_Header.cshtml b/WebStore/Views/Shared/Partial/_Header.cshtml index 1fc20c6..effe43e 100644 --- a/WebStore/Views/Shared/Partial/_Header.cshtml +++ b/WebStore/Views/Shared/Partial/_Header.cshtml @@ -35,40 +35,9 @@ -
-
- - -
- -
- - -
-
@@ -93,7 +62,7 @@
diff --git a/WebStore/Views/Shared/Partial/_LeftSideBar.cshtml b/WebStore/Views/Shared/Partial/_LeftSideBar.cshtml index bfda139..87e7148 100644 --- a/WebStore/Views/Shared/Partial/_LeftSideBar.cshtml +++ b/WebStore/Views/Shared/Partial/_LeftSideBar.cshtml @@ -1,13 +1,11 @@