예제 #1
0
        public bool EditUserEmail(ProfileEmailEditViewModel model)
        {
            if (!string.IsNullOrEmpty(model.Email))
            {
                var userManager = UserManager.GetManager(SecurityManager.GetUser(model.UserId).ProviderName);
                var user        = userManager.GetUser(model.UserId);

                if (!userManager.ValidateUser(user, model.Password))
                {
                    return(false);
                }

                if (user.Email != model.Email)
                {
                    user.Email = model.Email;

                    if (this.AllowCurrentProfileUpdates && SecurityManager.GetCurrentUserId() == user.Id)
                    {
                        using (new ElevatedModeRegion(userManager))
                        {
                            userManager.SaveChanges();
                        }
                    }
                    else
                    {
                        userManager.SaveChanges();
                    }

                    return(true);
                }

                return(false);
            }

            return(false);
        }
예제 #2
0
        public bool EditUserEmail(ProfileEmailEditViewModel model)
        {
            if (!string.IsNullOrEmpty(model.Email))
            {
                var userManager = UserManager.GetManager(SecurityManager.GetUser(model.UserId).ProviderName);
                var user        = userManager.GetUser(model.UserId);

                if (!userManager.ValidateUser(user, model.Password))
                {
                    return(false);
                }

                if (user.Email != model.Email)
                {
                    user.Email = model.Email;
                    userManager.SaveChanges();
                    return(true);
                }

                return(false);
            }

            return(false);
        }