Add validation to prevent updates with duplicate national codes
This commit is contained in:
@@ -13,7 +13,7 @@ public class UpdateUserCommandHandler : IRequestHandler<UpdateUserCommand, Unit>
|
||||
{
|
||||
var entity = await _context.Users
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(User), request.Id);
|
||||
if (entity.NationalCode == request.NationalCode)
|
||||
if (!string.IsNullOrWhiteSpace(request.NationalCode) && entity.NationalCode == request.NationalCode)
|
||||
{
|
||||
throw new Exception("کد ملی تکراری است");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user