Example #1
0
        public async Task <ActionResult> UpdateUserAccountPartial(UserAccountUpdateViewModel model, string command)
        {
            // Get selected user details
            var user = await _userManager.FindByIdAsync(model.UserId);

            // Validate if user exist
            if (user == null)
            {
                ModelState.AddModelError("", "User not found.");
                return(PartialView("_UpdateUserAccountPartial", model));
            }

            ViewBag.HttpMethod = Request.Method;

            // Check if command is update
            if (command == "Update")
            {
                if (ModelState.IsValid)
                {
                    // Update user details
                    user.Email    = model.Email;
                    user.IsActive = model.IsActive;


                    // Update user entry
                    var result = await _userManager.UpdateAsync(user);

                    // Check if entry update is successful
                    if (result.Succeeded)
                    {
                        //Return and notify success
                        return(PartialView("_SuccessUpdatePartial"));
                    }

                    AddErrors(result);
                }
            }

            // If command is delete
            if (command == "Delete")
            {
                // Delete user entry
                var result = await _userManager.DeleteAsync(user);

                // Check if entry delete is successful
                if (result.Succeeded)
                {
                    //Return and notify success
                    return(PartialView("_SuccessDeletePartial"));
                }

                AddErrors(result);
            }

            // Return the submitted data with error message
            return(PartialView("_UpdateUserAccountPartial", model));
        }
Example #2
0
        public async Task <ActionResult> UpdateUserAccountPartial(string id)
        {
            // Get the user account details
            var user = await _userManager.FindByIdAsync(id);

            // Validate if entry exist
            if (user == null)
            {
                return(PartialView("_FailureToLoadDataPartial"));
            }

            // Initialize the user account update view model
            var model = new UserAccountUpdateViewModel
            {
                UserId   = user.Id,
                Username = user.UserName,
                Email    = user.Email,
                IsActive = user.IsActive,
            };

            // Return the update form view
            return(PartialView("_UpdateUserAccountPartial", model));
        }