示例#1
0
        public ActionResult AreaNewCreate(string countryUrlPart, AreaNewViewModel m)
        {
            //-- this is a bit hacky to remove the validation required in step 1 and not have it cause out model to be invalid here.
            ModelState.Remove("locality");

            //-- Double check for duplicate
            var existingArea = geoSvc.GetArea(country.ID, m.Name.ToUrlFriendlyString());

            if (existingArea != default(Area))
            {
                ModelState.AddModelError("Name",
                                         string.Format("There is already an area with the name [{0}] in {1} listed in our database, if you are trying to add a city inside a province with the name name e.g. 'New York', change the name to 'New York, New York'",
                                                       m.Name, country.Name));
            }

            if (ModelState.IsValid)
            {
                var area = new Area();
                area.InjectFrom(m);
                area.Geo = SqlGeography.Parse(m.WKT);
                geoSvc.CreateArea(area);
                return(Redirect(area.SlugUrl));
            }
            else
            {
                InitializeAreaNewViewData(country, (CfType)m.TypeID, new List <Area>());
                m.locality = "DuplicateRetry";
                return(View("AreaNew", m));
            }
        }
        public ActionResult AreaNewCreate(string countryUrlPart, AreaNewViewModel m)
        {
            //-- this is a bit hacky to remove the validation required in step 1 and not have it cause out model to be invalid here.
            ModelState.Remove("locality");

            //-- Double check for duplicate
            var existingArea = geoSvc.GetArea(country.ID, m.Name.ToUrlFriendlyString());
            if (existingArea != default(Area))
            {
                ModelState.AddModelError("Name",
                    string.Format("There is already an area with the name [{0}] in {1} listed in our database, if you are trying to add a city inside a province with the name name e.g. 'New York', change the name to 'New York, New York'",
                        m.Name, country.Name));
            }

            if (ModelState.IsValid)
            {
                var area = new Area();
                area.InjectFrom(m);
                area.Geo = SqlGeography.Parse(m.WKT);
                geoSvc.CreateArea(area);
                return Redirect(area.SlugUrl);
            }
            else
            {
                InitializeAreaNewViewData(country, (CfType)m.TypeID, new List<Area>());
                m.locality = "DuplicateRetry";
                return View("AreaNew", m);
            }
        }