예제 #1
0
        public async Task <JsonResult> AddCountry([Bind(Include = "Name, Abbreviation")] Country country)
        {
            bool CountryUnique = await _geoRepository.ValidateCountry(country);

            if (CountryUnique == false)
            {
                return(Json(new { success = false, responseText = "Country already exists!" }));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _geoRepository.AddCountry(country);

                    return(Json(new { success = true, responseText = "Ok" }));
                }
                catch (Exception ex)
                {
                    throw new HttpException("Unable to Add Country. " + ex);
                }
            }
            ModelState.AddModelError("Country", "Cannot add this Country.");
            return(Json(new { success = false, responseText = "Country error!" }));
        }