Infrastructure

This commit is contained in:
2026-04-22 20:51:02 +04:30
parent c64c3dd9be
commit 64ee78e320
199 changed files with 7428 additions and 1027 deletions
@@ -0,0 +1,41 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Members.TypeIds;
using Vizhvizh.GoldGallery.Domain.Members.ValuesObjects;
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Members.Events;
namespace Vizhvizh.GoldGallery.Domain.Members.Entities;
public class Member : Entity<MemberId>, IAggregateRoot
{
private PhoneNumberVO _phoneNumber;
private MemberFullName _fullName;
private MemberAvatar? _avatar;
private MemberNationalCode? _nationalCode;
private Member()
{
}
private Member(PhoneNumberVO phoneNumber, MemberFullName fullName, MemberAvatar? avatar)
{
_fullName = fullName;
_phoneNumber = phoneNumber;
_avatar = avatar;
}
public static Member CreateNew(PhoneNumberVO phoneNumber, MemberFullName fullName, MemberAvatar? avatar = null)
{
return new Member(phoneNumber, fullName, avatar);
}
public MemberFullName? FullName => _fullName;
public PhoneNumberVO PhoneNumber => _phoneNumber;
public MemberAvatar? Avatar => _avatar;
public MemberNationalCode? NationalCode => _nationalCode;
public void SetNationalCode(MemberNationalCode nationalCode)
{
_nationalCode = nationalCode;
this.AddDomainEvent(new SetNationalCodeEvent(this));
}
}
@@ -0,0 +1,9 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Members.Entities;
namespace Vizhvizh.GoldGallery.Domain.Members.Events;
public class SetNationalCodeEvent(Member member) : DomainEventBase
{
public Member Member => member;
}
@@ -0,0 +1,11 @@
using Vizhvizh.GoldGallery.Domain.Resource.Members;
using Vizhvizh.BuildingBlocks.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Members.Exceptions;
public class MemberFullNameNullOrEmptyException : ValueObjectValidationException
{
public MemberFullNameNullOrEmptyException() : base(ExceptionResources.MemberFullNameNullOrEmptyException)
{
}
}
@@ -0,0 +1,16 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Members.TypeIds;
public class MemberId : TypedIdValueBase<long>
{
public MemberId(long value) : base(value)
{
}
public static implicit operator MemberId(long value)
=> new MemberId(value);
public static implicit operator long(MemberId value)
=> value.Value;
}
@@ -0,0 +1,17 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Members.ValuesObjects;
public class MemberAvatar : ValueObject
{
public const short Limit = 150;
public MemberAvatar(string value)
{
if (value.Length > Limit)
throw new CharacterLimitException(nameof(MemberAvatar), Limit);
Value = value;
}
public string Value { get; init; }
}
@@ -0,0 +1,30 @@
using Vizhvizh.Shared.Domain.Exceptions;
using Vizhvizh.GoldGallery.Domain.Members.Exceptions;
using Vizhvizh.GoldGallery.Domain.Resource.Members;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Members.ValuesObjects;
public class MemberFullName : ValueObject
{
public const short FirstNameLimit = 50;
public const short LastNameLimit = 50;
public MemberFullName(string firstName, string lastName)
{
if (string.IsNullOrWhiteSpace(firstName) || string.IsNullOrWhiteSpace(lastName))
throw new MemberFullNameNullOrEmptyException();
if (firstName.Length > FirstNameLimit || lastName.Length > LastNameLimit)
throw new CharacterLimitException(ValueObjectResources.MemberFullName, FirstNameLimit + LastNameLimit);
FirstName = firstName;
LastName = lastName;
}
public string FirstName { get; init; }
public string LastName { get; init; }
public override string ToString()
{
return $"{FirstName} {LastName}";
}
}
@@ -0,0 +1,17 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Members.ValuesObjects;
public class MemberNationalCode : ValueObject
{
public const short Limit = 10;
public MemberNationalCode(string value)
{
if (value.Length > Limit)
throw new CharacterLimitException(nameof(MemberNationalCode), Limit);
Value = value;
}
public string Value { get; private set; }
}
@@ -0,0 +1,61 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
using Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
using Vizhvizh.BuildingBlocks.Domain;
using System.IO;
namespace Vizhvizh.GoldGallery.Domain.Products.Entities;
/// <summary>
/// دسته بندی
/// </summary>
public class Category : Entity<CategoryId>
{
private TitleVO _title;
private DescriptionVO _description;
private CategoryImage _image;
private CategoryId? _parentId;
private CategoryPath _path;
#region Relationships
private List<Product> _products;
#endregion
private Category()
{
}
private Category(TitleVO title,
DescriptionVO description,
CategoryImage image,
CategoryPath path,
CategoryId? parentId = null,
CategoryPath? parentPath = null)
{
_title = title;
_description = description;
_image = image;
_parentId = parentId;
//_path = CategoryPath.CreatePath(parentPath, ;
}
public static Category CreateNew(TitleVO title,
DescriptionVO description,
CategoryImage image,
CategoryPath path,
CategoryId? parentId = null,
CategoryPath? parentPath = null)
{
return new Category(title, description, image, path, parentId, parentPath);
}
public TitleVO Title => _title;
public DescriptionVO Description => _description;
public CategoryImage Image => _image;
public CategoryId? ParentId => _parentId;
public CategoryPath Path => _path;
public IReadOnlyList<Product> Products => _products;
}
@@ -0,0 +1,80 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
using Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.Entities;
/// <summary>
/// محصول
/// </summary>
public class Product : Entity<ProductId>, IAggregateRoot
{
private Category _category;
private List<Specifications> _specifications;
private ProductCondition _productCondition;
private TitleVO _title;
private DescriptionVO _description;
private ProductScore _score;
private CraftsmanshipFee _craftsmanshipFee;
private List<ProductVariant> _variants;
/// <summary>
///عکس اصلی
/// </summary>
private ProductImage _image;
private ProductFile3D? _file3D;
private Product()
{
}
private Product(TitleVO title,
DescriptionVO description,
ProductCondition productCondition,
Category category,
List<Specifications> specifications,
List<ProductVariant> variants,
ProductImage image,
ProductFile3D? file3D,
CraftsmanshipFee craftsmanshipFee
)
{
_title = title;
_description = description;
_productCondition = productCondition;
_category = category;
_category = category;
_specifications = specifications;
_variants = variants;
_image = image;
_file3D = file3D;
_craftsmanshipFee = craftsmanshipFee;
}
public static Product CreateNew(TitleVO title,
DescriptionVO description,
ProductCondition productCondition,
Category category,
List<Specifications> specifications,
List<ProductVariant> variants,
ProductImage image,
ProductFile3D? file3D,
CraftsmanshipFee craftsmanshipFee)
{
return new(title, description, productCondition, category, specifications, variants, image, file3D, craftsmanshipFee);
}
public Category Category => _category;
public ProductCondition ProductCondition => _productCondition;
public TitleVO Title => _title;
public DescriptionVO Description => _description;
public ProductScore Score => _score;
public ProductImage Image => _image;
public ProductFile3D? File3D => _file3D;
public CraftsmanshipFee CraftsmanshipFee => _craftsmanshipFee;
public IReadOnlyList<ProductVariant> Variants => _variants;
public IReadOnlyList<Specifications> Specifications => _specifications;
}
@@ -0,0 +1,38 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
using Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
namespace Vizhvizh.GoldGallery.Domain.Products.Entities;
public class ProductVariant : Entity<ProductVariantId>
{
private ProductScore _score;
private ProductQuantity _quantity;
private ProductVariantGallery _gallery;
private GoldWeight _weight;
#region Relationships
private Product _product;
#endregion
private ProductVariant()
{
}
private ProductVariant(ProductQuantity quantity, GoldWeight weight, ProductVariantGallery gallery)
{
_quantity = quantity;
_weight = weight;
_gallery = gallery;
}
public ProductScore Score => _score;
public ProductQuantity Quantity => _quantity;
public GoldWeight Weight => _weight;
public Product Product => _product;
public ProductVariantGallery Gallery => _gallery;
public static ProductVariant CreateNew(ProductQuantity quantity, GoldWeight weight, ProductVariantGallery gallery)
=> new(quantity, weight, gallery);
}
@@ -0,0 +1,35 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.Entities;
/// <summary>
/// مشخصات محصول
/// </summary>
public class Specifications : Entity<SpecificationsId>
{
private TitleVO _title;
private List<string> _itemValues;
#region RelationShips
private Product _product;
private Specifications()
{
}
#endregion
private Specifications(TitleVO title, List<string> itemValues)
{
_title = title;
_itemValues = itemValues;
}
public static Specifications CreateNew(TitleVO title, List<string> values)
=> new Specifications(title, values);
public TitleVO Title => _title;
public Product Product => _product;
public IReadOnlyList<string> ItemValues => _itemValues;
}
@@ -0,0 +1,11 @@
using Vizhvizh.BuildingBlocks.Domain.Exceptions;
using Vizhvizh.GoldGallery.Domain.Resource.Products;
namespace Vizhvizh.GoldGallery.Domain.Products.Exceptions;
public class CraftsmanshipFeeCannotBeNegativeException : ValueObjectValidationException
{
public CraftsmanshipFeeCannotBeNegativeException() : base(ExceptionResources.CraftsmanshipFeeCannotBeNegativeException)
{
}
}
@@ -0,0 +1,12 @@
using Vizhvizh.BuildingBlocks.Domain.Exceptions;
using Vizhvizh.GoldGallery.Domain.Resource.Products;
namespace Vizhvizh.GoldGallery.Domain.Products.Exceptions;
public class GoldWeightMustGreaterThanException : ValueObjectValidationException
{
public GoldWeightMustGreaterThanException(short weight)
: base(string.Format(ExceptionResources.GoldWeightMustGreaterThanException, weight))
{
}
}
@@ -0,0 +1,11 @@
using Vizhvizh.BuildingBlocks.Domain.Exceptions;
using Vizhvizh.GoldGallery.Domain.Resource.Products;
namespace Vizhvizh.GoldGallery.Domain.Products.Exceptions;
public class InvalidCraftsmanshipFeeException : ValueObjectValidationException
{
public InvalidCraftsmanshipFeeException() : base(ExceptionResources.InvalidCraftsmanshipFeeException)
{
}
}
@@ -0,0 +1,14 @@
using Vizhvizh.BuildingBlocks.Domain.Exceptions;
using Vizhvizh.GoldGallery.Domain.Resource.Products;
namespace Vizhvizh.GoldGallery.Domain.Products.Exceptions
{
public class InvalidProductVariantValueException : ValueObjectValidationException
{
public InvalidProductVariantValueException(string value, string typeName)
: base(string.Format(ExceptionResources.InvalidProductVariantValueException, value, typeName))
{
}
}
}
@@ -0,0 +1,9 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Products.Entities;
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
namespace Vizhvizh.GoldGallery.Domain.Products.Repositories;
public interface ICategoryRepository : IRepositoryBase<Category, CategoryId>
{
}
@@ -0,0 +1,9 @@
using Vizhvizh.GoldGallery.Domain.Products.Entities;
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.Repositories;
public interface IProductRepository : IRepositoryBase<Product, ProductId>
{
}
@@ -0,0 +1,19 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
/// <summary>
///
/// </summary>
public class CategoryId : TypedIdValueBase<long>
{
public CategoryId(long value) : base(value)
{
}
public static implicit operator CategoryId(long value)
=> new CategoryId(value);
public static implicit operator long(CategoryId value)
=> value.Value;
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class CategoryVariantUnitId : TypedIdValueBase<long>
{
public CategoryVariantUnitId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class ModelId : TypedIdValueBase<long>
{
public ModelId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class ProductId : TypedIdValueBase<long>
{
public ProductId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class ProductVariantId : TypedIdValueBase<long>
{
public ProductVariantId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class SpecificationsId : TypedIdValueBase<long>
{
public SpecificationsId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class UnitId : TypedIdValueBase<long>
{
public UnitId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class VariantId : TypedIdValueBase<long>
{
public VariantId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.TypeIds;
public class VariantUnitId : TypedIdValueBase<long>
{
public VariantUnitId(long value) : base(value)
{
}
}
@@ -0,0 +1,20 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
public class CategoryImage : ValueObject
{
public const short Limit = 150;
private CategoryImage(string value)
{
if (value.Length > Limit)
throw new CharacterLimitException(nameof(CategoryImage), Limit);
Value = value;
}
public static CategoryImage CreateNew(string value)
=> new CategoryImage(value);
public string Value { get; init; }
}
@@ -0,0 +1,24 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
public class CategoryPath : ValueObject
{
private CategoryPath(string value)
{
Value = value;
}
public string Value { get; private set; }
public static CategoryPath CreateNew(string value)
=> new CategoryPath(value);
public static CategoryPath CreatePath(CategoryPath? parentPath, string childId)
{
if (parentPath == null)
return new CategoryPath(childId);
return new CategoryPath($"{parentPath.Value}/{childId}");
}
}
@@ -0,0 +1,57 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Products.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
/// <summary>
/// اجرت
/// </summary>
public class CraftsmanshipFee : ValueObject
{
private const int TotalPrecision = 4; // Precision (P)
private const int DecimalScale = 2; // Scale (S)
private const int IntegerPartMaxDigits = TotalPrecision - DecimalScale; // = 2
private const decimal MaxValue = 99.99m;
private const decimal MinValue = 0m;
public decimal Value { get; private set; }
public CraftsmanshipFee(decimal value)
{
if (value < 0)
throw new CraftsmanshipFeeCannotBeNegativeException();
if (!ValidateDecimalPrecision(value))
throw new InvalidCraftsmanshipFeeException();
Value = value;
}
public static CraftsmanshipFee CreateNew(decimal value)
=> new CraftsmanshipFee(value);
private bool ValidateDecimalPrecision(decimal value)
{
// روش اول: بررسی محدوده عددی
if (value > MaxValue || value < MinValue)
return false;
// روش دوم: بررسی دقیق تعداد ارقام (اختیاری - برای اطمینان بیشتر)
var roundedValue = Math.Round(value, DecimalScale);
if (Math.Abs(value - roundedValue) > 0)
return false;
// روش سوم: بررسی اینکه تعداد ارقام صحیح از حد مجاز بیشتر نباشد
var integerPart = Math.Floor(Math.Abs(value));
if (integerPart >= (decimal)Math.Pow(10, IntegerPartMaxDigits))
return false;
return true;
}
public static implicit operator CraftsmanshipFee(decimal value)
=> new(value);
public static implicit operator decimal(CraftsmanshipFee value)
=> value.Value;
}
@@ -0,0 +1,28 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Products.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
public class GoldWeight : ValueObject
{
public decimal Value { get; private set; } // بر حسب گرم
private GoldWeight(decimal value)
{
if (value <= 0)
throw new GoldWeightMustGreaterThanException(0);
Value = value;
}
public static GoldWeight CreateNew(decimal value)
=> new(value);
public static implicit operator GoldWeight(decimal value)
=> new(value);
public static implicit operator decimal(GoldWeight value)
=> value.Value;
}
@@ -0,0 +1,34 @@
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
/// <summary>
/// پول
/// </summary>
public class MoneyValue
{
public const short CurrencyLimit = 150;
public decimal Value { get; }
public string Currency { get; }
public static MoneyValue CreateNew(decimal value, string currency)
{
return new MoneyValue(value, currency);
}
private MoneyValue(decimal value, string currency)
{
if(currency.Length > CurrencyLimit)
throw new CharacterLimitException(nameof(Currency), CurrencyLimit);
this.Value = value;
this.Currency = currency;
}
public static MoneyValue operator *(int left, MoneyValue right)
{
return new MoneyValue(right.Value * left, right.Currency);
}
}
@@ -0,0 +1,35 @@
using System.ComponentModel.DataAnnotations;
using Vizhvizh.GoldGallery.Domain.Resource.Products;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
/// <summary>
/// وضعیت محصول نو، کارکرده
/// </summary>
public class ProductCondition : ValueObject
{
private ProductCondition(ProductConditionEnum value)
{
Value = value;
}
public static ProductCondition CreateNew(ProductConditionEnum value)
=> new ProductCondition(value);
public ProductConditionEnum Value { get; private set; }
public static implicit operator ProductCondition(ProductConditionEnum value)
=> new(value);
public static implicit operator ProductConditionEnum(ProductCondition value)
=> value.Value;
}
public enum ProductConditionEnum
{
[Display(Name = nameof(ValueObjectResources.ProductConditionEnum_BrandNew), ResourceType = typeof(ValueObjectResources))]
BrandNew = 0,
[Display(Name = nameof(ValueObjectResources.ProductConditionEnum_LikeNew), ResourceType = typeof(ValueObjectResources))]
LikeNew = 1,
[Display(Name = nameof(ValueObjectResources.ProductConditionEnum_Used), ResourceType = typeof(ValueObjectResources))]
Used = 2,
}
@@ -0,0 +1,27 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
public class ProductFile3D : ValueObject
{
public const short Limit = 150;
public string Value { get; private set; }
private ProductFile3D(string value)
{
if (value.Length > Limit)
throw new CharacterLimitException(nameof(ProductFile3D), Limit);
Value = value;
}
public static ProductFile3D CreateNew(string value)
=> new(value);
public static implicit operator ProductFile3D?(string? value)
=> string.IsNullOrWhiteSpace(value) ? null : new(value);
public static implicit operator string(ProductFile3D value)
=> value.Value;
}
@@ -0,0 +1,29 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
/// <summary>
/// عکس محصولات
/// </summary>
public class ProductImage : ValueObject
{
public const short Limit = 150;
private ProductImage(string value)
{
if (value.Length > Limit)
throw new CharacterLimitException(nameof(ProductImage), Limit);
Value = value;
}
public static ProductImage CreateNew(string value)
=> new ProductImage(value);
public string Value { get; private set; }
public static implicit operator ProductImage(string value)
=> new(value);
public static implicit operator string(ProductImage value)
=> value.Value;
}
@@ -0,0 +1,24 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
/// <summary>
/// تعداد
/// </summary>
public class ProductQuantity : ValueObject
{
private ProductQuantity(double value)
{
Value = value;
}
public static ProductQuantity CreateNew(double value)
=> new ProductQuantity(value);
public double Value { get; init; }
public static implicit operator ProductQuantity(double value)
=> new(value);
public static implicit operator double(ProductQuantity value)
=> value.Value;
}
@@ -0,0 +1,20 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
/// <summary>
/// امتیاز
/// </summary>
public class ProductScore : ValueObject
{
private ProductScore(byte score, int totalVoters)
{
Score = score;
TotalVoters = totalVoters;
}
public static ProductScore CreateNew(byte score, int totalVoters)
=> new ProductScore(score, totalVoters);
public byte Score { get; private set; }
public int TotalVoters { get; private set; }
}
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects
{
public class ProductVariantGallery : ValueObject
{
public const short Limit = 150;
private ProductVariantGallery(List<string> values)
{
Values = values;
}
public static ProductVariantGallery CreateNew(List<string> values)
=> new ProductVariantGallery(values);
public List<string> Values { get; private set; }
public static implicit operator ProductVariantGallery(List<string> value)
=> new(value);
public static implicit operator List<string>(ProductVariantGallery value)
=> value.Values;
}
}
@@ -0,0 +1,19 @@
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
using Vizhvizh.GoldGallery.Domain.Shops.TypeIds;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Shops.Entities;
/// <summary>
/// مدیریت فروشگاه
/// </summary>
public class Management : Entity<ShopId>
{
private Shop _shop;
private Management()
{
}
internal static Management CreateNew()
=> new Management();
public Shop Shop => _shop;
}
@@ -0,0 +1,33 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Shops.TypeIds;
using Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Shops.Entities;
/// <summary>
/// (نوع ارسال (پست و تیپاکس
/// </summary>
public class ShippingMethod : Entity<ShippingMethodId>
{
private TitleVO _title;
private DescriptionVO _description;
private ShippingMethodImage _image;
private Shop _shop;
private ShippingMethod()
{
}
public ShippingMethod(TitleVO title, DescriptionVO description, ShippingMethodImage image)
{
_title = title;
_description = description;
_image = image;
}
public TitleVO Title => _title;
public DescriptionVO Description => _description;
public ShippingMethodImage Image => _image;
public Shop Shop => _shop;
}
@@ -0,0 +1,79 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Members.Entities;
using Vizhvizh.GoldGallery.Domain.Members.TypeIds;
using Vizhvizh.GoldGallery.Domain.Products.Entities;
using Vizhvizh.GoldGallery.Domain.Shops.TypeIds;
using Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Shops.Entities;
public class Shop : Entity<ShopId>, IAggregateRoot
{
private Management _management;
private List<Product> _products;
private List<ShippingMethod> _shippingMethods;
private List<Member> _members;
private ShopLocation _location;
private TitleVO _title;
private DescriptionVO? _description;
private EmailVO? _email;
private TelephoneVO _telephoneVO;
private ShopLogo _logo;
private MemberId _ownerId;
private ShopStatus _shopStatus;
private ShopBusinessLicense _businessLicense;
private Shop()
{
}
private Shop(
MemberId ownerId,
TitleVO title,
ShopLocation location,
TelephoneVO telephone,
ShopBusinessLicense businessLicense,
DescriptionVO? description = null,
EmailVO? email = null
)
{
_ownerId = ownerId;
_title = title;
_location = location;
_description = description;
_businessLicense = businessLicense;
_email = email;
_telephoneVO = telephone;
_shopStatus = ShopStatus.CreateNew(ShopStatusEnum.PendingApproval);
}
public static Shop CreateNew(MemberId ownerId,
TitleVO title,
ShopLocation location,
TelephoneVO telephone,
ShopBusinessLicense businessLicense,
DescriptionVO? description = null,
EmailVO? email = null)
{
return new Shop(ownerId, title, location, telephone, businessLicense, description, email);
}
public MemberId OwnerId => _ownerId;
public Management Management => _management;
public ShopLocation Location => _location;
public TitleVO Title => _title;
public DescriptionVO? Description => _description;
public EmailVO? Email => _email;
public TelephoneVO Telephone => _telephoneVO;
public ShopLogo Logo => _logo;
public ShopStatus Status => _shopStatus;
public ShopBusinessLicense BusinessLicense => _businessLicense;
public IReadOnlyList<Product> Products => _products;
public IReadOnlyList<ShippingMethod> ShippingMethods => _shippingMethods;
public IReadOnlyList<Member> Members => _members;
public void SetTitle(TitleVO title)
=> _title = title;
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Shops.Entities;
using Vizhvizh.GoldGallery.Domain.Shops.TypeIds;
namespace Vizhvizh.GoldGallery.Domain.Shops.Repositories;
public interface IShopRepository : IRepositoryBase<Shop, ShopId>
{
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Shops.TypeIds;
public class ShippingMethodId : TypedIdValueBase<int>
{
public ShippingMethodId(int value) : base(value)
{
}
}
@@ -0,0 +1,15 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Shops.TypeIds;
public class ShopId : TypedIdValueBase<long>
{
public ShopId(long value) : base(value)
{
}
public static implicit operator ShopId(long value)
=> new ShopId(value);
public static implicit operator long(ShopId value)
=> value.Value;
}
@@ -0,0 +1,19 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
public class ShippingMethodImage : ValueObject
{
public const short Limit = 150;
private ShippingMethodImage(string value)
{
if (value.Length > Limit)
throw new CharacterLimitException(nameof(ShippingMethodImage), Limit);
Value = value;
}
public static ShippingMethodImage CreateNew(string value)
=> new ShippingMethodImage(value);
public string Value { get; init; }
}
@@ -0,0 +1,31 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
/// <summary>
/// پروانه کسب
/// </summary>
public class ShopBusinessLicense : ValueObject
{
public const short ImageLimit = 150;
public const short CodeLimit = 50;
private ShopBusinessLicense(string image, string code)
{
if (image.Length > ImageLimit)
throw new CharacterLimitException("ShopBusinessLicenseImage", ImageLimit);
if (code.Length > CodeLimit)
throw new CharacterLimitException("ShopBusinessLicenseCode", CodeLimit);
Image = image;
Code = code;
}
public string Image { get; private set; }
public string Code { get; private set; }
public static ShopBusinessLicense CreateNew(string image, string code)
=> new ShopBusinessLicense(image, code);
}
@@ -0,0 +1,26 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
public class ShopLocation : ValueObject
{
public ShopLocation(double latitude, double longitude, int provinceId, int cityId, string address, string postalCode)
{
Latitude = latitude;
Longitude = longitude;
ProvinceId = provinceId;
CityId = cityId;
Address = address;
PostalCode = postalCode;
}
public static ShopLocation CreateNew(double latitude, double longitude, int provinceId, int cityId, string address, string postalCode)
=> new ShopLocation(latitude, longitude, provinceId, cityId, address, postalCode);
public double Latitude { get; private set; }
public double Longitude { get; private set; }
public int ProvinceId { get; private set; }
public int CityId { get; private set; }
public string Address { get; private set; }
public string PostalCode { get; private set; }
}
@@ -0,0 +1,19 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
public class ShopLogo : ValueObject
{
public const short Limit = 150;
private ShopLogo(string value)
{
if (string.IsNullOrWhiteSpace(value) || value.Length > Limit)
throw new CharacterLimitException(nameof(ShopLogo), Limit);
Value = value;
}
public static ShopLogo CreateNew(string value)
=> new ShopLogo(value);
public string? Value { get; init; }
}
@@ -0,0 +1,22 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
public class ShopStatus : ValueObject
{
public ShopStatus(ShopStatusEnum value)
{
Value = value;
}
public ShopStatusEnum Value { get; private set; }
public static ShopStatus CreateNew(ShopStatusEnum value)
=> new(value);
}
public enum ShopStatusEnum
{
Creating = 1,
PendingApproval,
Available,
}
@@ -0,0 +1,35 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Sliders.TypeIds;
using Vizhvizh.GoldGallery.Domain.Sliders.ValuesObjects;
namespace Vizhvizh.GoldGallery.Domain.Sliders.Entities;
public class Slider : Entity<SliderId>
{
private TitleVO _title;
private SliderImage _image;
private SliderUrl _url;
private SliderKey _key;
private Slider()
{
}
private Slider(TitleVO title, SliderImage image, SliderUrl url, SliderKey key)
{
_title = title;
_image = image;
_url = url;
_key = key;
}
public static Slider CreateNew(TitleVO title, SliderImage image, SliderUrl url, SliderKey key)
{
return new Slider(title, image, url, key);
}
public TitleVO Title => _title;
public SliderImage Image => _image;
public SliderUrl Url => _url;
public SliderKey Key => _key;
}
@@ -0,0 +1,11 @@
using Vizhvizh.GoldGallery.Domain.Resource.Shops;
using Vizhvizh.BuildingBlocks.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Sliders.Exceptions;
public class IsNullOrEmptySliderUrlException : ValueObjectValidationException
{
public IsNullOrEmptySliderUrlException() : base(ExceptionResources.IsNullOrEmptySliderUrlException)
{
}
}
@@ -0,0 +1,9 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.GoldGallery.Domain.Sliders.Entities;
using Vizhvizh.GoldGallery.Domain.Sliders.TypeIds;
namespace Vizhvizh.GoldGallery.Domain.Sliders.Repositories;
public interface ISliderRepository : IRepositoryBase<Slider, SliderId>
{
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Sliders.TypeIds;
public class SliderId : TypedIdValueBase<long>
{
public SliderId(long value) : base(value)
{
}
}
@@ -0,0 +1,20 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Sliders.ValuesObjects;
public class SliderImage : ValueObject
{
public const short Limit = 150;
private SliderImage(string value)
{
if (value.Length > Limit)
throw new CharacterLimitException(nameof(SliderImage), Limit);
Value = value;
}
public static SliderImage CreateNew(string value)
=> new SliderImage(value);
public string Value { get; init; }
}
@@ -0,0 +1,30 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Sliders.ValuesObjects;
public class SliderKey : ValueObject
{
public const short Limit = 150;
private SliderKey()
{
}
public SliderKey(SliderKeyType type, string? key)
{
Type = type;
Value = $"{type}/{key}";
if (Value.Length > Limit)
throw new CharacterLimitException(nameof(SliderKey), Limit);
}
public SliderKeyType Type { get; private set; }
public string Value { get; private set; }
}
public enum SliderKeyType
{
Main = 1,
Shop,
Category
}
@@ -0,0 +1,23 @@
using Vizhvizh.BuildingBlocks.Domain;
using Vizhvizh.Shared.Domain.Exceptions;
using Vizhvizh.GoldGallery.Domain.Sliders.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Sliders.ValuesObjects;
public class SliderUrl : ValueObject
{
public const short Limit = 150;
private SliderUrl(string value)
{
if (string.IsNullOrWhiteSpace(value))
throw new IsNullOrEmptySliderUrlException();
if(value.Length > Limit)
throw new CharacterLimitException(nameof(SliderUrl), Limit);
Value = value.Trim();
}
public static SliderUrl CreateNew(string value)
=> new SliderUrl(value);
public string Value { get; init; }
}
@@ -0,0 +1,36 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Users.TypeIds;
using Vizhvizh.GoldGallery.Domain.Users.ValueObjects;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.Entities;
public class Resource : Entity<ResourceId>
{
private List<Role> _roles;
private TitleVO _title;
private DescriptionVO _description;
private ModuleNameVO _moduleName;
private ResourceKey _resourceKey;
private Resource()
{
}
public Resource(TitleVO title, DescriptionVO description, ModuleNameVO moduleNames, ResourceKey resourceKey, List<Role> roles)
{
_description = description;
_title = title;
_moduleName = moduleNames;
_resourceKey = resourceKey;
_roles = roles;
}
public static Resource CreateNew(TitleVO title, DescriptionVO description, ModuleNameVO moduleNames, ResourceKey resourceKey, List<Role> roles)
=> new Resource(title, description, moduleNames, resourceKey, roles);
public TitleVO Title => _title;
public DescriptionVO Description => _description;
public ModuleNameVO ModuleName => _moduleName;
public ResourceKey ResourceKey => _resourceKey;
public IReadOnlyList<Role> Roles => _roles;
}
@@ -0,0 +1,26 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.Domain.Users.TypeIds;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.Entities;
public class Role : Entity<RoleId>
{
private TitleVO _title;
private List<RoleResource> _roleResources;
private Role()
{
}
private Role(TitleVO title, List<RoleResource> roleResources)
{
_title = title;
_roleResources = roleResources;
}
public static Role CreateNew(TitleVO title, List<RoleResource> roleResources)
=> new Role(title, roleResources);
public TitleVO Title => _title;
public IReadOnlyList<RoleResource> RoleResources => _roleResources;
}
@@ -0,0 +1,32 @@
using Vizhvizh.GoldGallery.Domain.Users.TypeIds;
using Vizhvizh.GoldGallery.Domain.Users.ValueObjects;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.Entities;
public class RoleResource : Entity<RoleResourceId>
{
private AccessLevel _accessLevel;
private User _user;
private Role _role;
private RoleResource()
{
}
private RoleResource(AccessLevel accessLevel, User user, Role role)
{
_accessLevel = accessLevel;
_user = user;
_role = role;
}
public static RoleResource CreateNew(AccessLevel accessLevel, User user, Role role)
=> new RoleResource(accessLevel, user, role);
public AccessLevel AccessLevel => _accessLevel;
public User User => _user;
public Role Role => _role;
}
@@ -0,0 +1,30 @@
using Vizhvizh.GoldGallery.Domain.Members.TypeIds;
using Vizhvizh.GoldGallery.Domain.Users.TypeIds;
using Vizhvizh.GoldGallery.Domain.Users.ValueObjects;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.Entities;
public class User : Entity<UserId>, IAggregateRoot
{
//private UserNationalCode _nationalCode;
private MemberId _memberId;
private List<Role> _roles;
private User()
{
}
private User(MemberId memberId, List<Role> roles)
{
_memberId = memberId;
_roles = roles;
}
public static User CreateNew(MemberId memberId, List<Role> roles)
=> new User(memberId, roles);
//public UserNationalCode NationalCode => _nationalCode;
public MemberId MemberId => _memberId;
public IReadOnlyList<Role> Roles => _roles;
}
@@ -0,0 +1,11 @@
using Vizhvizh.GoldGallery.Domain.Resource.Users;
using Vizhvizh.BuildingBlocks.Domain.Exceptions;
namespace Vizhvizh.GoldGallery.Domain.Users.Exceptions;
public class InvalidNationalCodeException : ValueObjectValidationException
{
public InvalidNationalCodeException() : base(ExceptionResources.InvalidNationalCodeException)
{
}
}
@@ -0,0 +1,11 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.TypeIds;
public class ResourceId : TypedIdValueBase<long>
{
public ResourceId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.TypeIds;
public class RoleId : TypedIdValueBase<int>
{
public RoleId(int value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.TypeIds;
public class RoleResourceId : TypedIdValueBase<long>
{
public RoleResourceId(long value) : base(value)
{
}
}
@@ -0,0 +1,10 @@
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.TypeIds;
public class UserId : TypedIdValueBase<long>
{
public UserId(long value) : base(value)
{
}
}
@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using Vizhvizh.GoldGallery.Domain.Resource.Users;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.ValueObjects;
public class AccessLevel : ValueObject
{
private AccessLevel(AccessLevelEnum value)
{
Value = (int)value;
}
public static AccessLevel CreateNew(AccessLevelEnum value)
=> new AccessLevel(value);
public int Value { get; init;}
}
public enum AccessLevelEnum
{
[Display(Name = nameof(ValueObjectResources.AccessLevelEnum_Write), ResourceType = typeof(ValueObjectResources))]
Write = 0,
[Display(Name = nameof(ValueObjectResources.AccessLevelEnum_Read), ResourceType = typeof(ValueObjectResources))]
Read = 1,
[Display(Name = nameof(ValueObjectResources.AccessLevelEnum_ReadWrite), ResourceType = typeof(ValueObjectResources))]
ReadWrite = 2
}
@@ -0,0 +1,20 @@
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.ValueObjects;
public class ResourceKey : ValueObject
{
private ResourceKey(ModuleNameVO module, TitleVO resourceTitle, params string[] parts)
{
Value = $"{module.Value}_{string.Join('.', parts)}_{resourceTitle.Value}";
}
public static ResourceKey CreateNew(string value)
{
string[] valueSplit = value.Split('_');
ModuleNamesEnum module = Enum.Parse<ModuleNamesEnum>(valueSplit[0]);
string[] paths = valueSplit[1]?.Split('.') ?? [];
return new ResourceKey(ModuleNameVO.CreateNew(module), TitleVO.CreateNew(valueSplit[2]), paths);
}
public string Value { get; init; }
}
@@ -0,0 +1,48 @@
using Vizhvizh.GoldGallery.Domain.Users.Exceptions;
using Vizhvizh.BuildingBlocks.Domain;
namespace Vizhvizh.GoldGallery.Domain.Users.ValueObjects;
public class UserNationalCode : ValueObject
{
public static bool IsValidNationalCode(string nationalCode)
{
if (nationalCode is null || nationalCode.Length > 10)
return false;
// تبدیل به آرایه
var arr = nationalCode.ToArray().Select(n => int.Parse(n.ToString()));
//بر عکس کردن اجزا
var arrReduce = arr.Reverse().ToList();
// بدست آوردن رقم کنترل اخر کد ملی
var numberControl = arrReduce.First();
arrReduce.RemoveAt(0);
// تمام 9 رقم سمت چپ کد ملی ضرب در موقعیت خودش میشه بعد همه جمع میشن بعدش تقسیم به یازده و باقی مانده رو میگیرم
//کد ملی 0700454713
//موقیعت 07 به ترتیب 9و10 هست از اونجایی ک ما رقم کنترل رو برداشتیم پس باید ایندکس ب اضافه ی 2 شه
var remaining = decimal.Parse($"{arrReduce.Select((n, i) => n * (i + 2)).Sum() % 11}");
if (remaining <= 2.0m)
{
if (numberControl == remaining)
return true;
else
return false;
}
else if (11m - remaining == numberControl)
return true;
else
return false;
}
public UserNationalCode(string value)
{
if (!IsValidNationalCode(value))
throw new InvalidNationalCodeException();
Value = value;
}
public string Value { get; init; }
}
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Members\Repositories\" />
<Folder Include="Members\Rules\" />
<Folder Include="Products\Events\" />
<Folder Include="Products\Rules\" />
<Folder Include="Shops\Events\" />
<Folder Include="Shops\Exceptions\" />
<Folder Include="Shops\Rules\" />
<Folder Include="Users\Events\" />
<Folder Include="Users\Repositories\" />
<Folder Include="Users\Rules\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Vichvich.Shared.Domain\Vizhvizh.Shared.Domain.csproj" />
<ProjectReference Include="..\Vizhvizh.GoldGallery.Domain.Resource\Vizhvizh.GoldGallery.Domain.Resource.csproj" />
</ItemGroup>
</Project>