Ejemplo n.º 1
0
        /// <summary>
        /// return value is user token for email confirmation of created user
        /// </summary>
        /// <param name="userModel"></param>
        /// <returns></returns>
        public string CreateUser(UserViewModel userModel)
        {
            try
            {
                ExceptionManager.WriteToEventLog(userModel.ToString(), "Application", System.Diagnostics.EventLogEntryType.Error);
                var addressId = addressRepository.AddNewAddress(userModel.AddressModel);
                userModel.AddressID = addressId;

                // store hashed and salted password
                string passwordHist = PasswordHash.CreateHash(userModel.Password);
                ExceptionManager.WriteToEventLog("passwordHist:" + passwordHist, "Application", System.Diagnostics.EventLogEntryType.Error);
                string userToken = WebSecurity.CreateUserAndAccount(userModel.UserName, userModel.Password,
                                                 propertyValues: new
                                                 {
                                                     FirstName = userModel.FirstName,
                                                     LastName = userModel.LastName,
                                                     AddressID = userModel.AddressID,
                                                     PreferredTimeZone = userModel.SelectedTimezone,
                                                     ModifiedBy = UserPrincipal.Current.UserId,
                                                     ModifiedOn = DateTime.UtcNow,
                                                     PasswordHist = passwordHist,
                                                     IsRegisterComplete = false
                                                 },
                                                 requireConfirmationToken: true);
                ExceptionManager.WriteToEventLog("usertoken:" + userToken, "Application", System.Diagnostics.EventLogEntryType.Error);
                //Roles.AddUsersToRole(new string[] { userModel.UserName }, userModel.SelectedRole);

                // retrieve roles from session and save update user roles
                var newRoles = SessionHelper.SessionExtract<List<string>>(SessionHelper.SESSION_KEY_NEW_ROLES);
                if (newRoles.Count > 0)
                    Roles.AddUserToRoles(userModel.UserName, newRoles.ToArray());                
                // retrieve lenders assigned to servicer if user is in role of servicer
                List<int> lenderIdsAssigned = new List<int>();
                List<string> FhasAssigned = new List<string>();
                if(newRoles.Contains("Servicer"))
                {
                    var lendersAssigned = SessionHelper.SessionExtract<IDictionary<int, string>>(SessionHelper.SESSION_KEY_NEW_LENDERS);
                    if (lendersAssigned != null)
                        lendersAssigned.ToList().ForEach(p => lenderIdsAssigned.Add(p.Key));
                }
                if(newRoles.Contains("LenderAccountRep"))
                {
                    var fhasSelected = SessionHelper.SessionExtract<IDictionary<string, string>>(SessionHelper.SESSION_KEY_LAR_FHA_LINKS);
                    if (fhasSelected != null)
                        fhasSelected.ToList().ForEach(p => FhasAssigned.Add(p.Key));
                }

                unitOfWork.Save();
                return userToken;
            }
            catch(Exception e)
            {
                throw new InvalidOperationException("Error happened while creating new user", e.InnerException);
            }            
        }
Ejemplo n.º 2
0
 public void UpdateUser(UserViewModel model)
 {
         addressRepository.UpdateAddress(model.AddressModel);
         userRepository.UpdateUser(model);
         ExceptionManager.WriteToEventLog(model.ToString(), "Application", System.Diagnostics.EventLogEntryType.Error);  
         unitOfWork.Save();         
 }