// GET: ProfileController/Edit/5
        public ActionResult Edit(int id)
        {
            if (!_userProfileRepository.VerifyAdminStatus(GetCurrentUserProfileId()))
            {
                return(RedirectToAction("AccountChangedRecently", "UserProfile"));
            }
            var vm = new UserProfileAdminEditViewModel()
            {
                Profile = _userProfileRepository.GetById(id),
                Types   = _userProfileRepository.GetAllTypes(),
            };

            if (vm.Profile == null)
            {
                return(NotFound());
            }

            return(View(vm));
        }
        public ActionResult Edit(int id, UserProfile profile)
        {
            //Verify that the current user's Admin status hasn't changed recently
            if (!_userProfileRepository.VerifyAdminStatus(GetCurrentUserProfileId()))
            {
                return(RedirectToAction("AccountChangedRecently", "UserProfile"));
            }
            try
            {
                _userProfileRepository.UpdateUserProfile(profile);

                //if the submitted change was to demote a user, check to make sure they were not the last admin
                if (profile.UserTypeId == 2)
                {
                    var numOfAdmins = _userProfileRepository.CheckForAdmins();
                    if (numOfAdmins.Count == 0)
                    {
                        //Change the user type back to admin and re-submit
                        profile.UserTypeId = 1;
                        profile.IdIsActive = 0;
                        try
                        {
                            _userProfileRepository.UpdateUserProfile(profile);
                            return(RedirectToAction("LastAdminError", "UserProfile", profile));
                        }
                        catch
                        {
                            return(NotFound());
                        }
                    }
                }
                //Verify that the account to be deactivated is not the last Admin
                else if (profile.IdIsActive == 1)
                {
                    var numOfAdmins = _userProfileRepository.CheckForActiveAdmins();
                    if (numOfAdmins.Count == 0)
                    {
                        //Change the user type back to active and re-submit

                        profile.IdIsActive = 0;
                        try
                        {
                            _userProfileRepository.UpdateUserProfile(profile);
                            return(RedirectToAction("LastAdminDeactivateError", "UserProfile", profile));
                        }
                        catch
                        {
                            return(NotFound());
                        }
                    }
                }

                return(RedirectToAction("Index", "UserProfile"));
            }
            catch
            {
                var vm = new UserProfileAdminEditViewModel()
                {
                    Profile = profile,
                    Types   = _userProfileRepository.GetAllTypes(),
                };
                return(View(vm));
            }
        }