コード例 #1
0
        public IActionResult DeleteCountry(int countryId)
        {
            if (!_countryRepo.isExists(countryId))
            {
                return(NotFound());
            }

            var country = _countryRepo.GetCountry(countryId);

            if (_countryRepo.GetAuthoresFromCountry(countryId).Count() > 0)
            {
                ModelState.AddModelError("", $"Sorry we can't delete country{country.Name} while at least has one Author");
                return(StatusCode(409, ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_countryRepo.DeleteCaountry(country))
            {
                ModelState.AddModelError("", $"Sorry we can't delete country{country.Name} somthing went wrong");
                return(StatusCode(500, ModelState));
            }
            return(NoContent());
        }