Esempio n. 1
0
        public ActionResult Create()
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name +
                "\" visited AccountsManagement/Institution/Create");

            var model = new viewModels.CreateInstitutionViewModel();
            return View(model);
        }
Esempio n. 2
0
        public ActionResult Create()
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name +
                         "\" visited AccountsManagement/Institution/Create");

            var model = new viewModels.CreateInstitutionViewModel();

            return(View(model));
        }
Esempio n. 3
0
        public ActionResult Create(viewModels.CreateInstitutionViewModel Model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    Country country = repository
                                      .Country
                                      .FirstOrDefault(c => c.CountryID == Model.CountryID);
                    if (country == null)
                    {
                        ModelState.AddModelError("Country", "Страна не существует в базе");
                        return(View(Model));
                    }

                    City city = repository
                                .City
                                .FirstOrDefault(c => c.CityID == Model.CityID && c.CountryID == Model.CountryID);
                    if (city == null)
                    {
                        ModelState.AddModelError("City", "Город не существует в базе");
                        return(View(Model));
                    }

                    Institution institution = repository
                                              .Institutions
                                              .FirstOrDefault(i => i.Name == Model.Institution && i.CityID == city.CityID);
                    if (institution != null)
                    {
                        ModelState.AddModelError("Institution", "Образовательное учреждение с таким именем уже существует");
                        return(View(Model));
                    }

                    institution = new Institution()
                    {
                        Name   = Model.Institution,
                        CityID = city.CityID
                    };

                    int userID = WebSecurity.CurrentUserId;
                    if (userID != 1)
                    {
                        UserProfile user = repository.Users.FirstOrDefault(u => u.UserId == userID);
                        institution.UsersCanModify = new List <UserProfile>();
                        institution.UsersCanModify.Add(user);
                    }
                    int institutionID = repository.AddInstitution(institution);

                    logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name +
                                "\" create institution \"" + institutionID + "\"");
                    TempData["SuccessMessage"] = "Образовательное учреждение (организация) успешно создано(а)!";
                    return(RedirectToAction("Create"));
                }
                catch (MembershipCreateUserException ex)
                {
                    logger.Warn("Error occured on user " + WebSecurity.GetUserId(User.Identity.Name) +
                                " \"" + User.Identity.Name + "\" institution creating: ", ex);
                    TempData["ErrorMessage"] = "Произошла ошибка при создании образовательного учреждения (организации)";
                }
            }

            return(View(Model));
        }