From 5ca6ff014278e83a367cc2dbfb0bf66fff5e2856 Mon Sep 17 00:00:00 2001 From: Jitca Beniamin Date: Mon, 18 Sep 2023 22:23:23 +0100 Subject: [PATCH 01/14] adding migrations and new table config --- .../20230910103737_Migrations_13.Designer.cs | 787 ++++++++++++++++++ .../20230910103737_Migrations_13.cs | 38 + .../20230918200125_Migration_14.Designer.cs | 784 +++++++++++++++++ .../Migrations/20230918200125_Migration_14.cs | 32 + .../ApplicationDbContextModelSnapshot.cs | 71 +- .../Persistence/ApplicationDbContext.cs | 5 + .../Persistence/ApplicationDbContextSeed.cs | 40 +- .../CustomClaimConfiguration.cs | 30 + .../Configurations/MusicConfiguration.cs | 2 - .../Services/CustomClaimsService.cs | 44 + .../Services/RoleService.cs | 4 +- 11 files changed, 1801 insertions(+), 36 deletions(-) create mode 100644 BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.Designer.cs create mode 100644 BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.cs create mode 100644 BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.Designer.cs create mode 100644 BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.cs create mode 100644 BlazorShop.Infrastructure/Persistence/Configurations/CustomClaimConfiguration.cs create mode 100644 BlazorShop.Infrastructure/Services/CustomClaimsService.cs diff --git a/BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.Designer.cs b/BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.Designer.cs new file mode 100644 index 00000000..454bc592 --- /dev/null +++ b/BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.Designer.cs @@ -0,0 +1,787 @@ +// +#pragma warning disable CS1591 + +using System; +using BlazorShop.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlazorShop.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230910103737_Migrations_13")] + partial class Migrations_13 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Cart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("ClotheId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Price") + .HasColumnType("decimal(18, 2)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClotheId"); + + b.HasIndex("UserId"); + + b.ToTable("Carts", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Clothe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("ImageName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ImagePath") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .IsRequired() + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Price") + .IsRequired() + .HasColumnType("decimal(18, 2)"); + + b.HasKey("Id"); + + b.ToTable("Clothes", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.CustomClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.Property("ClaimValue") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CustomClaims", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("NormalizedName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AppRoles", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.RoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ClaimValue") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AppRoleClaims", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("NormalizedUserName") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + 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") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AppUsers", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ClaimValue") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AppUserClaims", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AppUserLogins", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserRole", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AppUserRoles", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserToken", b => + { + b.Property("UserId") + .HasColumnType("int"); + + 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("AppUserTokens", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Invoice", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AmountSubTotal") + .HasColumnType("int"); + + b.Property("AmountTotal") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("UserEmail") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Invoices", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Music", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AccessLevel") + .HasColumnType("int"); + + b.Property("Author") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("DateRelease") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("ImageName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ImagePath") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("Musics", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AmountTotal") + .HasMaxLength(50) + .HasColumnType("int"); + + b.Property("LineItems") + .IsRequired() + .HasMaxLength(10000) + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserEmail") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Orders", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Receipt", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ReceiptDate") + .HasColumnType("datetime2"); + + b.Property("ReceiptName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ReceiptUrl") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserEmail") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Receipts", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Subscriber", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CurrentPeriodEnd") + .HasColumnType("datetime2"); + + b.Property("CurrentPeriodStart") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("DateStart") + .HasColumnType("datetime2"); + + b.Property("HostedInvoiceUrl") + .IsRequired() + .HasMaxLength(700) + .HasColumnType("nvarchar(700)"); + + b.Property("Status") + .HasMaxLength(50) + .HasColumnType("int"); + + b.Property("StripeSubscriberSubscriptionId") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("SubscriptionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("SubscriptionId"); + + b.ToTable("Subscribers", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ChargeType") + .IsRequired() + .HasMaxLength(25) + .HasColumnType("nvarchar(25)"); + + b.Property("Currency") + .IsRequired() + .HasMaxLength(25) + .HasColumnType("nvarchar(25)"); + + b.Property("CurrencySymbol") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("ImageName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ImagePath") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Options") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Price") + .HasColumnType("int"); + + b.Property("StripeSubscriptionId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Done") + .HasColumnType("bit"); + + b.Property("ListId") + .HasColumnType("int"); + + b.Property("Note") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Priority") + .HasColumnType("int"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("ListId"); + + b.ToTable("TodoItems", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoList", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("TodoLists", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Cart", b => + { + b.HasOne("BlazorShop.Domain.Entities.Clothe", "Clothe") + .WithMany() + .HasForeignKey("ClotheId"); + + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("Clothe"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.RoleClaim", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.Role", "Role") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserClaim", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserLogin", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserRole", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.Role", "Role") + .WithMany("Users") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserToken", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("UserTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Subscriber", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "Customer") + .WithMany() + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlazorShop.Domain.Entities.Subscription", "Subscription") + .WithMany() + .HasForeignKey("SubscriptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + + b.Navigation("Subscription"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoItem", b => + { + b.HasOne("BlazorShop.Domain.Entities.TodoList", "List") + .WithMany("Items") + .HasForeignKey("ListId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("List"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.Role", b => + { + b.Navigation("Claims"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.User", b => + { + b.Navigation("Claims"); + + b.Navigation("Logins"); + + b.Navigation("Roles"); + + b.Navigation("UserTokens"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoList", b => + { + b.Navigation("Items"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.cs b/BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.cs new file mode 100644 index 00000000..6ed394d8 --- /dev/null +++ b/BlazorShop.Infrastructure/Migrations/20230910103737_Migrations_13.cs @@ -0,0 +1,38 @@ +// +#pragma warning disable CS1591 + +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlazorShop.Infrastructure.Migrations +{ + /// + public partial class Migrations_13 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CustomClaims", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClaimType = table.Column(type: "nvarchar(250)", maxLength: 250, nullable: false), + ClaimValue = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CustomClaims", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CustomClaims"); + } + } +} diff --git a/BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.Designer.cs b/BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.Designer.cs new file mode 100644 index 00000000..2f67a2e7 --- /dev/null +++ b/BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.Designer.cs @@ -0,0 +1,784 @@ +// +#pragma warning disable CS1591 + +using System; +using BlazorShop.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlazorShop.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230918200125_Migration_14")] + partial class Migration_14 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Cart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("ClotheId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Price") + .HasColumnType("decimal(18, 2)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClotheId"); + + b.HasIndex("UserId"); + + b.ToTable("Carts", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Clothe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("ImageName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ImagePath") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .IsRequired() + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Price") + .IsRequired() + .HasColumnType("decimal(18, 2)"); + + b.HasKey("Id"); + + b.ToTable("Clothes", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.CustomClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.Property("ClaimValue") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CustomClaims", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("NormalizedName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AppRoles", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.RoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ClaimValue") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AppRoleClaims", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("NormalizedUserName") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + 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") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AppUsers", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ClaimValue") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AppUserClaims", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AppUserLogins", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserRole", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AppUserRoles", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserToken", b => + { + b.Property("UserId") + .HasColumnType("int"); + + 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("AppUserTokens", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Invoice", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AmountSubTotal") + .HasColumnType("int"); + + b.Property("AmountTotal") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("UserEmail") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Invoices", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Music", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("DateRelease") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("ImageName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ImagePath") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("Musics", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AmountTotal") + .HasMaxLength(50) + .HasColumnType("int"); + + b.Property("LineItems") + .IsRequired() + .HasMaxLength(10000) + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserEmail") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Orders", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Receipt", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ReceiptDate") + .HasColumnType("datetime2"); + + b.Property("ReceiptName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ReceiptUrl") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserEmail") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Receipts", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Subscriber", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CurrentPeriodEnd") + .HasColumnType("datetime2"); + + b.Property("CurrentPeriodStart") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("DateStart") + .HasColumnType("datetime2"); + + b.Property("HostedInvoiceUrl") + .IsRequired() + .HasMaxLength(700) + .HasColumnType("nvarchar(700)"); + + b.Property("Status") + .HasMaxLength(50) + .HasColumnType("int"); + + b.Property("StripeSubscriberSubscriptionId") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("SubscriptionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("SubscriptionId"); + + b.ToTable("Subscribers", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ChargeType") + .IsRequired() + .HasMaxLength(25) + .HasColumnType("nvarchar(25)"); + + b.Property("Currency") + .IsRequired() + .HasMaxLength(25) + .HasColumnType("nvarchar(25)"); + + b.Property("CurrencySymbol") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("ImageName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ImagePath") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Options") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Price") + .HasColumnType("int"); + + b.Property("StripeSubscriptionId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Done") + .HasColumnType("bit"); + + b.Property("ListId") + .HasColumnType("int"); + + b.Property("Note") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Priority") + .HasColumnType("int"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("ListId"); + + b.ToTable("TodoItems", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoList", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("TodoLists", (string)null); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Cart", b => + { + b.HasOne("BlazorShop.Domain.Entities.Clothe", "Clothe") + .WithMany() + .HasForeignKey("ClotheId"); + + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("Clothe"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.RoleClaim", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.Role", "Role") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserClaim", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserLogin", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserRole", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.Role", "Role") + .WithMany("Users") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.UserToken", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "User") + .WithMany("UserTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Subscriber", b => + { + b.HasOne("BlazorShop.Domain.Entities.Identity.User", "Customer") + .WithMany() + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlazorShop.Domain.Entities.Subscription", "Subscription") + .WithMany() + .HasForeignKey("SubscriptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + + b.Navigation("Subscription"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoItem", b => + { + b.HasOne("BlazorShop.Domain.Entities.TodoList", "List") + .WithMany("Items") + .HasForeignKey("ListId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("List"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.Role", b => + { + b.Navigation("Claims"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.User", b => + { + b.Navigation("Claims"); + + b.Navigation("Logins"); + + b.Navigation("Roles"); + + b.Navigation("UserTokens"); + }); + + modelBuilder.Entity("BlazorShop.Domain.Entities.TodoList", b => + { + b.Navigation("Items"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.cs b/BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.cs new file mode 100644 index 00000000..0fed0564 --- /dev/null +++ b/BlazorShop.Infrastructure/Migrations/20230918200125_Migration_14.cs @@ -0,0 +1,32 @@ +// +#pragma warning disable CS1591 + +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlazorShop.Infrastructure.Migrations +{ + /// + public partial class Migration_14 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "AccessLevel", + table: "Musics"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "AccessLevel", + table: "Musics", + type: "int", + nullable: false, + defaultValue: 0); + } + } +} diff --git a/BlazorShop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/BlazorShop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs index 84050ea2..eac4a917 100644 --- a/BlazorShop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BlazorShop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,7 +1,10 @@ -// -#pragma warning disable CS1591 - +// +using System; +using BlazorShop.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable @@ -14,10 +17,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); modelBuilder.Entity("BlazorShop.Domain.Entities.Cart", b => { @@ -25,7 +28,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Amount") .HasColumnType("int"); @@ -39,7 +42,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("nvarchar(200)"); b.Property("Price") - .HasColumnType("decimal(18,2)"); + .HasColumnType("decimal(18, 2)"); b.Property("UserId") .HasColumnType("int"); @@ -59,7 +62,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Amount") .HasColumnType("int"); @@ -90,20 +93,43 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Price") .IsRequired() - .HasColumnType("decimal(18,2)"); + .HasColumnType("decimal(18, 2)"); b.HasKey("Id"); b.ToTable("Clothes", (string)null); }); + modelBuilder.Entity("BlazorShop.Domain.Entities.CustomClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.Property("ClaimValue") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CustomClaims", (string)null); + }); + modelBuilder.Entity("BlazorShop.Domain.Entities.Identity.Role", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ConcurrencyStamp") .IsConcurrencyToken() @@ -134,7 +160,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ClaimType") .IsRequired() @@ -162,7 +188,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("AccessFailedCount") .HasColumnType("int"); @@ -246,7 +272,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ClaimType") .IsRequired() @@ -329,7 +355,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("AmountSubTotal") .HasColumnType("int"); @@ -361,10 +387,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("AccessLevel") - .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Author") .IsRequired() @@ -405,7 +428,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("AmountTotal") .HasMaxLength(50) @@ -440,7 +463,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ReceiptDate") .HasColumnType("datetime2"); @@ -471,7 +494,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("CurrentPeriodEnd") .HasColumnType("datetime2"); @@ -517,7 +540,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ChargeType") .IsRequired() @@ -572,7 +595,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Done") .HasColumnType("bit"); @@ -608,7 +631,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Title") .IsRequired() diff --git a/BlazorShop.Infrastructure/Persistence/ApplicationDbContext.cs b/BlazorShop.Infrastructure/Persistence/ApplicationDbContext.cs index 3b240c6e..0590694b 100644 --- a/BlazorShop.Infrastructure/Persistence/ApplicationDbContext.cs +++ b/BlazorShop.Infrastructure/Persistence/ApplicationDbContext.cs @@ -69,6 +69,9 @@ protected ApplicationDbContext() /// public DbSet TodoLists { get; set; } + /// + public DbSet CustomClaims { get; set; } + /// public override async Task SaveChangesAsync(CancellationToken cancellationToken = default) { @@ -103,6 +106,8 @@ protected override void OnModelCreating(ModelBuilder builder) builder.ApplyConfiguration(new SubscriptionConfiguration()); builder.ApplyConfiguration(new TodoItemConfiguration()); builder.ApplyConfiguration(new TodoListConfiguration()); + + builder.ApplyConfiguration(new CustomClaimConfiguration()); } /// diff --git a/BlazorShop.Infrastructure/Persistence/ApplicationDbContextSeed.cs b/BlazorShop.Infrastructure/Persistence/ApplicationDbContextSeed.cs index e1ce79b1..252ec1ad 100644 --- a/BlazorShop.Infrastructure/Persistence/ApplicationDbContextSeed.cs +++ b/BlazorShop.Infrastructure/Persistence/ApplicationDbContextSeed.cs @@ -9,6 +9,38 @@ namespace BlazorShop.Infrastructure.Persistence /// public static class ApplicationDbContextSeed { + /// + /// Adding the custom claims data when the app is deploy the first time. + /// + /// The instance of to use. + /// A representing the result of the asynchronous operation. + public static async Task SeedCustomClaimsAsync(ApplicationDbContext context) + { + if (!context.CustomClaims.Any()) + { + context.CustomClaims.AddRange(new List + { + new CustomClaim + { + ClaimType = ClaimTypes.Role, + ClaimValue = "BASIC", + }, + new CustomClaim + { + ClaimType = ClaimTypes.Role, + ClaimValue = "PRO", + }, + new CustomClaim + { + ClaimType = ClaimTypes.Role, + ClaimValue = "ENTERPRISE", + }, + }); + + await context.SaveChangesAsync(); + } + } + /// /// Adding the roles data when the app is deploy the first time. /// @@ -229,7 +261,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2020, 12, 25), ImageName = "music-1", ImagePath = "music-1.jpg", - AccessLevel = 1, }); context.Musics.Add(new Music { @@ -239,7 +270,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2022, 1, 15), ImageName = "music-2", ImagePath = "music-2.jpg", - AccessLevel = 1, }); context.Musics.Add(new Music { @@ -249,7 +279,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2019, 8, 30), ImageName = "music-3", ImagePath = "music-3.jpg", - AccessLevel = 2, }); context.Musics.Add(new Music { @@ -259,7 +288,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2011, 11, 11), ImageName = "music-4", ImagePath = "music-4.jpg", - AccessLevel = 2, }); context.Musics.Add(new Music { @@ -269,7 +297,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2022, 1, 19), ImageName = "music-5", ImagePath = "music-5.jpg", - AccessLevel = 2, }); context.Musics.Add(new Music { @@ -279,7 +306,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2015, 5, 15), ImageName = "music-6", ImagePath = "music-6.jpg", - AccessLevel = 3, }); context.Musics.Add(new Music { @@ -289,7 +315,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2013, 9, 15), ImageName = "music-2", ImagePath = "music-2.jpg", - AccessLevel = 3, }); context.Musics.Add(new Music { @@ -299,7 +324,6 @@ public static async Task SeedMusicsDataAsync(ApplicationDbContext context) DateRelease = new DateTime(2019, 5, 15), ImageName = "music-6", ImagePath = "music-6.jpg", - AccessLevel = 3, }); await context.SaveChangesAsync(); diff --git a/BlazorShop.Infrastructure/Persistence/Configurations/CustomClaimConfiguration.cs b/BlazorShop.Infrastructure/Persistence/Configurations/CustomClaimConfiguration.cs new file mode 100644 index 00000000..586bb5bd --- /dev/null +++ b/BlazorShop.Infrastructure/Persistence/Configurations/CustomClaimConfiguration.cs @@ -0,0 +1,30 @@ +// +// Copyright (c) Beniamin Jitca. All rights reserved. +// + +namespace BlazorShop.Infrastructure.Persistence.Configurations +{ + /// + /// The configuration for the entity . + /// + public class CustomClaimConfiguration : IEntityTypeConfiguration + { + /// + /// A method to configure an entity. + /// + /// The builder for configuring the entity metadata. + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("CustomClaims"); + + builder.HasKey(x => x.Id); + + builder.Property(t => t.ClaimType) + .HasMaxLength(250) + .IsRequired(); + builder.Property(t => t.ClaimValue) + .HasMaxLength(50) + .IsRequired(); + } + } +} diff --git a/BlazorShop.Infrastructure/Persistence/Configurations/MusicConfiguration.cs b/BlazorShop.Infrastructure/Persistence/Configurations/MusicConfiguration.cs index 3103b6df..74a195dd 100644 --- a/BlazorShop.Infrastructure/Persistence/Configurations/MusicConfiguration.cs +++ b/BlazorShop.Infrastructure/Persistence/Configurations/MusicConfiguration.cs @@ -35,8 +35,6 @@ public void Configure(EntityTypeBuilder builder) builder.Property(t => t.ImagePath) .HasMaxLength(200) .IsRequired(); - builder.Property(t => t.AccessLevel) - .IsRequired(); } } } diff --git a/BlazorShop.Infrastructure/Services/CustomClaimsService.cs b/BlazorShop.Infrastructure/Services/CustomClaimsService.cs new file mode 100644 index 00000000..8f9dbde4 --- /dev/null +++ b/BlazorShop.Infrastructure/Services/CustomClaimsService.cs @@ -0,0 +1,44 @@ +// +// Copyright (c) Beniamin Jitca. All rights reserved. +// + +namespace BlazorShop.Infrastructure.Services +{ + /// + /// An implementation of . + /// + public class CustomClaimsService : ICustomClaimsService + { + /// + /// Initializes a new instance of the class. + /// + /// The instance of to use. + public CustomClaimsService(UserManager userManager) + { + this.UserManager = userManager; + } + + /// + /// Gets the instance of the to use. + /// + private UserManager UserManager { get; } + + /// + public Task AddUserClaim() + { + throw new NotImplementedException(); + } + + /// + public Task DeleteUserClaim() + { + throw new NotImplementedException(); + } + + /// + public Task UpdateUserClaim() + { + throw new NotImplementedException(); + } + } +} diff --git a/BlazorShop.Infrastructure/Services/RoleService.cs b/BlazorShop.Infrastructure/Services/RoleService.cs index b3420a56..ebf745da 100644 --- a/BlazorShop.Infrastructure/Services/RoleService.cs +++ b/BlazorShop.Infrastructure/Services/RoleService.cs @@ -149,7 +149,7 @@ public RoleResponse GetRoleByNormalizedName(string normalizedName) } /// - public async Task CreateRoleAsync(CreateRoleCommand command) + public async Task CreateRoleAsync(CreateClaimCommand command) { var role = await this.RoleManager.FindByNameAsync(command.Name); if (role != null) @@ -168,7 +168,7 @@ await this.RoleManager.CreateAsync(new Role } /// - public async Task UpdateRoleAsync(UpdateRoleCommand command) + public async Task UpdateRoleAsync(UpdateClaimCommand command) { var existsRole = await this.RoleManager.FindByNameAsync(command.Name); if (existsRole != null) From 50496f9f1b528437f9dd561277330148d26e183d Mon Sep 17 00:00:00 2001 From: Jitca Beniamin Date: Mon, 18 Sep 2023 22:23:32 +0100 Subject: [PATCH 02/14] adding docs --- .../Commands/RoleHandler/CreateRoleCommandHandlerTests.cs | 4 ++-- .../Commands/RoleHandler/DeleteRoleCommandHandlerTests.cs | 4 ++-- .../Commands/RoleHandler/UpdateRoleCommandHandlerTests.cs | 4 ++-- .../Queries/RoleHandler/GetRoleByIdQueryHandlerTests.cs | 4 ++-- .../RoleHandler/GetRoleByNormalizedNameQueryHandlerTests.cs | 4 ++-- .../Queries/RoleHandler/GetRolesForAdminQueryHandlerTests.cs | 4 ++-- .../Handlers/Queries/RoleHandler/GetRolesQueryHandlerTests.cs | 4 ++-- BlazorShop.UnitTests/Controllers/RolesControllerTests.cs | 4 ++-- BlazorShop.UnitTests/Infrastructure/RoleServiceTests.cs | 4 ++-- BlazorShop.UnitTests/WebClient/Auth/AuthStateProviderTests.cs | 2 +- .../WebClient/Auth/AuthenticationServiceTests.cs | 2 +- .../WebClient/Services/AccountServiceTests.cs | 2 +- BlazorShop.UnitTests/WebClient/Services/CartServiceTests.cs | 2 +- BlazorShop.UnitTests/WebClient/Services/ClotheServiceTests.cs | 2 +- BlazorShop.UnitTests/WebClient/Services/MusicServiceTests.cs | 2 +- BlazorShop.UnitTests/WebClient/Services/OrderServiceTests.cs | 2 +- .../WebClient/Services/ReceiptServiceTests.cs | 2 +- BlazorShop.UnitTests/WebClient/Services/RoleServiceTests.cs | 2 +- BlazorShop.UnitTests/WebClient/Services/StripeServiceTests.cs | 2 +- .../WebClient/Services/SubscriberServiceTests.cs | 2 +- .../WebClient/Services/SubscriptionServiceTests.cs | 2 +- .../WebClient/Services/TodoItemServiceTests.cs | 2 +- .../WebClient/Services/TodoListServiceTests.cs | 2 +- BlazorShop.UnitTests/WebClient/Services/UserServiceTests.cs | 2 +- BlazorShop.UnitTests/WorkerService/WorkerServiceTests.cs | 2 +- 25 files changed, 34 insertions(+), 34 deletions(-) diff --git a/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/CreateRoleCommandHandlerTests.cs b/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/CreateRoleCommandHandlerTests.cs index 9a38e31e..d236cbd7 100644 --- a/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/CreateRoleCommandHandlerTests.cs +++ b/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/CreateRoleCommandHandlerTests.cs @@ -47,7 +47,7 @@ public CreateRoleCommandHandlerTests() private ILogger Logger { get; } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] @@ -57,7 +57,7 @@ public async Task Handle() } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] diff --git a/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/DeleteRoleCommandHandlerTests.cs b/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/DeleteRoleCommandHandlerTests.cs index a87b5f63..52819e76 100644 --- a/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/DeleteRoleCommandHandlerTests.cs +++ b/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/DeleteRoleCommandHandlerTests.cs @@ -47,7 +47,7 @@ public DeleteRoleCommandHandlerTests() private ILogger Logger { get; } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] @@ -57,7 +57,7 @@ public async Task Handle() } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] diff --git a/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/UpdateRoleCommandHandlerTests.cs b/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/UpdateRoleCommandHandlerTests.cs index e727f389..cfe07c51 100644 --- a/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/UpdateRoleCommandHandlerTests.cs +++ b/BlazorShop.UnitTests/Application/Handlers/Commands/RoleHandler/UpdateRoleCommandHandlerTests.cs @@ -47,7 +47,7 @@ public UpdateRoleCommandHandlerTests() private ILogger Logger { get; } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] @@ -57,7 +57,7 @@ public async Task Handle() } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] diff --git a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByIdQueryHandlerTests.cs b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByIdQueryHandlerTests.cs index 710b8d28..f7351edd 100644 --- a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByIdQueryHandlerTests.cs +++ b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByIdQueryHandlerTests.cs @@ -50,7 +50,7 @@ public GetRoleByIdQueryHandlerTests() private IMapper Mapper { get; } = Mock.Of(); /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] @@ -60,7 +60,7 @@ public async Task Handle() } /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] diff --git a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByNormalizedNameQueryHandlerTests.cs b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByNormalizedNameQueryHandlerTests.cs index 628ac720..0782efd0 100644 --- a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByNormalizedNameQueryHandlerTests.cs +++ b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRoleByNormalizedNameQueryHandlerTests.cs @@ -50,7 +50,7 @@ public GetRoleByNormalizedNameQueryHandlerTests() private IMapper Mapper { get; } = Mock.Of(); /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] @@ -60,7 +60,7 @@ public async Task Handle() } /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] diff --git a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesForAdminQueryHandlerTests.cs b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesForAdminQueryHandlerTests.cs index ada51aef..ec06e5c3 100644 --- a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesForAdminQueryHandlerTests.cs +++ b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesForAdminQueryHandlerTests.cs @@ -50,7 +50,7 @@ public GetRolesForAdminQueryHandlerTests() private IMapper Mapper { get; } = Mock.Of(); /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] @@ -60,7 +60,7 @@ public async Task Handle() } /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] diff --git a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesQueryHandlerTests.cs b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesQueryHandlerTests.cs index 9ea87a7c..63f6478f 100644 --- a/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesQueryHandlerTests.cs +++ b/BlazorShop.UnitTests/Application/Handlers/Queries/RoleHandler/GetRolesQueryHandlerTests.cs @@ -50,7 +50,7 @@ public GetRolesQueryHandlerTests() private IMapper Mapper { get; } = Mock.Of(); /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] @@ -60,7 +60,7 @@ public async Task Handle() } /// - /// A test for method. + /// A test for method. /// /// A async result. [Fact] diff --git a/BlazorShop.UnitTests/Controllers/RolesControllerTests.cs b/BlazorShop.UnitTests/Controllers/RolesControllerTests.cs index 0db3fd92..2d6766b0 100644 --- a/BlazorShop.UnitTests/Controllers/RolesControllerTests.cs +++ b/BlazorShop.UnitTests/Controllers/RolesControllerTests.cs @@ -28,7 +28,7 @@ public RolesControllerTests() private IMediator Mediator { get; } = Mock.Of(); /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] @@ -38,7 +38,7 @@ public async Task CreateRole() } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] diff --git a/BlazorShop.UnitTests/Infrastructure/RoleServiceTests.cs b/BlazorShop.UnitTests/Infrastructure/RoleServiceTests.cs index 836ee77d..9b0999aa 100644 --- a/BlazorShop.UnitTests/Infrastructure/RoleServiceTests.cs +++ b/BlazorShop.UnitTests/Infrastructure/RoleServiceTests.cs @@ -131,7 +131,7 @@ public async Task GetRoleByNormalizedName() } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] @@ -141,7 +141,7 @@ public async Task CreateRoleAsync() } /// - /// A test for method. + /// A test for method. /// /// A representing the result of the asynchronous operation. [Fact] diff --git a/BlazorShop.UnitTests/WebClient/Auth/AuthStateProviderTests.cs b/BlazorShop.UnitTests/WebClient/Auth/AuthStateProviderTests.cs index a69c899d..20760d5f 100644 --- a/BlazorShop.UnitTests/WebClient/Auth/AuthStateProviderTests.cs +++ b/BlazorShop.UnitTests/WebClient/Auth/AuthStateProviderTests.cs @@ -28,7 +28,7 @@ public AuthStateProviderTests() private AuthStateProvider AuthStateProvider { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } diff --git a/BlazorShop.UnitTests/WebClient/Auth/AuthenticationServiceTests.cs b/BlazorShop.UnitTests/WebClient/Auth/AuthenticationServiceTests.cs index cfde178c..3b144598 100644 --- a/BlazorShop.UnitTests/WebClient/Auth/AuthenticationServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Auth/AuthenticationServiceTests.cs @@ -27,7 +27,7 @@ public AuthenticationServiceTests() private AuthenticationService AuthenticationService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } diff --git a/BlazorShop.UnitTests/WebClient/Services/AccountServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/AccountServiceTests.cs index fa71f631..d192639e 100644 --- a/BlazorShop.UnitTests/WebClient/Services/AccountServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/AccountServiceTests.cs @@ -27,7 +27,7 @@ public AccountServiceTests() private AccountService AccountService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/CartServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/CartServiceTests.cs index d407642c..76917205 100644 --- a/BlazorShop.UnitTests/WebClient/Services/CartServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/CartServiceTests.cs @@ -27,7 +27,7 @@ public CartServiceTests() private CartService CartService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/ClotheServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/ClotheServiceTests.cs index 07b91f53..71adb8a7 100644 --- a/BlazorShop.UnitTests/WebClient/Services/ClotheServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/ClotheServiceTests.cs @@ -27,7 +27,7 @@ public ClotheServiceTests() private ClotheService ClotheService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/MusicServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/MusicServiceTests.cs index 45d5a6ed..70fb5bfa 100644 --- a/BlazorShop.UnitTests/WebClient/Services/MusicServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/MusicServiceTests.cs @@ -27,7 +27,7 @@ public MusicServiceTests() private MusicService MusicService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/OrderServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/OrderServiceTests.cs index 1257dd0e..0faf1f80 100644 --- a/BlazorShop.UnitTests/WebClient/Services/OrderServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/OrderServiceTests.cs @@ -27,7 +27,7 @@ public OrderServiceTests() private OrderService OrderService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/ReceiptServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/ReceiptServiceTests.cs index 77afaf4d..0fc6870e 100644 --- a/BlazorShop.UnitTests/WebClient/Services/ReceiptServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/ReceiptServiceTests.cs @@ -27,7 +27,7 @@ public ReceiptServiceTests() private ReceiptService ReceiptService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/RoleServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/RoleServiceTests.cs index dbef8aba..91af41dd 100644 --- a/BlazorShop.UnitTests/WebClient/Services/RoleServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/RoleServiceTests.cs @@ -27,7 +27,7 @@ public RoleServiceTests() private RoleService RoleService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/StripeServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/StripeServiceTests.cs index 33e28ff4..cea46129 100644 --- a/BlazorShop.UnitTests/WebClient/Services/StripeServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/StripeServiceTests.cs @@ -27,7 +27,7 @@ public StripeServiceTests() private StripeService StripeService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/SubscriberServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/SubscriberServiceTests.cs index fac6c20e..1efef287 100644 --- a/BlazorShop.UnitTests/WebClient/Services/SubscriberServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/SubscriberServiceTests.cs @@ -27,7 +27,7 @@ public SubscriberServiceTests() private SubscriberService SubscriberService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/SubscriptionServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/SubscriptionServiceTests.cs index ac77b30f..4d7d1a1d 100644 --- a/BlazorShop.UnitTests/WebClient/Services/SubscriptionServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/SubscriptionServiceTests.cs @@ -27,7 +27,7 @@ public SubscriptionServiceTests() private SubscriptionService SubscriptionService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/TodoItemServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/TodoItemServiceTests.cs index dc1ef4ec..13d22762 100644 --- a/BlazorShop.UnitTests/WebClient/Services/TodoItemServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/TodoItemServiceTests.cs @@ -27,7 +27,7 @@ public TodoItemServiceTests() private TodoItemService TodoItemService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/TodoListServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/TodoListServiceTests.cs index 504b1bb3..9d3f0951 100644 --- a/BlazorShop.UnitTests/WebClient/Services/TodoListServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/TodoListServiceTests.cs @@ -27,7 +27,7 @@ public TodoListServiceTests() private TodoListService TodoListService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WebClient/Services/UserServiceTests.cs b/BlazorShop.UnitTests/WebClient/Services/UserServiceTests.cs index 9a219ac0..c5e09c69 100644 --- a/BlazorShop.UnitTests/WebClient/Services/UserServiceTests.cs +++ b/BlazorShop.UnitTests/WebClient/Services/UserServiceTests.cs @@ -27,7 +27,7 @@ public UserServiceTests() private UserService UserService { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); diff --git a/BlazorShop.UnitTests/WorkerService/WorkerServiceTests.cs b/BlazorShop.UnitTests/WorkerService/WorkerServiceTests.cs index a9adfc20..88c805c5 100644 --- a/BlazorShop.UnitTests/WorkerService/WorkerServiceTests.cs +++ b/BlazorShop.UnitTests/WorkerService/WorkerServiceTests.cs @@ -36,7 +36,7 @@ public WorkerServiceTests() private IServiceScopeFactory ServiceScopeFactory { get; } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } = Mock.Of(); From 2411c5a88ffb604bc681e60ff66603ead25c05f0 Mon Sep 17 00:00:00 2001 From: Jitca Beniamin Date: Mon, 18 Sep 2023 22:23:44 +0100 Subject: [PATCH 03/14] creating the web client for claims stuff --- .../Auth/AuthStateProvider.cs | 4 +- .../Auth/AuthenticationService.cs | 4 +- .../Interfaces/IClaimService.cs | 46 +++++ .../Pages/Admin/Claims/AddEditClaim.razor | 105 ++++++++++ .../Pages/Admin/Claims/Claims.razor | 185 ++++++++++++++++++ .../Pages/Admin/Musics/AddEditMusic.razor | 8 - .../Pages/Admin/Roles/Roles.razor | 4 - BlazorShop.WebClient/Pages/Musics/Index.razor | 2 +- .../Services/AccountService.cs | 4 +- BlazorShop.WebClient/Services/CartService.cs | 4 +- BlazorShop.WebClient/Services/ClaimService.cs | 142 ++++++++++++++ .../Services/ClotheService.cs | 4 +- BlazorShop.WebClient/Services/MusicService.cs | 4 +- BlazorShop.WebClient/Services/OrderService.cs | 4 +- .../Services/ReceiptService.cs | 4 +- BlazorShop.WebClient/Services/RoleService.cs | 6 +- .../Services/StripeService.cs | 4 +- .../Services/SubscriberService.cs | 4 +- .../Services/SubscriptionService.cs | 4 +- .../Services/TodoItemService.cs | 4 +- .../Services/TodoListService.cs | 4 +- BlazorShop.WebClient/Services/UserService.cs | 4 +- BlazorShop.WebClient/Shared/NavMenu.razor | 5 + 23 files changed, 515 insertions(+), 44 deletions(-) create mode 100644 BlazorShop.WebClient/Interfaces/IClaimService.cs create mode 100644 BlazorShop.WebClient/Pages/Admin/Claims/AddEditClaim.razor create mode 100644 BlazorShop.WebClient/Pages/Admin/Claims/Claims.razor create mode 100644 BlazorShop.WebClient/Services/ClaimService.cs diff --git a/BlazorShop.WebClient/Auth/AuthStateProvider.cs b/BlazorShop.WebClient/Auth/AuthStateProvider.cs index abf49fd2..c96be8d4 100644 --- a/BlazorShop.WebClient/Auth/AuthStateProvider.cs +++ b/BlazorShop.WebClient/Auth/AuthStateProvider.cs @@ -12,7 +12,7 @@ public class AuthStateProvider : AuthenticationStateProvider /// /// Initializes a new instance of the class. /// - /// The instance of the to use. + /// The instance of the to use. /// The instance of the to use. /// The instance of the to use. public AuthStateProvider(HttpClient httpClient, ILocalStorageService localStorage, NavigationManager navMagager) @@ -24,7 +24,7 @@ public AuthStateProvider(HttpClient httpClient, ILocalStorageService localStorag } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } diff --git a/BlazorShop.WebClient/Auth/AuthenticationService.cs b/BlazorShop.WebClient/Auth/AuthenticationService.cs index 81a719ae..81ebf33b 100644 --- a/BlazorShop.WebClient/Auth/AuthenticationService.cs +++ b/BlazorShop.WebClient/Auth/AuthenticationService.cs @@ -12,7 +12,7 @@ public class AuthenticationService : IAuthenticationService /// /// Initializes a new instance of the class. /// - /// The instance of the to use. + /// The instance of the to use. /// The instance of the to use. /// The instance of the to use. /// The instance of the to use. @@ -29,7 +29,7 @@ public AuthenticationService( } /// - /// Gets the instance of the to use. + /// Gets the instance of the to use. /// private HttpClient HttpClient { get; } diff --git a/BlazorShop.WebClient/Interfaces/IClaimService.cs b/BlazorShop.WebClient/Interfaces/IClaimService.cs new file mode 100644 index 00000000..a3358c02 --- /dev/null +++ b/BlazorShop.WebClient/Interfaces/IClaimService.cs @@ -0,0 +1,46 @@ +// +// Copyright (c) Beniamin Jitca. All rights reserved. +// + +namespace BlazorShop.WebClient.Interfaces +{ + /// + /// The service to interact with the claim. + /// + public interface IClaimService + { + /// + /// Get the Claims. + /// + /// A representing the result of the asynchronous operation. + Task> GetClaims(); + + /// + /// Get a Claim. + /// + /// The id. + /// A representing the result of the asynchronous operation. + Task GetClaim(int id); + + /// + /// Save a Claim. + /// + /// The Claim. + /// A representing the result of the asynchronous operation. + Task AddClaim(ClaimResponse claim); + + /// + /// Update a Claim. + /// + /// The Claim. + /// A representing the result of the asynchronous operation. + Task UpdateClaim(ClaimResponse claim); + + /// + /// Delete a Claim. + /// + /// The id. + /// A representing the result of the asynchronous operation. + Task DeleteClaim(int id); + } +} diff --git a/BlazorShop.WebClient/Pages/Admin/Claims/AddEditClaim.razor b/BlazorShop.WebClient/Pages/Admin/Claims/AddEditClaim.razor new file mode 100644 index 00000000..77b4e37c --- /dev/null +++ b/BlazorShop.WebClient/Pages/Admin/Claims/AddEditClaim.razor @@ -0,0 +1,105 @@ +@* + + Copyright (c) Beniamin Jitca. All rights reserved. + +*@ + +@page "/admin/claims/add" +@page "/admin/claims/edit/{Id:int}" + +@attribute [Authorize(Policy = StringRoleResources.Admin)] + +@inject IClaimService ClaimService +@inject NavigationManager NavManager +@inject HttpInterceptorService Interceptor + +

