Exemplo n.º 1
0
        public ActionResult NewUniversityAdmin(UserViewModel user)
        {
            var universities = _commonBusinessLogic.GetUniversitiesList();

            if (ModelState.IsValid)
            {
                try
                {
                    _adminBusinessLogic.CreateNewUniAdmin(user, UserRoles.UniversityAdmin);
                }
                catch (FormValidationException e)
                {
                    e.ValidationToModelState(ModelState);
                    universities.Insert(0, new University()
                    {
                        Name = "Select university", Id = 0
                    });
                    user.Universities = new SelectList(universities.Select(x => new SelectListItem()
                    {
                        Text = x.Name, Value = x.Id.ToString()
                    }), "Value", "Text");
                    return(View(user));
                }

                return(RedirectToAction("UniversityAdmins"));
            }
            universities.Insert(0, new University()
            {
                Name = "Select university", Id = 0
            });
            user.Universities = new SelectList(universities.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Id.ToString(), Selected = user.UniversityId == x.Id
            }), "Value", "Text");
            return(View(user));
        }