public ActionResult EditUniversityAdmin(UserViewModel model)
        {
            var errors = ModelState.Values.SelectMany(x => x.Errors, (state, error) => error.ErrorMessage).ToList();

            //For now the password field needs to be ignored, if there's only 1 error then it's the password
            if (errors.Count != 1)
            {
                var universities = _commonBusinessLogic.GetUniversitiesList();
                universities.Insert(0, new University()
                {
                    Name = "Select university", Id = 0
                });
                model.Universities = new SelectList(universities.Select(x => new SelectListItem()
                {
                    Text = x.Name, Value = x.Id.ToString(), Selected = model.UniversityId == x.Id
                }), "Value", "Text");
                return(View(model));
            }

            try
            {
                _adminBusinessLogic.UpdateUser(model, UserRoles.UniversityAdmin);
            }
            catch (FormValidationException e)
            {
                e.ValidationToModelState(ModelState);
                var universities = _commonBusinessLogic.GetUniversitiesList();
                universities.Insert(0, new University()
                {
                    Name = "Select university", Id = 0
                });
                model.Universities = new SelectList(universities.Select(x => new SelectListItem()
                {
                    Text = x.Name, Value = x.Id.ToString(), Selected = model.UniversityId == x.Id
                }), "Value", "Text");
                return(View(model));
            }

            return(RedirectToAction("UniversityAdmins"));
        }
示例#2
0
        public ActionResult PersonalInfo(UserViewModel model)
        {
            var errors = ModelState.Values.SelectMany(x => x.Errors, (state, error) => error.ErrorMessage).ToList();

            //For now the password field needs to be ignored, if there's only 1 error then it's the password
            if (errors.Count != 1)
            {
                return(View(model));
            }

            try
            {
                _adminBusinessLogic.UpdateUser(model, UserRoles.Student, User.Identity.GetUserId());
            }
            catch (FormValidationException e)
            {
                e.ValidationToModelState(ModelState);
                return(View(model));
            }

            return(RedirectToAction("Index", "Home"));
        }