DocSas/PropertyService.Domain/ModelView/Users/UserProvider.cs
/// <summary>
/// login user as an asynchronous operation.
/// </summary>
/// <param name="user">The user.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
login user as an asynchronous operation.
login user as an asynchronous operation .
public async Task<DSCResponse> LoginUserAsync(UserVM user)
        {
            var msg = new Dictionary<string, string>();
            var response = new DSCResponse();
            var userEntity = await _userRepo.GetSingleAsync(x => x.Email.Equals(user.Email, StringComparison.OrdinalIgnoreCase));
            var userVerify = _appCommon.IsUserAccountValid(userEntity);
            if (userVerify.IsSuccess)
            {
                var isValid = SecurityManager.VerifyPassword(user.Password, userEntity.Password);
                if (isValid)
                {
                    UserSessionVM sessionVM = new UserSessionVM();
                    if (userEntity.IsActive.HasValue && !userEntity.IsActive.ToBool())
                    {
                        userEntity.IsActive = true;
                    }
                    userEntity.LastLogin = DateTime.UtcNow;
                    userEntity.LoginSessionId = Guid.NewGuid();
                    await _userRepo.ModifyAsync(userEntity);
                    var userVM = _mapper.Map<User, UserVM>(userEntity);
                    var utypes = await _userTypeRepo.GetSingleAsync(x => x.UserTypeEnum == userEntity.UserTypeEnum);
                    var userTypeVM = _mapper.Map<UserType, UserTypeVM>(utypes);
                    var userRole = await _appCommon.GetUserRoleAsync(userEntity);
                   var role = userRole.ResponseData as AvailableRoleVM;
                    if (role != null)
                    {
                        sessionVM.IsManager = role.HasManagementRights;
                        sessionVM.ManagementId = role.ManagementUserId;
                    }
                    if (userTypeVM != null)
                    {
                        sessionVM.UserTypeEnum = userTypeVM.UserTypeEnum;
                        sessionVM.UserTypeId = userTypeVM.Id;
                        sessionVM.UserTypeTitle = userTypeVM.Title;
                        sessionVM.NoPropertyRedirectPage = userTypeVM.NoPropertyRedirectPage;
                    }
                    userVM.Password = string.Empty;
                    userVM.UserSecurityAns = string.Empty;
                    sessionVM.UserVM = userVM;                   
                    response.ResponseData = sessionVM;
                }
                else
                {
                    msg.Add("InvalidAccount", "Invalid Account");
                }
            }
            else
            {
                msg = userVerify.ErrorMessage;
            }
            response.ErrorMessage = msg;
            return response;
        }
public async Task < DSCResponse > LoginUserAsync ( UserVM user ) { var msg = new Dictionary < string , string > ( ) ; var response = new DSCResponse ( ) ; var userEntity = await _userRepo . GetSingleAsync ( x => x . Email . Equals ( user . Email , StringComparison . OrdinalIgnoreCase ) ) ; var userVerify = _appCommon . IsUserAccountValid ( userEntity ) ; if ( userVerify . IsSuccess ) { var isValid = SecurityManager . VerifyPassword ( user . Password , userEntity . Password ) ; if ( isValid ) { UserSessionVM sessionVM = new UserSessionVM ( ) ; if ( userEntity . IsActive . HasValue && ! userEntity . IsActive . ToBool ( ) ) { userEntity . IsActive = true ; } userEntity . LastLogin = DateTime . UtcNow ; userEntity . LoginSessionId = Guid . NewGuid ( ) ; await _userRepo . ModifyAsync ( userEntity ) ; var userVM = _mapper . Map < User , UserVM > ( userEntity ) ; var utypes = await _userTypeRepo . GetSingleAsync ( x => x . UserTypeEnum == userEntity . UserTypeEnum ) ; var userTypeVM = _mapper . Map < UserType , UserTypeVM > ( utypes ) ; var userRole = await _appCommon . GetUserRoleAsync ( userEntity ) ; var role = userRole . ResponseData as AvailableRoleVM ; if ( role != null ) { sessionVM . IsManager = role . HasManagementRights ; sessionVM . ManagementId = role . ManagementUserId ; } if ( userTypeVM != null ) { sessionVM . UserTypeEnum = userTypeVM . UserTypeEnum ; sessionVM . UserTypeId = userTypeVM . Id ; sessionVM . UserTypeTitle = userTypeVM . Title ; sessionVM . NoPropertyRedirectPage = userTypeVM . NoPropertyRedirectPage ; } userVM . Password = string . Empty ; userVM . UserSecurityAns = string . Empty ; sessionVM . UserVM = userVM ; response . ResponseData = sessionVM ; } else { msg . Add ( " " , " " ) ; } } else { msg = userVerify . ErrorMessage ; } response . ErrorMessage = msg ; return response ; }
login user as an asynchronous operation.
login user as an asynchronous operation .
//Map //Clean
None
user
UserVM
None