/// <inheritdoc/> public async Task <AppUser> RegisterUserAsync(string email, string fullname, string username, string password, int?affiliatorId = null) { var isUserExists = await _usersRepository.AnyAsync(x => x.Email == email || x.UserName == username); if (isUserExists) { throw new UserManagementException("User already exists"); } var affiliatorExistance = affiliatorId.HasValue && (await GetUserById(affiliatorId.Value)) != null; var newUser = new AppUser { Email = email, UserName = username, FullName = fullname, AffiliateUserId = affiliatorExistance ? affiliatorId : null }; var result = await _userManager.CreateAsync(newUser, password); if (result.Succeeded) { newUser = await GetUserByUserName(username); return(newUser); } throw new UserManagementException(String.Join(',', result.Errors)); }
public async Task <BlResult <bool> > UserExists(string email) { var result = new BlResult <bool>(); if (string.IsNullOrWhiteSpace(email)) { throw new ArgumentNullException(nameof(email)); } var exists = await _usersRepository.AnyAsync(x => x.Email == email.ToLower(Thread.CurrentThread.CurrentCulture)); result.Success(exists); return(result); }