first commit

This commit is contained in:
2026-04-16 21:05:21 +04:30
commit 49591985ac
283 changed files with 12716 additions and 0 deletions
@@ -0,0 +1,10 @@
using System.Reflection;
using Vizhvizh.Shop.Application;
namespace Vizhvizh.Shop.Infrastructure.Configuration;
internal static class Assemblies
{
public static Assembly Application = typeof(IShopModule).Assembly;
public static Assembly Infrastructure = typeof(ShopStartup).Assembly;
}
@@ -0,0 +1,52 @@
using Microsoft.Extensions.DependencyInjection;
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.BuildingBlocks.Application.Configuration.Query;
using Vizhvizh.BuildingBlocks.Application.Contract;
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.BuildingBlocks.Domain.Contract;
using Vizhvizh.BuildingBlocks.Infrastructure;
namespace Vizhvizh.Shop.Infrastructure.Configuration;
public class Executor : IExecutor
{
private readonly IServiceProvider _serviceProvider;
public Executor(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public async Task Execute(ICommand command, CancellationToken cancellationToken)
{
var handlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType());
var handler = _serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicCommand = command;
await dynamicHandler.Handle(dynamicCommand, cancellationToken);
}
public async Task<TResult> Execute<TResult>(ICommand<TResult> command, CancellationToken cancellationToken)
{
var handlerType = typeof(ICommandHandler<,>).MakeGenericType(command.GetType(),typeof(TResult));
var handler = _serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicCommand = command;
return await dynamicHandler.Handle(dynamicCommand, cancellationToken);
}
public async Task<TResult> Execute<TResult>(IQuery<TResult> query, CancellationToken cancellationToken)
{
var handlerType = typeof(IQueryHandler<,>).MakeGenericType(query.GetType(), typeof(TResult));
var handler = _serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicQuery = query;
return await dynamicHandler.Handle(dynamicQuery, cancellationToken);
}
public async Task Execute(IDomainEvent notification, CancellationToken cancellationToken = default)
{
var handlerType = typeof(INotificationHandler<>).MakeGenericType(notification.GetType());
var handler = _serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicNotification = notification;
await dynamicHandler.Handle(dynamicNotification, cancellationToken);
}
}
@@ -0,0 +1,29 @@
using Vizhvizh.Shop.Application;
using Vizhvizh.BuildingBlocks.Application.Contract;
using Vizhvizh.BuildingBlocks.Domain.Contract;
using Vizhvizh.BuildingBlocks.Infrastructure;
namespace Vizhvizh.Shop.Infrastructure.Configuration;
internal class ShopModule : IShopModule
{
private readonly IExecutor _executor;
public ShopModule(IExecutor executor)
{
_executor = executor;
}
public async Task<TResult> ExecuteCommandAsync<TResult>(ICommand<TResult> command, CancellationToken cancellationToken)
{
return await _executor.Execute(command, cancellationToken);
}
public async Task ExecuteCommandAsync(ICommand command, CancellationToken cancellationToken)
{
await _executor.Execute(command, cancellationToken);
}
public async Task<TResult> ExecuteQueryAsync<TResult>(IQuery<TResult> query, CancellationToken cancellationToken)
{
return await _executor.Execute(query, cancellationToken);
}
}
@@ -0,0 +1,47 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Products.Entities;
using Vizhvizh.Shop.Domain.Products.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class CategoryConfiguration : IEntityTypeConfiguration<Category>
{
public void Configure(EntityTypeBuilder<Category> builder)
{
builder.ToTable("Categories", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.CategoryId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.Title)
.HasField("_title")
.IsRequired();
builder.Property(x => x.Description)
.IsRequired(false)
.HasField("_description");
builder.Property(x => x.ParentId)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.CategoryId(x))
.IsRequired(false)
.HasField("_parentId");
builder.OwnsOne(x => x.Image, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(CategoryImage.Limit)
.HasColumnName("Image");
});
builder.Property(x => x.Path)
.HasField("_path")
.IsRequired()
.HasConversion(x => x.Value, x => Domain.Products.ValuesObjects.CategoryPath.CreateNew(x))
.HasColumnType("HIERARCHYID");
builder.Metadata.FindNavigation(nameof(Category.Products))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(Category.CategoryVariantUnits))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Products.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class CategoryVariantUnitConfiguration : IEntityTypeConfiguration<CategoryVariantUnit>
{
public void Configure(EntityTypeBuilder<CategoryVariantUnit> builder)
{
builder.ToTable("CategoryVariantUnit", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.CategoryVariantUnitId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.VariantUnitId)
.HasField("_variantUnitId")
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.VariantUnitId(x));
builder.Property(x => x.CategoryId)
.HasField("_categoryId")
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.CategoryId(x));
builder.HasIndex(x=> new {x.VariantUnitId, x.CategoryId})
.IsUnique();
builder.Metadata.FindNavigation(nameof(CategoryVariantUnit.VariantUnit))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(CategoryVariantUnit.Category))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System.Linq.Expressions;
using Vizhvizh.Shop.Domain.Members.TypeIds;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations.Converter;
internal class MemberIdConverter : ValueConverter<MemberId, long>
{
public MemberIdConverter()
: base(x=>x.Value, x=> new MemberId(x))
{
}
}
@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System.Linq.Expressions;
using Vizhvizh.Shop.Domain.Products.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations.Converter;
internal class ProductImageConverter : ValueConverter<ProductImage, string>
{
public ProductImageConverter()
: base(x=>x.Value, x=> ProductImage.CreateNew(x))
{
}
}
@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Shops.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class ManagementConfiguration : IEntityTypeConfiguration<Management>
{
public void Configure(EntityTypeBuilder<Management> builder)
{
builder.ToTable("Managements", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Shops.TypeIds.ShopId(x));
builder.Metadata.FindNavigation(nameof(Management.Shop))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Members.Entities;
using Vizhvizh.Shop.Domain.Members.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class MemberConfiguration : IEntityTypeConfiguration<Member>
{
public void Configure(EntityTypeBuilder<Member> builder)
{
builder.ToTable("Members", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.ValueGeneratedOnAdd();
builder.Property(x => x.PhoneNumber)
.HasField("_phoneNumber");
builder.OwnsOne(x => x.FullName, sa =>
{
sa.Property(x => x.FirstName)
.HasMaxLength(MemberFullName.FirstNameLimit)
.HasColumnName("FirstName");
sa.Property(x => x.LastName)
.HasMaxLength(MemberFullName.LastNameLimit)
.HasColumnName("LastName");
});
builder.OwnsOne(x => x.Avatar, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(MemberAvatar.Limit)
.HasColumnName("Avatar");
});
}
}
@@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Drawing;
using Vizhvizh.Shop.Domain.Products.Entities;
using Vizhvizh.Shop.Domain.Products.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class ProductConfiguration : IEntityTypeConfiguration<Product>
{
public void Configure(EntityTypeBuilder<Product> builder)
{
builder.ToTable("Products", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.ProductId(x))
.ValueGeneratedOnAdd();
builder.OwnsOne(x => x.ProductCondition, sa =>
{
sa.Property(x => x.Value).HasColumnName("ProductCondition");
});
builder.Property(x => x.Title)
.HasField("_title");
builder.Property(x => x.Description)
.HasField("_description");
builder.OwnsOne(x => x.Score, sa =>
{
sa.Property(x => x.Score).HasColumnType("Score")
.HasColumnType("TINYINT")
.HasDefaultValue(0);
sa.Property(x => x.TotalVoters).HasColumnName("TotalVoters")
.HasColumnType("INT")
.HasDefaultValue(0); ;
});
builder.OwnsOne(x => x.Image, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(ProductImage.Limit)
.HasColumnName("Image");
});
builder.Metadata.FindNavigation(nameof(Product.Specifications))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(Product.Category))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(Product.Variants))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,58 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Products.Entities;
using Vizhvizh.Shop.Domain.Products.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class ProductVariantConfiguration : IEntityTypeConfiguration<ProductVariant>
{
public void Configure(EntityTypeBuilder<ProductVariant> builder)
{
builder.ToTable("ProductVariants", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.ProductVariantId(x))
.ValueGeneratedOnAdd();
builder.OwnsOne(x => x.Score, sa =>
{
sa.Property(x => x.Score)
.HasColumnName("Score")
.HasColumnType("TINYINT")
.HasDefaultValue(0);
sa.Property(x => x.TotalVoters)
.HasColumnName("TotalVoters")
.HasColumnType("INT")
.HasDefaultValue(0);
});
builder.OwnsOne(x => x.Value, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(ProductVariantValue.Limit)
.HasColumnName("Value")
.IsRequired();
});
builder.OwnsOne(x => x.Price, x =>
{
x.Property(x => x.Value).HasColumnName("Price").IsRequired();
x.Property(x => x.Currency)
.HasMaxLength(MoneyValue.CurrencyLimit)
.HasColumnName("Currency").IsRequired();
});
builder.OwnsOne(x => x.Quantity, sa =>
{
sa.Property(x => x.Value).HasColumnName("Quantity");
});
builder.OwnsMany(x => x.Gallery, sa =>
{
sa.Property(x => x.Value).HasColumnName("Gallery");
sa.ToJson();
});
builder.Metadata.FindNavigation(nameof(ProductVariant.Product))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.Shop.Domain.Users.Entities;
using Vizhvizh.Shop.Domain.Users.ValueObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
public class ResourceConfiguration : IEntityTypeConfiguration<Resource>
{
public void Configure(EntityTypeBuilder<Resource> builder)
{
builder.ToTable("Resources", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Users.TypeIds.ResourceId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.Title)
.HasField("_title");
builder.Property(x => x.Description)
.HasField("_description");
builder.Property(x => x.ModuleName)
.HasField("_moduleName")
.HasColumnType("int")
.HasConversion(x=> (int)x.Value, x=> ModuleNameVO.CreateNew((ModuleNamesEnum)x));
builder.Property(x => x.ResourceKey)
.HasConversion(x=>x.Value, x=> ResourceKey.CreateNew(x))
.HasField("_resourceKey");
builder.Metadata.FindNavigation(nameof(Resource.Roles))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Users.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
public class RoleConfiguration : IEntityTypeConfiguration<Role>
{
public void Configure(EntityTypeBuilder<Role> builder)
{
builder.ToTable("Roles", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Users.TypeIds.RoleId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.Title)
.HasField("_title");
builder.Metadata.FindNavigation(nameof(Role.RoleResources))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Users.Entities;
using Vizhvizh.Shop.Domain.Users.ValueObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
public class RoleResourceConfiguration : IEntityTypeConfiguration<RoleResource>
{
public void Configure(EntityTypeBuilder<RoleResource> builder)
{
builder.ToTable("RoleResources", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Users.TypeIds.RoleResourceId(x))
.ValueGeneratedOnAdd();
builder.Property(x=>x.AccessLevel)
.HasConversion(x=>x.Value, x=> AccessLevel.CreateNew((AccessLevelEnum)x));
builder.Metadata.FindNavigation(nameof(RoleResource.User))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(RoleResource.Role))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Shops.Entities;
using Vizhvizh.Shop.Domain.Shops.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class ShippingMethodConfiguration : IEntityTypeConfiguration<ShippingMethod>
{
public void Configure(EntityTypeBuilder<ShippingMethod> builder)
{
builder.ToTable("ShippingMethods", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Shops.TypeIds.ShippingMethodId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.Title)
.HasField("_title");
builder.Property(x => x.Description)
.HasField("_description");
builder.OwnsOne(x => x.Image, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(ShippingMethodImage.Limit)
.HasColumnName("Image");
});
builder.Metadata.FindNavigation(nameof(ShippingMethod.Shop))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Shops.Entities;
using Vizhvizh.Shop.Domain.Shops.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
public class ShopConfiguration : IEntityTypeConfiguration<Domain.Shops.Entities.Shop>
{
public void Configure(EntityTypeBuilder<Domain.Shops.Entities.Shop> builder)
{
builder.ToTable("Shops", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Shops.TypeIds.ShopId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.OwnerId)
.HasField("_ownerId");
builder.Property(x => x.Title)
.HasField("_title");
builder.Property(x => x.Description)
.HasField("_description");
builder.Property(x => x.Email)
.HasField("_email");
builder.Property(x => x.Telephone)
.HasField("_telephoneVO");
builder.OwnsOne(x => x.Logo, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(ShopLogo.Limit)
.HasColumnName("Logo");
});
builder.OwnsOne(x => x.Location, sa =>
{
sa.Property(x => x.PostalCode).HasColumnName(nameof(ShopLocation.PostalCode));
sa.Property(x => x.ProvinceId).HasColumnName(nameof(ShopLocation.ProvinceId));
sa.Property(x => x.CityId).HasColumnName(nameof(ShopLocation.CityId));
sa.Property(x => x.Address).HasColumnName(nameof(ShopLocation.Address));
sa.Property(x => x.Latitude).HasColumnName(nameof(ShopLocation.Latitude));
sa.Property(x => x.Longitude).HasColumnName(nameof(ShopLocation.Longitude));
sa.ToJson();
});
builder.HasOne(x => x.Management)
.WithOne(x => x.Shop)
.HasForeignKey<Management>(x => x.Id);
builder.Metadata.FindNavigation(nameof(Domain.Shops.Entities.Shop.Management))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(Domain.Shops.Entities.Shop.Products))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(Domain.Shops.Entities.Shop.ShippingMethods))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(Domain.Shops.Entities.Shop.Members))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Sliders.Entities;
using Vizhvizh.Shop.Domain.Sliders.ValuesObjects;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class SliderConfiguration : IEntityTypeConfiguration<Slider>
{
public void Configure(EntityTypeBuilder<Slider> builder)
{
builder.ToTable("Sliders", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Sliders.TypeIds.SliderId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.Title)
.HasField("_title");
builder.OwnsOne(x => x.Image, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(SliderImage.Limit)
.HasColumnName("Image");
});
builder.OwnsOne(x => x.Url, sa =>
{
sa.Property(x => x.Value)
.HasMaxLength(SliderUrl.Limit)
.HasColumnName("Url");
});
builder.OwnsOne(x => x.Key, sa =>
{
sa.Property(x => x.Value)
.HasColumnName("Key")
.HasMaxLength(SliderKey.Limit);
sa.Property(x => x.Type)
.HasColumnName("Type")
.HasColumnType("INT");
});
}
}
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Newtonsoft.Json;
using Vizhvizh.Shop.Domain.Products.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class SpecificationsConfiguration : IEntityTypeConfiguration<Specifications>
{
public void Configure(EntityTypeBuilder<Specifications> builder)
{
builder.ToTable("ProductSpecifications", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x=>x.Value, x=> new Domain.Products.TypeIds.SpecificationsId(x))
.ValueGeneratedOnAdd();
builder.Property(x => x.Title)
.HasField("_title");
builder.Property(x => x.ItemValues)
.HasConversion(x=> JsonConvert.SerializeObject(x), x=> JsonConvert.DeserializeObject<List<string>>(x)!)
.HasField("_itemValues");
builder.Metadata.FindNavigation(nameof(Specifications.Product))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Products.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class UnitConfiguration : IEntityTypeConfiguration<Unit>
{
public void Configure(EntityTypeBuilder<Unit> builder)
{
builder.ToTable("Units", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.UnitId(x));
builder.Property(x => x.Title)
.HasField("_title");
builder.Metadata.FindNavigation(nameof(Unit.VariantUnits))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Users.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
public class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable("Users", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Users.TypeIds.UserId(x))
.ValueGeneratedOnAdd();
//builder.OwnsOne(x => x.NationalCode, sa =>
//{
// sa.Property(x => x.Value).HasColumnName("NationalCode");
//});
builder.Property(x => x.MemberId);
builder.Metadata.FindNavigation(nameof(User.Roles))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Products.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class VariantConfiguration : IEntityTypeConfiguration<Variant>
{
public void Configure(EntityTypeBuilder<Variant> builder)
{
builder.ToTable("Variants", schema: "Shop");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.VariantId(x));
builder.Property(x => x.Title)
.HasField("_title");
builder.Metadata.FindNavigation(nameof(Variant.VariantUnits))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vizhvizh.Shop.Domain.Products.Entities;
namespace Vizhvizh.Shop.Infrastructure.EF.Configurations;
internal class VariantUnitConfiguration : IEntityTypeConfiguration<VariantUnit>
{
public void Configure(EntityTypeBuilder<VariantUnit> builder)
{
builder.ToTable("VariantUnits", schema: "Shop");
builder.HasKey(x=>x.Id);
builder.Property(x => x.Id)
.HasConversion(x => x.Value, x => new Domain.Products.TypeIds.VariantUnitId(x));
builder.Property(x => x.VariantUnitType)
.HasColumnType("INT")
.HasField("_variantUnitType");
builder.Metadata.FindNavigation(nameof(VariantUnit.Variant))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(VariantUnit.Unit))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(VariantUnit.CategoryVariantUnits))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
builder.Metadata.FindNavigation(nameof(VariantUnit.ProductVariants))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
@@ -0,0 +1,84 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Abstractions;
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.Shared.Infrastructure.EF.Configurations.Converters;
using Vizhvizh.Shop.Domain.Members.TypeIds;
using Vizhvizh.Shop.Domain.Sliders.Entities;
using Vizhvizh.Shop.Infrastructure.Configuration;
using Vizhvizh.Shop.Infrastructure.EF.Configurations.Converter;
namespace Vizhvizh.Shop.Infrastructure.EF;
internal class ShopDbContext : DbContext
{
public ShopDbContext(DbContextOptions<ShopDbContext> options)
: base(options)
{
}
public virtual DbSet<Domain.Members.Entities.Member> Members { get; set; }
public virtual DbSet<Domain.Products.Entities.Product> Products { get; set; }
public virtual DbSet<Domain.Products.Entities.Category> Categories { get; set; }
public virtual DbSet<Domain.Products.Entities.Specifications> Specifications { get; set; }
public virtual DbSet<Domain.Shops.Entities.Shop> Shops { get; set; }
public virtual DbSet<Slider> Sliders { get; set; }
public virtual DbSet<Domain.Shops.Entities.ShippingMethod> ShippingMethods { get; set; }
public virtual DbSet<Domain.Shops.Entities.Management> Managements { get; set; }
public virtual DbSet<Domain.Users.Entities.User> Users { get; set; }
public virtual DbSet<Domain.Users.Entities.RoleResource> RoleResources { get; set; }
public virtual DbSet<Domain.Users.Entities.Role> Roles { get; set; }
public virtual DbSet<Domain.Users.Entities.Resource> Resources { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(Assemblies.Infrastructure, FindConfigurations);
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
var createOnProperty = entityType.FindProperty("CreateOn");
if (createOnProperty != null && createOnProperty.ClrType == typeof(DateTime))
{
createOnProperty.SetDefaultValueSql("GETDATE()");
}
}
}
public bool FindConfigurations(Type type)
=> type?.FullName?.Contains("Configurations") ?? false;
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.Properties<MemberId>()
.HaveConversion<MemberIdConverter>();
configurationBuilder.Properties<DateTimeVO>()
.HaveConversion<DateTimeConverter>();
configurationBuilder.Properties<TitleVO>()
.HaveConversion<TitleConverter>()
.HaveMaxLength(TitleVO.Limit);
configurationBuilder.Properties<DescriptionVO>()
.HaveConversion<DescriptionConverter>()
.HaveMaxLength(DescriptionVO.Limit);
configurationBuilder.Properties<EmailVO>()
.HaveMaxLength(EmailVO.Limit)
.HaveConversion<EmailConverter>();
configurationBuilder.Properties<PhoneNumberVO>()
.HaveConversion<PhoneNumberConverter>()
.HaveMaxLength(PhoneNumberVO.Limit);
configurationBuilder.Properties<TelephoneVO>()
.HaveConversion<TelephoneConverter>()
.HaveMaxLength(TelephoneVO.Limit);
configurationBuilder.Properties<ModuleNameVO>()
.HaveConversion<ModuleNameConverter>();
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,565 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Vizhvizh.Shop.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "Shop");
migrationBuilder.CreateTable(
name: "Categories",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
Image = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
ParentId = table.Column<long>(type: "bigint", nullable: true),
Path = table.Column<string>(type: "HIERARCHYID", nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Categories", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Resources",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
ModuleName = table.Column<int>(type: "int", nullable: false),
ResourceKey = table.Column<string>(type: "nvarchar(max)", nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Resources", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Shops",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OwnerId = table.Column<long>(type: "bigint", nullable: false),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
Email = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
Telephone = table.Column<string>(type: "nvarchar(11)", maxLength: 11, nullable: false),
Logo = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"),
Location = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sliders",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
Image = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
Url = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
Type = table.Column<int>(type: "INT", nullable: false),
Key = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Sliders", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Units",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Units", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MemberId = table.Column<long>(type: "bigint", nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Variants",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Variants", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Managements",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Managements", x => x.Id);
table.ForeignKey(
name: "FK_Managements_Shops_Id",
column: x => x.Id,
principalSchema: "Shop",
principalTable: "Shops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Members",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FirstName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
LastName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
PhoneNumber = table.Column<string>(type: "nvarchar(11)", maxLength: 11, nullable: false),
Avatar = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: true),
ShopId = table.Column<long>(type: "bigint", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Members", x => x.Id);
table.ForeignKey(
name: "FK_Members_Shops_ShopId",
column: x => x.ShopId,
principalSchema: "Shop",
principalTable: "Shops",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Products",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProductCondition = table.Column<int>(type: "int", nullable: false),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
Score_Score = table.Column<byte>(type: "TINYINT", nullable: false, defaultValue: (byte)0),
TotalVoters = table.Column<int>(type: "INT", nullable: false, defaultValue: 0),
Image = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
CategoryId = table.Column<long>(type: "bigint", nullable: true),
ShopId = table.Column<long>(type: "bigint", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
table.ForeignKey(
name: "FK_Products_Categories_CategoryId",
column: x => x.CategoryId,
principalSchema: "Shop",
principalTable: "Categories",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Products_Shops_ShopId",
column: x => x.ShopId,
principalSchema: "Shop",
principalTable: "Shops",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ShippingMethods",
schema: "Shop",
columns: table => new
{
Id = table.Column<byte>(type: "tinyint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
Image = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
ShopId = table.Column<long>(type: "bigint", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_ShippingMethods", x => x.Id);
table.ForeignKey(
name: "FK_ShippingMethods_Shops_ShopId",
column: x => x.ShopId,
principalSchema: "Shop",
principalTable: "Shops",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Roles",
schema: "Shop",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
ResourceId = table.Column<long>(type: "bigint", nullable: true),
UserId = table.Column<long>(type: "bigint", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
table.ForeignKey(
name: "FK_Roles_Resources_ResourceId",
column: x => x.ResourceId,
principalSchema: "Shop",
principalTable: "Resources",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Roles_Users_UserId",
column: x => x.UserId,
principalSchema: "Shop",
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "VariantUnits",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
VariantUnitType = table.Column<int>(type: "INT", nullable: false),
UnitId = table.Column<long>(type: "bigint", nullable: true),
VariantId = table.Column<long>(type: "bigint", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_VariantUnits", x => x.Id);
table.ForeignKey(
name: "FK_VariantUnits_Units_UnitId",
column: x => x.UnitId,
principalSchema: "Shop",
principalTable: "Units",
principalColumn: "Id");
table.ForeignKey(
name: "FK_VariantUnits_Variants_VariantId",
column: x => x.VariantId,
principalSchema: "Shop",
principalTable: "Variants",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ProductSpecifications",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
ItemValues = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProductId = table.Column<long>(type: "bigint", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_ProductSpecifications", x => x.Id);
table.ForeignKey(
name: "FK_ProductSpecifications_Products_ProductId",
column: x => x.ProductId,
principalSchema: "Shop",
principalTable: "Products",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "RoleResources",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AccessLevel = table.Column<int>(type: "int", nullable: false),
RoleId = table.Column<int>(type: "int", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_RoleResources", x => x.Id);
table.ForeignKey(
name: "FK_RoleResources_Roles_RoleId",
column: x => x.RoleId,
principalSchema: "Shop",
principalTable: "Roles",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "CategoryVariantUnit",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CategoryId = table.Column<long>(type: "bigint", nullable: false),
VariantUnitId = table.Column<long>(type: "bigint", nullable: false),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()")
},
constraints: table =>
{
table.PrimaryKey("PK_CategoryVariantUnit", x => x.Id);
table.ForeignKey(
name: "FK_CategoryVariantUnit_Categories_CategoryId",
column: x => x.CategoryId,
principalSchema: "Shop",
principalTable: "Categories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CategoryVariantUnit_VariantUnits_VariantUnitId",
column: x => x.VariantUnitId,
principalSchema: "Shop",
principalTable: "VariantUnits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProductVariants",
schema: "Shop",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Currency = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
Score = table.Column<byte>(type: "TINYINT", nullable: false, defaultValue: (byte)0),
TotalVoters = table.Column<int>(type: "INT", nullable: false, defaultValue: 0),
Quantity = table.Column<double>(type: "float", nullable: false),
Value = table.Column<string>(type: "nvarchar(120)", maxLength: 120, nullable: false),
ProductId = table.Column<long>(type: "bigint", nullable: true),
VariantUnitId = table.Column<long>(type: "bigint", nullable: true),
CreateOn = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"),
Gallery = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ProductVariants", x => x.Id);
table.ForeignKey(
name: "FK_ProductVariants_Products_ProductId",
column: x => x.ProductId,
principalSchema: "Shop",
principalTable: "Products",
principalColumn: "Id");
table.ForeignKey(
name: "FK_ProductVariants_VariantUnits_VariantUnitId",
column: x => x.VariantUnitId,
principalSchema: "Shop",
principalTable: "VariantUnits",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_CategoryVariantUnit_CategoryId",
schema: "Shop",
table: "CategoryVariantUnit",
column: "CategoryId");
migrationBuilder.CreateIndex(
name: "IX_CategoryVariantUnit_VariantUnitId_CategoryId",
schema: "Shop",
table: "CategoryVariantUnit",
columns: new[] { "VariantUnitId", "CategoryId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Members_ShopId",
schema: "Shop",
table: "Members",
column: "ShopId");
migrationBuilder.CreateIndex(
name: "IX_Products_CategoryId",
schema: "Shop",
table: "Products",
column: "CategoryId");
migrationBuilder.CreateIndex(
name: "IX_Products_ShopId",
schema: "Shop",
table: "Products",
column: "ShopId");
migrationBuilder.CreateIndex(
name: "IX_ProductSpecifications_ProductId",
schema: "Shop",
table: "ProductSpecifications",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_ProductVariants_ProductId",
schema: "Shop",
table: "ProductVariants",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_ProductVariants_VariantUnitId",
schema: "Shop",
table: "ProductVariants",
column: "VariantUnitId");
migrationBuilder.CreateIndex(
name: "IX_RoleResources_RoleId",
schema: "Shop",
table: "RoleResources",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_Roles_ResourceId",
schema: "Shop",
table: "Roles",
column: "ResourceId");
migrationBuilder.CreateIndex(
name: "IX_Roles_UserId",
schema: "Shop",
table: "Roles",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_ShippingMethods_ShopId",
schema: "Shop",
table: "ShippingMethods",
column: "ShopId");
migrationBuilder.CreateIndex(
name: "IX_VariantUnits_UnitId",
schema: "Shop",
table: "VariantUnits",
column: "UnitId");
migrationBuilder.CreateIndex(
name: "IX_VariantUnits_VariantId",
schema: "Shop",
table: "VariantUnits",
column: "VariantId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CategoryVariantUnit",
schema: "Shop");
migrationBuilder.DropTable(
name: "Managements",
schema: "Shop");
migrationBuilder.DropTable(
name: "Members",
schema: "Shop");
migrationBuilder.DropTable(
name: "ProductSpecifications",
schema: "Shop");
migrationBuilder.DropTable(
name: "ProductVariants",
schema: "Shop");
migrationBuilder.DropTable(
name: "RoleResources",
schema: "Shop");
migrationBuilder.DropTable(
name: "ShippingMethods",
schema: "Shop");
migrationBuilder.DropTable(
name: "Sliders",
schema: "Shop");
migrationBuilder.DropTable(
name: "Products",
schema: "Shop");
migrationBuilder.DropTable(
name: "VariantUnits",
schema: "Shop");
migrationBuilder.DropTable(
name: "Roles",
schema: "Shop");
migrationBuilder.DropTable(
name: "Categories",
schema: "Shop");
migrationBuilder.DropTable(
name: "Shops",
schema: "Shop");
migrationBuilder.DropTable(
name: "Units",
schema: "Shop");
migrationBuilder.DropTable(
name: "Variants",
schema: "Shop");
migrationBuilder.DropTable(
name: "Resources",
schema: "Shop");
migrationBuilder.DropTable(
name: "Users",
schema: "Shop");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,15 @@
using Vizhvizh.Shop.Domain.Shops.Repositories;
using Vizhvizh.Shop.Domain.Shops.TypeIds;
using Vizhvizh.Shop.Infrastructure.EF;
namespace Vizhvizh.Shop.Infrastructure.Repositories
{
internal class ShopRepository(ShopDbContext context) : IShopRepository
{
public async Task AddAsync(Domain.Shops.Entities.Shop shop, CancellationToken cancellationToken)
=> await context.Shops.AddAsync(shop, cancellationToken);
public async Task<Domain.Shops.Entities.Shop?> FindByIdAsync(ShopId id, CancellationToken cancellationToken)
=> await context.Shops.FindAsync(id,cancellationToken).ConfigureAwait(false);
}
}
@@ -0,0 +1,18 @@
using Vizhvizh.Shop.Domain.Sliders.Entities;
using Vizhvizh.Shop.Domain.Sliders.Repositories;
using Vizhvizh.Shop.Domain.Sliders.TypeIds;
namespace Vizhvizh.Shop.Infrastructure.Repositories;
public class SliderRepository : ISliderRepository
{
public Task AddAsync(Slider slider, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task GetByIdAsync(SliderId id, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
@@ -0,0 +1,80 @@
using Vizhvizh.Shop.Application;
using Vizhvizh.Shop.Infrastructure.Configuration;
using Vizhvizh.Shop.Infrastructure.EF;
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.BuildingBlocks.Application.Configuration.Query;
using Vizhvizh.BuildingBlocks.Application.Data;
using Vizhvizh.BuildingBlocks.Application.Events;
using Vizhvizh.BuildingBlocks.Application.Outbox;
using Vizhvizh.BuildingBlocks.Infrastructure;
using Vizhvizh.BuildingBlocks.Infrastructure.DomainEventsDispatching;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Vizhvizh.Shop.Domain.Shops.Repositories;
using Vizhvizh.Shop.Infrastructure.Repositories;
using Vizhvizh.BuildingBlocks.Infrastructure.SelectBuilders;
using Vizhvizh.BuildingBlocks.Application.SelectBuilders;
using Vizhvizh.Shop.Domain.Sliders.Repositories;
namespace Vizhvizh.Shop.Infrastructure;
public class ShopStartup
{
public static void Initialize(IServiceCollection services, string connectionString)
{
services.AddDbContext<ShopDbContext>(op =>
{
op.UseSqlServer(connectionString);
});
services.AddScoped<DbContext>(sp => sp.GetRequiredService<ShopDbContext>());
services.AddScoped<IShopModule, ShopModule>();
services.AddScoped<IUnitOfWork, UnitOfWork>();
services.AddScoped<IDomainEventsAccessor, DomainEventsAccessor>();
services.AddScoped<IDomainEventsDispatcher, DomainEventsDispatcher>();
services.AddScoped<IDomainNotificationsMapper, DomainNotificationsMapper>();
services.AddScoped<IExecutor, Executor>();
services.Scan(scan => scan.
FromAssemblies(Assemblies.Application, Assemblies.Infrastructure)
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime()
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<,>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime()
.AddClasses(classes => classes.AssignableTo(typeof(IQueryHandler<,>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime()
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime());
services.Decorate(typeof(ICommandHandler<>), typeof(UnitOfWorkCommandHandlerDecorator<>));
services.Decorate(typeof(ICommandHandler<,>), typeof(UnitOfWorkCommandHandlerDecorator<,>));
services.AddScoped(sa =>
{
var notifications = sa.GetServices<IDomainEventNotification>();
var notificationDic = new BiDictionary<string, Type>();
foreach (var notification in notifications)
notificationDic.Add(notification!.ToString()!, notification!.GetType());
return notificationDic;
});
services.AddScoped<IOutbox>(sa =>
{
return null; // ToDo
});
services.AddScoped<ISqlConnectionFactory>(sp =>
{
return new SqlConnectionFactory(connectionString);
});
services.AddScoped<ISqlDialect, SqlServerDialect>();
services.AddScoped<ISqlSelectBuilder, SqlSelectBuilder>();
#region Repositories
services.AddScoped<IShopRepository, ShopRepository>();
services.AddScoped<ISliderRepository, SliderRepository>();
#endregion
}
}
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.25">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.25">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Vichvich.Shared.Infrastructure\Vizhvizh.Shared.Infrastructure.csproj" />
<ProjectReference Include="..\Vichvich.Shop.Application\Vizhvizh.Shop.Application.csproj" />
<ProjectReference Include="..\Vichvich.Shop.Domain\Vizhvizh.Shop.Domain.csproj" />
</ItemGroup>
</Project>