Exemple #1
0
        public ActionResult Edit(UserEditModel model)
        {
            if (ModelState.IsValid)
            {
                SubjectManager subjectManager = new SubjectManager();

                User user = subjectManager.GetUserById(model.UserId);

                if (model.Password == model.ConfirmPassword && model.Password != null)
                {
                    subjectManager.ChangePassword(user.Id, model.Password);
                }

                user.FullName = model.FullName;
                user.Email = model.Email;

                user.IsApproved = model.IsApproved;
                user.IsBlocked = model.IsBlocked;
                user.IsLockedOut = model.IsLockedOut;

                // removing
                long[] groups = user.Groups.Select(g => g.Id).ToArray();

                foreach (long groupId in groups)
                {
                    subjectManager.RemoveUserFromGroup(user.Id, groupId);
                }

                //adding
                if (Session["Groups"] != null)
                {
                    foreach (UserMembershipGridRowModel group in (UserMembershipGridRowModel[]) Session["Groups"])
                    {
                        if (group.IsUserInGroup)
                        {
                            subjectManager.AddUserToGroup(user.Id, group.Id);
                        }
                    }
                }

                subjectManager.UpdateUser(user);

                return Json(new { success = true });
            }
            else
            {
                return PartialView("_EditPartial", model);
            }
        }
Exemple #2
0
        public ActionResult MyAccount(MyAccountModel model)
        {
            if (!ModelState.IsValid) return View("MyAccount", model);

            SubjectManager subjectManager = new SubjectManager();

            User user = subjectManager.GetUserById(model.UserId);

            if (model.Password == model.ConfirmPassword && model.Password != null)
            {
                subjectManager.ChangePassword(user.Id, model.Password);
            }

            if (model.SecurityAnswer != null)
            {
                subjectManager.ChangeSecurityQuestionAndSecurityAnswer(user.Id, model.SecurityQuestionId, model.SecurityAnswer);
            }

            user.Email = model.Email;
            user.FullName = model.FullName;

            subjectManager.UpdateUser(user);

            return RedirectToAction("Index", "Home", new { area = "" });
        }