diff --git a/Exam.StockManagement.API/Data/ProductSeedData.cs b/Exam.StockManagement.API/Data/ProductSeedData.cs new file mode 100644 index 0000000..3315775 --- /dev/null +++ b/Exam.StockManagement.API/Data/ProductSeedData.cs @@ -0,0 +1,36 @@ +using Exam.StockManagement.Domain.Entities.Models; +using Exam.StockManagement.Infrastructure.Persistance; + +namespace Exam.StockManagement.API.Data +{ + public static class ProductSeedData + { + public static async Task InitiliazeDataAsync(this IServiceProvider serviceProvider) + { + var db = serviceProvider.GetRequiredService(); + if (!db.Products.Any()) + { + List transports = [ + new Product + { + ProductName = "Asus TUF Gaming A17", + ProductDescription = "AMD Ryzen™ 7 6800H", + ProductPrice = 1200, + ProductPicture = @"\images\51ZOFgc-4yL._AC_UF894,1000_QL80_.jpg", + CreatedAt = DateTime.UtcNow, + }, + new Product + { + ProductName = "Lenovo Legion 5 Pro", + ProductDescription = "16ith6 i7-11800H 16/512GB SSD RTX3050-4GB 16", + ProductPrice = 20, + ProductPicture = @"\images\", + CreatedAt = DateTime.UtcNow, + } + ]; + db.Products.AddRange(transports); + await db.SaveChangesAsync(); + } + } + } +} diff --git a/Exam.StockManagement.API/Program.cs b/Exam.StockManagement.API/Program.cs index 10508c3..b742cb4 100644 --- a/Exam.StockManagement.API/Program.cs +++ b/Exam.StockManagement.API/Program.cs @@ -76,6 +76,7 @@ public static void Main(string[] args) app.UseSwaggerUI(); } + AsyncServiceScope scope = app.Services.CreateAsyncScope(); app.UseStaticFiles(); app.UseHttpsRedirection(); diff --git a/Exam.StockManagement.API/wwwroot/images/51ZOFgc-4yL._AC_UF894,1000_QL80_.jpg b/Exam.StockManagement.API/wwwroot/images/51ZOFgc-4yL._AC_UF894,1000_QL80_.jpg new file mode 100644 index 0000000..943b614 Binary files /dev/null and b/Exam.StockManagement.API/wwwroot/images/51ZOFgc-4yL._AC_UF894,1000_QL80_.jpg differ diff --git a/Exam.StockManagement.API/wwwroot/images/8a85a980-f250-4412-9532-6e5413e8cec6_myLogo.jpg b/Exam.StockManagement.API/wwwroot/images/8a85a980-f250-4412-9532-6e5413e8cec6_myLogo.jpg new file mode 100644 index 0000000..77db8a6 Binary files /dev/null and b/Exam.StockManagement.API/wwwroot/images/8a85a980-f250-4412-9532-6e5413e8cec6_myLogo.jpg differ diff --git a/Exam.StockManagement.API/wwwroot/images/db4c7987-1e16-453c-a706-76d72476434a_myLogo.jpg b/Exam.StockManagement.API/wwwroot/images/db4c7987-1e16-453c-a706-76d72476434a_myLogo.jpg new file mode 100644 index 0000000..77db8a6 Binary files /dev/null and b/Exam.StockManagement.API/wwwroot/images/db4c7987-1e16-453c-a706-76d72476434a_myLogo.jpg differ diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240305051228_update1.Designer.cs b/Exam.StockManagement.Infrastructure/Migrations/20240305051228_update1.Designer.cs new file mode 100644 index 0000000..e9cfa46 --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240305051228_update1.Designer.cs @@ -0,0 +1,136 @@ +// +using System; +using Exam.StockManagement.Infrastructure.Persistance; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + [DbContext(typeof(StockManagementDbContext))] + [Migration("20240305051228_update1")] + partial class update1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Category", b => + { + b.Property("CategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CategoryId")); + + b.Property("CategoryName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.HasKey("CategoryId"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ProductDescription") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ProductName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ProductPicture") + .HasColumnType("text"); + + b.Property("ProductPrice") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Salt") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.HasOne("Exam.StockManagement.Domain.Entities.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240305051228_update1.cs b/Exam.StockManagement.Infrastructure/Migrations/20240305051228_update1.cs new file mode 100644 index 0000000..2e91625 --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240305051228_update1.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + /// + public partial class update1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ProductName", + table: "Products", + type: "character varying(100)", + maxLength: 100, + nullable: false, + oldClrType: typeof(string), + oldType: "character varying(30)", + oldMaxLength: 30); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ProductName", + table: "Products", + type: "character varying(30)", + maxLength: 30, + nullable: false, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100); + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240305070248_less.Designer.cs b/Exam.StockManagement.Infrastructure/Migrations/20240305070248_less.Designer.cs new file mode 100644 index 0000000..e68fd63 --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240305070248_less.Designer.cs @@ -0,0 +1,136 @@ +// +using System; +using Exam.StockManagement.Infrastructure.Persistance; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + [DbContext(typeof(StockManagementDbContext))] + [Migration("20240305070248_less")] + partial class less + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Category", b => + { + b.Property("CategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CategoryId")); + + b.Property("CategoryName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.HasKey("CategoryId"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ProductDescription") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ProductName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ProductPicture") + .HasColumnType("text"); + + b.Property("ProductPrice") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Salt") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.HasOne("Exam.StockManagement.Domain.Entities.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240305070248_less.cs b/Exam.StockManagement.Infrastructure/Migrations/20240305070248_less.cs new file mode 100644 index 0000000..4ee0eaf --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240305070248_less.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + /// + public partial class less : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs b/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs index 12c2a0e..c51f102 100644 --- a/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs +++ b/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs @@ -18,6 +18,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -60,8 +63,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("ProductName") .IsRequired() - .HasMaxLength(30) - .HasColumnType("character varying(30)"); + .HasMaxLength(100) + .HasColumnType("character varying(100)"); b.Property("ProductPicture") .HasColumnType("text"); diff --git a/Exam.StockManagement.Infrastructure/Persistance/Configuration/ProductConfig.cs b/Exam.StockManagement.Infrastructure/Persistance/Configuration/ProductConfig.cs index c62ec12..d9cbf74 100644 --- a/Exam.StockManagement.Infrastructure/Persistance/Configuration/ProductConfig.cs +++ b/Exam.StockManagement.Infrastructure/Persistance/Configuration/ProductConfig.cs @@ -9,7 +9,7 @@ public class ProductConfig : IEntityTypeConfiguration public void Configure(EntityTypeBuilder builder) { builder.Property(x => x.ProductName) - .HasMaxLength(30); + .HasMaxLength(100); builder.Property(x => x.ProductDescription) .HasMaxLength(100);