Skip to content

Commit

Permalink
Core: UpdateUserCommandHandler: Added username and email uniqueness r…
Browse files Browse the repository at this point in the history
…equirement
  • Loading branch information
Xian55 committed Jan 4, 2024
1 parent 0aeb485 commit 872d025
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public async Task<Result> Handle(UpdateUserCommand request, CancellationToken ca
return Result.Failure(ValidationErrors.User.NotFound);
}

bool userNameAlreadyTaken = _dbContext.Set<User>().Where(x => x.Username == request.Username).Any();
if (userNameAlreadyTaken)
{
return Result.Failure(Domain.Core.Errors.DomainErrors.User.UserNameMustBeUnique);
}

bool emailAlreadyTaken = _dbContext.Set<User>().Where(x => x.Email == request.Email).Any();
if (emailAlreadyTaken)
{
return Result.Failure(Domain.Core.Errors.DomainErrors.User.EmailMustBeUnique);
}

User user = maybeUser.Value;

Result updatedResult = user.Update(
Expand Down

0 comments on commit 872d025

Please sign in to comment.