public ActionResult Edit(int id, UPEditViewModel vm) { vm.UserProfile.Id = id; List <UserProfile> userProfiles = _UserProfileRepository.GetAllUsers(); int totalAdmins = userProfiles.Where(up => up.UserTypeId == 2).Count(); try { if (vm.UserProfile.UserTypeId == 1 && totalAdmins < 2) { vm.UserTypes = _UserTypeRepository.GetAllUserTypes(); ModelState.AddModelError("UserProfile.UserTypeId", "Assign another admin before changing the final Admin to author"); return(View(vm)); } else { _UserProfileRepository.ChangeUserType(vm.UserProfile); //return RedirectToAction("Index"); return(RedirectToAction("Index")); } } catch { vm.UserTypes = _UserTypeRepository.GetAllUserTypes(); return(View("Index")); } }