コード例 #1
0
ファイル: CityController.cs プロジェクト: solomon00/judge
        public ActionResult Create()
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name +
                "\" visited AccountsManagement/City/Create");

            var model = new viewModels.CreateCityViewModel();
            return View(model);
        }
コード例 #2
0
        public ActionResult Create(viewModels.CreateCityViewModel 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.Name == Model.City && c.Area == Model.Area && c.Region == Model.Region && c.CountryID == country.CountryID);
                    if (city != null)
                    {
                        ModelState.AddModelError("City", "Город (населенный пункт) с таким именем уже существует");
                        return(View(Model));
                    }

                    city = new City()
                    {
                        Name      = Model.City,
                        Area      = Model.Area,
                        Region    = Model.Region,
                        CountryID = country.CountryID
                    };

                    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 cityID = repository.AddCity(city);

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

            return(View(Model));
        }
コード例 #3
0
        public ActionResult Create()
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name +
                         "\" visited AccountsManagement/City/Create");

            var model = new viewModels.CreateCityViewModel();

            return(View(model));
        }