예제 #1
0
        public async Task <IActionResult> Edit([Bind("UserEntity, Roles")] UsersCreateUpdateViewModel model)
        {
            if (!UserIsAdmin())
            {
                return(Error("You need to be logged in as admin to do this."));
            }

            if (!ModelState.IsValid)
            {
                model.RoleDropDown = RoleDefaults();
                return(View(model));
            }

            if (model.UserEntity.Password != model.UserEntity.ConfirmPassword)
            {
                model.RoleDropDown   = RoleDefaults();
                ViewBag.errorMessage = "Password and Confirm Password fields must match!";
                return(View(model));
            }

            ActionObject _actionObject = await _accountActions.EditPost(model, User.Identity.Name);

            if (!_actionObject.Success)
            {
                return(Error(_actionObject.Message));
            }

            ViewBag.successMessage = "User details have been modified.";
            return(RedirectToAction("Index"));
        }