示例#1
0
        public async Task <IActionResult> AddCountry([FromBody] CountryDTO country)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid input"));
            }

            Country newCountry = new Country()
            {
                name   = country.name,
                cities = country.cities
            };

            if (_countryRepository.CheckIfExists(newCountry))
            {
                return(Conflict("Country already exists"));
            }

            bool created = await _countryRepository.Add(newCountry);

            if (created)
            {
                return(Created("", newCountry));
            }

            return(Conflict());
        }