DocSas/PropertyService.Domain/ModelView/Users/UserProvider.cs
/// <summary>
/// register user as an asynchronous operation.
/// </summary>
/// <param name="user">The user.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
register user as an asynchronous operation.
register user as an asynchronous operation .
public async Task<DSCResponse> RegisterUserAsync(UserVM user)
        {
            var isOperationSuccess = false;
            var msg = new Dictionary<string, string>();
            var response = new DSCResponse();
            var validUsers = await _userRepo.GetSingleAsync(x => x.Email.Equals(user.Email, StringComparison.OrdinalIgnoreCase));
            if (validUsers != null)
            {
                msg.Add("AccountAlreadyExist", "Account already registered.");
                response.ErrorMessage = msg;
                return response;
            }
            var entity = _mapper.Map<UserVM, User>(user);
            entity.UserSalt = SecurityManager.GenerateSalt();
            entity.Password = SecurityManager.HashPassword(entity.Password, entity.UserSalt);
            isOperationSuccess = await _userRepo.AddAsync(entity);
            if (isOperationSuccess)
            {
                var genResponse = await GenerateAndSendRegisterEmailAsync(entity);
                if (!genResponse.IsSuccess)
                {
                    msg = genResponse.ErrorMessage;
                }
            }
            response.ErrorMessage = msg;
            return response;
        }
public async Task < DSCResponse > RegisterUserAsync ( UserVM user ) { var isOperationSuccess = false ; var msg = new Dictionary < string , string > ( ) ; var response = new DSCResponse ( ) ; var validUsers = await _userRepo . GetSingleAsync ( x => x . Email . Equals ( user . Email , StringComparison . OrdinalIgnoreCase ) ) ; if ( validUsers != null ) { msg . Add ( " " , " " ) ; response . ErrorMessage = msg ; return response ; } var entity = _mapper . Map < UserVM , User > ( user ) ; entity . UserSalt = SecurityManager . GenerateSalt ( ) ; entity . Password = SecurityManager . HashPassword ( entity . Password , entity . UserSalt ) ; isOperationSuccess = await _userRepo . AddAsync ( entity ) ; if ( isOperationSuccess ) { var genResponse = await GenerateAndSendRegisterEmailAsync ( entity ) ; if ( ! genResponse . IsSuccess ) { msg = genResponse . ErrorMessage ; } } response . ErrorMessage = msg ; return response ; }
register user as an asynchronous operation.
register user as an asynchronous operation .
//validation //Map to Entity //generate password salt //hash password //Add User
None
user
UserVM
None