@Title Claim

+
+ + + + +
+
+ +
+
+
+
+ +
+
+ +
+ + Save + + + Cancel + +
+
+ +@code { + [Parameter] + public int Id { get; set; } + protected string Title = "Add"; + + public ClaimResponse claim = new(); + + public void Dispose() => Interceptor.DisposeEvent(); + + /// + /// Initialize the component on load. + /// + protected override void OnInitialized() + { + Interceptor.RegisterEvent(); + } + + /// + /// Initialize the component using the parameter. + /// + protected override async Task OnParametersSetAsync() + { + if (Id != 0) + { + Title = "Edit"; + claim = await ClaimService.GetClaim(Id); + } + } + + /// + /// Save the Claim. + /// + protected async Task SaveClaim() + { + RequestResponse result = new(); + if (claim.Id != 0) + { + result = await ClaimService.UpdateClaim(claim); + } + else + { + result = await ClaimService.AddClaim(claim); + } + if (result.Successful) + { + Cancel(); + } + } + + /// + /// Cancel. + /// + public void Cancel() + { + NavManager.NavigateTo("/admin/claims"); + } +} diff --git a/BlazorShop.WebClient/Pages/Admin/Claims/Claims.razor b/BlazorShop.WebClient/Pages/Admin/Claims/Claims.razor new file mode 100644 index 00000000..2b6dd793 --- /dev/null +++ b/BlazorShop.WebClient/Pages/Admin/Claims/Claims.razor @@ -0,0 +1,185 @@ +@* + + Copyright (c) Beniamin Jitca. All rights reserved. + +*@ + +@page "/admin/claims" + +@attribute [Authorize(Policy = StringRoleResources.Admin)] + +@inject IClaimService ClaimService +@inject NavigationManager NavManager +@inject HttpInterceptorService Interceptor + +

Claims List

+ +
+
+ Add Claim +
+
+ +@if (claimsList is null) +{ +
+

Loading the data...

+
+} +else +{ + @if (claimsList.Count > 0) + { + + + Id + Value + Type + Actions + + + + @String.Format("{0:d}", @context.Id) + @context.Value + @context.Type + + + Edit + + + Delete + + + + + + @if (showModal) + { + + } + } + else + { +
+

No record found

+
+ } +} + +@code { + bool showModal = false; + + void ModalShow() => showModal = true; + void ModalCancel() => showModal = false; + void ModalOk() => showModal = false; + + protected ClaimResponse claim = new(); + protected string searchString { get; set; } = string.Empty; + + protected List claimsList { get; set; } + protected List searchClaimsData { get; set; } + + public void Dispose() => Interceptor.DisposeEvent(); + + /// + /// Initialize the component on load. + /// + protected override async Task OnInitializedAsync() + { + Interceptor.RegisterEvent(); + await GetClaims(); + } + + /// + /// Get the admin Claims. + /// + protected async Task GetClaims() + { + claimsList = await ClaimService.GetClaims(); + searchClaimsData = claimsList; + } + + /// + /// Filter the Claims. + /// + protected void FilterClaims() + { + if (!string.IsNullOrEmpty(searchString)) + { + claimsList = searchClaimsData.Where(x => x.Value.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) != -1).ToList(); + } + else + { + claimsList = searchClaimsData; + } + } + + /// + /// Confirm the delete operation. + /// + protected void DeleteConfirm(int Id) + { + claim = claimsList.FirstOrDefault(x => x.Id == Id); + } + + /// + /// Delete the Claim. + /// + protected async Task DeleteClaim(int Id) + { + await ClaimService.DeleteClaim(Id); + await GetClaims(); + } + + /// + /// Reset the search filter. + /// + public void ResetSearch() + { + searchString = string.Empty; + claimsList = searchClaimsData; + } + + /// + /// Navigate. + /// + private void NavigateToPage(int id) + { + NavManager.NavigateTo($"admin/claims/edit/{id}"); + } +} + + diff --git a/BlazorShop.WebClient/Pages/Admin/Musics/AddEditMusic.razor b/BlazorShop.WebClient/Pages/Admin/Musics/AddEditMusic.razor index 8f00407b..50813a94 100644 --- a/BlazorShop.WebClient/Pages/Admin/Musics/AddEditMusic.razor +++ b/BlazorShop.WebClient/Pages/Admin/Musics/AddEditMusic.razor @@ -64,14 +64,6 @@ Variant="Variant.Outlined"> -
-
- -
-
diff --git a/BlazorShop.WebClient/Pages/Admin/Roles/Roles.razor b/BlazorShop.WebClient/Pages/Admin/Roles/Roles.razor index db18b76f..472e3247 100644 --- a/BlazorShop.WebClient/Pages/Admin/Roles/Roles.razor +++ b/BlazorShop.WebClient/Pages/Admin/Roles/Roles.razor @@ -44,10 +44,6 @@ else @context.Name @context.NormalizedName - Edit - Edit diff --git a/BlazorShop.WebClient/Pages/Musics/Index.razor b/BlazorShop.WebClient/Pages/Musics/Index.razor index 1bd8b42e..1896683b 100644 --- a/BlazorShop.WebClient/Pages/Musics/Index.razor +++ b/BlazorShop.WebClient/Pages/Musics/Index.razor @@ -80,7 +80,7 @@ else
- @if (MembershipAccess !=0 && MembershipAccess >= item.AccessLevel) + @if (MembershipAccess !=0 && MembershipAccess >= 1)//"TO DO") {
+
- @foreach (var role in roles)