Generator Changes at 10/13/2025 8:08:52 AM
This commit is contained in:
@@ -4,10 +4,10 @@ public interface IApplicationDbContext
|
||||
{
|
||||
DbSet<UserAddress> UserAddresss { get; }
|
||||
DbSet<Package> Packages { get; }
|
||||
DbSet<UserOrder> UserOrders { get; }
|
||||
DbSet<Role> Roles { get; }
|
||||
DbSet<UserRole> UserRoles { get; }
|
||||
DbSet<OtpToken> OtpTokens { get; }
|
||||
DbSet<UserOrder> UserOrders { get; }
|
||||
DbSet<User> Users { get; }
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault;
|
||||
public record SetAddressAsDefaultCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault;
|
||||
public class SetAddressAsDefaultCommandHandler : IRequestHandler<SetAddressAsDefaultCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public SetAddressAsDefaultCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(SetAddressAsDefaultCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.UserAddresss
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserAddress), request.Id);
|
||||
|
||||
var entities = await _context.UserAddresss
|
||||
.Where(x => x.UserId == entity.UserId)
|
||||
.ToListAsync(cancellationToken);
|
||||
entities.ForEach(x => x.IsDefault = false);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
entity.IsDefault = true;
|
||||
_context.UserAddresss.Update(entity);
|
||||
entity.AddDomainEvent(new SetAddressAsDefaultEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault;
|
||||
public class SetAddressAsDefaultCommandValidator : AbstractValidator<SetAddressAsDefaultCommand>
|
||||
{
|
||||
public SetAddressAsDefaultCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<SetAddressAsDefaultCommand>.CreateWithOptions((SetAddressAsDefaultCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.EventHandlers;
|
||||
|
||||
public class SetAddressAsDefaultEventHandler : INotificationHandler<SetAddressAsDefaultEvent>
|
||||
{
|
||||
private readonly ILogger<SetAddressAsDefaultEventHandler> _logger;
|
||||
|
||||
public SetAddressAsDefaultEventHandler(ILogger<SetAddressAsDefaultEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(SetAddressAsDefaultEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,13 @@ public record CreateNewUserCommand : IRequest<CreateNewUserResponseDto>
|
||||
public string? AvatarPath { get; init; }
|
||||
//شناسه والد
|
||||
public long? ParentId { get; init; }
|
||||
//اعلان ایمیل
|
||||
public bool EmailNotifications { get; init; }
|
||||
//اعلان پیامک
|
||||
public bool SmsNotifications { get; init; }
|
||||
//اعلان پوش
|
||||
public bool PushNotifications { get; init; }
|
||||
//تاریخ تولد
|
||||
public DateTime? BirthDate { get; init; }
|
||||
|
||||
}
|
||||
@@ -5,6 +5,12 @@ public class CreateNewUserCommandValidator : AbstractValidator<CreateNewUserComm
|
||||
{
|
||||
RuleFor(model => model.Mobile)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.EmailNotifications)
|
||||
.NotNull();
|
||||
RuleFor(model => model.SmsNotifications)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PushNotifications)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
|
||||
@@ -15,5 +15,13 @@ public record UpdateUserCommand : IRequest<Unit>
|
||||
public bool IsRulesAccepted { get; init; }
|
||||
//تاریخ پذیرش قوانین
|
||||
public DateTime? RulesAcceptedAt { get; init; }
|
||||
//اعلان ایمیل
|
||||
public bool EmailNotifications { get; init; }
|
||||
//اعلان پیامک
|
||||
public bool SmsNotifications { get; init; }
|
||||
//اعلان پوش
|
||||
public bool PushNotifications { get; init; }
|
||||
//تاریخ تولد
|
||||
public DateTime? BirthDate { get; init; }
|
||||
|
||||
}
|
||||
@@ -7,6 +7,12 @@ public class UpdateUserCommandValidator : AbstractValidator<UpdateUserCommand>
|
||||
.NotNull();
|
||||
RuleFor(model => model.IsRulesAccepted)
|
||||
.NotNull();
|
||||
RuleFor(model => model.EmailNotifications)
|
||||
.NotNull();
|
||||
RuleFor(model => model.SmsNotifications)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PushNotifications)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
|
||||
@@ -30,4 +30,12 @@ public record GetAllUserByFilterQuery : IRequest<GetAllUserByFilterResponseDto>
|
||||
public bool? IsMobileVerified { get; set; }
|
||||
//تاریخ فعال سازی موبایل
|
||||
public DateTime? MobileVerifiedAt { get; set; }
|
||||
//اعلان ایمیل
|
||||
public bool? EmailNotifications { get; set; }
|
||||
//اعلان پیامک
|
||||
public bool? SmsNotifications { get; set; }
|
||||
//اعلان پوش
|
||||
public bool? PushNotifications { get; set; }
|
||||
//تاریخ تولد
|
||||
public DateTime? BirthDate { get; set; }
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ public class GetAllUserByFilterQueryHandler : IRequestHandler<GetAllUserByFilter
|
||||
.Where(x => request.Filter.ReferralCode == null || x.ReferralCode == request.Filter.ReferralCode)
|
||||
.Where(x => request.Filter.IsMobileVerified == null || x.IsMobileVerified == request.Filter.IsMobileVerified)
|
||||
.Where(x => request.Filter.ParentId == null || x.ParentId == request.Filter.ParentId)
|
||||
.Where(x => request.Filter.SmsNotifications == null || x.SmsNotifications == request.Filter.SmsNotifications)
|
||||
.Where(x => request.Filter.EmailNotifications == null || x.EmailNotifications == request.Filter.EmailNotifications)
|
||||
.Where(x => request.Filter.PushNotifications == null || x.PushNotifications == request.Filter.PushNotifications)
|
||||
.Where(x => request.Filter.BirthDate == null || x.BirthDate == request.Filter.BirthDate)
|
||||
;
|
||||
}
|
||||
return new GetAllUserByFilterResponseDto
|
||||
|
||||
@@ -28,4 +28,12 @@ public class GetAllUserByFilterResponseDto
|
||||
public bool IsMobileVerified { get; set; }
|
||||
//تاریخ فعال سازی موبایل
|
||||
public DateTime? MobileVerifiedAt { get; set; }
|
||||
//اعلان ایمیل
|
||||
public bool EmailNotifications { get; set; }
|
||||
//اعلان پیامک
|
||||
public bool SmsNotifications { get; set; }
|
||||
//اعلان پوش
|
||||
public bool PushNotifications { get; set; }
|
||||
//تاریخ تولد
|
||||
public DateTime? BirthDate { get; set; }
|
||||
}
|
||||
|
||||
@@ -21,5 +21,13 @@ public class GetUserResponseDto
|
||||
public bool IsMobileVerified { get; set; }
|
||||
//تاریخ فعال سازی موبایل
|
||||
public DateTime? MobileVerifiedAt { get; set; }
|
||||
//اعلان ایمیل
|
||||
public bool EmailNotifications { get; set; }
|
||||
//اعلان پیامک
|
||||
public bool SmsNotifications { get; set; }
|
||||
//اعلان پوش
|
||||
public bool PushNotifications { get; set; }
|
||||
//تاریخ تولد
|
||||
public DateTime? BirthDate { get; set; }
|
||||
|
||||
}
|
||||
@@ -13,5 +13,7 @@ public record CreateNewUserOrderCommand : IRequest<CreateNewUserOrderResponseDto
|
||||
public DateTime? PaymentDate { get; init; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; init; }
|
||||
//شناسه آدرس کاربر
|
||||
public long UserAddressId { get; init; }
|
||||
|
||||
}
|
||||
@@ -11,6 +11,8 @@ public class CreateNewUserOrderCommandValidator : AbstractValidator<CreateNewUse
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserAddressId)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
|
||||
@@ -15,5 +15,7 @@ public record UpdateUserOrderCommand : IRequest<Unit>
|
||||
public DateTime? PaymentDate { get; init; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; init; }
|
||||
//شناسه آدرس کاربر
|
||||
public long UserAddressId { get; init; }
|
||||
|
||||
}
|
||||
@@ -13,6 +13,8 @@ public class UpdateUserOrderCommandValidator : AbstractValidator<UpdateUserOrder
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserAddressId)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
|
||||
@@ -24,4 +24,6 @@ public record GetAllUserOrderByFilterQuery : IRequest<GetAllUserOrderByFilterRes
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long? UserId { get; set; }
|
||||
//شناسه آدرس کاربر
|
||||
public long? UserAddressId { get; set; }
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class GetAllUserOrderByFilterQueryHandler : IRequestHandler<GetAllUserOrd
|
||||
.Where(x => request.Filter.PaymentStatus == null || x.PaymentStatus == request.Filter.PaymentStatus)
|
||||
.Where(x => request.Filter.PaymentDate == null || x.PaymentDate == request.Filter.PaymentDate)
|
||||
.Where(x => request.Filter.UserId == null || x.UserId == request.Filter.UserId)
|
||||
.Where(x => request.Filter.UserAddressId == null || x.UserAddressId == request.Filter.UserAddressId)
|
||||
;
|
||||
}
|
||||
return new GetAllUserOrderByFilterResponseDto
|
||||
|
||||
@@ -22,4 +22,6 @@ public class GetAllUserOrderByFilterResponseDto
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
//شناسه آدرس کاربر
|
||||
public long UserAddressId { get; set; }
|
||||
}
|
||||
|
||||
@@ -15,5 +15,7 @@ public class GetUserOrderResponseDto
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
//شناسه آدرس کاربر
|
||||
public long UserAddressId { get; set; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user