Generator Changes at 11/12/2025 1:32:03 AM +03:30
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.UpdateUserWalletChangeLog;
|
||||
public record UpdateUserWalletChangeLogCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
//شناسه کیف پول
|
||||
public long WalletId { get; init; }
|
||||
//موجودی
|
||||
public long CurrentBalance { get; init; }
|
||||
//تغییر موجودی
|
||||
public long ChangeValue { get; init; }
|
||||
//افزایشی؟
|
||||
public bool IsIncrease { get; init; }
|
||||
//شناسه ارجاع
|
||||
public long? RefrenceId { get; init; }
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.UpdateUserWalletChangeLog;
|
||||
public class UpdateUserWalletChangeLogCommandHandler : IRequestHandler<UpdateUserWalletChangeLogCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public UpdateUserWalletChangeLogCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdateUserWalletChangeLogCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.UserWalletChangeLogs
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserWalletChangeLog), request.Id);
|
||||
request.Adapt(entity);
|
||||
_context.UserWalletChangeLogs.Update(entity);
|
||||
entity.AddDomainEvent(new UpdateUserWalletChangeLogEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.UpdateUserWalletChangeLog;
|
||||
public class UpdateUserWalletChangeLogCommandValidator : AbstractValidator<UpdateUserWalletChangeLogCommand>
|
||||
{
|
||||
public UpdateUserWalletChangeLogCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
RuleFor(model => model.WalletId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.CurrentBalance)
|
||||
.NotNull();
|
||||
RuleFor(model => model.ChangeValue)
|
||||
.NotNull();
|
||||
RuleFor(model => model.IsIncrease)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateUserWalletChangeLogCommand>.CreateWithOptions((UpdateUserWalletChangeLogCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user