Exemplo n.º 1
0
        public async Task <JsonResult> AddState([Bind(Include = "CountryID, Name, Abbreviation")] State state)
        {
            if (ModelState.IsValid)
            {
                bool StateUnique = await _geoRepository.ValidateStateUnique(state);

                if (StateUnique == false)
                {
                    return(Json(new { success = false, responseText = "State already exists for this Country!" }));
                }

                try
                {
                    await _geoRepository.AddState(state);

                    return(Json(new { success = true, responseText = "Ok" }));
                }
                catch (Exception ex)
                {
                    throw new HttpException("Unable to Add Country. " + ex);
                }
            }
            return(Json(new { success = false, responseText = "<b style='color:red'>Must enter country, name, and abbrev! </b>" }));
        }