예제 #1
0
        public IActionResult Index(AppUserViewModel vm, string buttonValue)
        {
            bool retainEdit = false;

            switch (buttonValue)
            {
            case "Save":
                if (ModelState.IsValid)
                {
                    int userId = _AppUserRepo.SaveAppUser(vm.EditAppUser);
                    _AppUserRepo.DeleteUserRoles(userId);
                    foreach (var role in vm.EditAppUser.Roles.Where(x => x.Active))
                    {
                        _AppUserRepo.SaveUserRole(userId, role.Id);
                    }
                }
                else
                {
                    retainEdit = true;
                }
                break;

            case "Delete":
                _AppUserRepo.DeleteAppUser(vm.EditAppUser.UserId);
                break;
            }
            PrepAppUser(vm, retainEdit);
            return(View(vm));
        }