Add validation to prevent updates with duplicate national codes

This commit is contained in:
masoodafar-web
2025-11-17 01:42:59 +03:30
parent 41fd6e1424
commit 08eba7c885

View File

@@ -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("کد ملی تکراری است");
}