コード例 #1
0
 public ActionResult Report()
 {
     var model = new ReportCrueltyModel();
     var allCategories = CrueltySpotCategoriesService.Get(new CrueltySpotCategories()).CrueltySpotCategories;
     model.AllCrueltySpotCategories =
         allCategories.Select(csc => new KeyValuePair<int, string>(csc.Id, csc.Name)).ToList();
     model.AllCrueltySpotCategories.Insert(0, new KeyValuePair<int, string>(0, "-- Please Select --"));
     ViewBag.GoogleApiKey = AppHost.AppConfig.GoogleApiKey;
     return View(model);
 }
コード例 #2
0
        public JsonResult Report(ReportCrueltyModel model)
        {
            if (!ModelState.IsValid)
            {
                return Json(new { success = false, errors = ModelState.Keys.SelectMany(key => this.ModelState[key].Errors) });
            }

            var crueltySpot = new CrueltySpotDto();
            crueltySpot.Name = model.CrueltySpotPlace.Name;
            crueltySpot.Address = model.ExtractAddress();
            crueltySpot.City = model.ExtractCity();
            crueltySpot.StateProvinceAbbreviation = model.ExtractStateAbbreviation();
            crueltySpot.Zipcode = model.ExtractZipcode();
            crueltySpot.PhoneNumber = model.CrueltySpotPlace.formatted_phone_number;
            crueltySpot.WebpageUrl = model.CrueltySpotPlace.Website;
            crueltySpot.Latitude = model.CrueltySpotPlace.Lat;
            crueltySpot.Longitude = model.CrueltySpotPlace.Lng;
            crueltySpot.CrueltySpotCategoryId = model.CrueltySpotCategoryId;
            CrueltySpotService.Post(crueltySpot);

            var redirectUrl = Url.Action("Index", "CrueltySpots");
            return Json(new { success = true, redirectUrl = redirectUrl, statusCode = StatusCode.AddCrueltySpotSuccess });
        }