public IActionResult DeleteProvienceForCountry(Guid countryId, Guid id)
        {
            if (!_countryRepository.EntityExists(countryId))
            {
                return(NotFound());
            }

            var provienceFromRepo = _countryRepository.GetProvienceForCountry(countryId, id);

            if (provienceFromRepo == null)
            {
                return(NotFound());
            }



            if (_provienceRepository.DeleteAsync(provienceFromRepo) == null)
            {
                throw new Exception($"Deleting provience {id} for country {countryId} failed on save.");
            }

            _logger.LogInformation(100, $"Provience {id} for country {countryId} was deleted.");

            return(NoContent());
        }
Beispiel #2
0
        public IActionResult DeleteCountry(Guid id)
        {
            var countryFromRepo = _countryRepository.GetSingleAsync(id);

            if (countryFromRepo == null)
            {
                return(NotFound());
            }

            foreach (var provience in countryFromRepo.Result.AllProviences)
            {
                _provienceRepository.DeleteAsync(provience);
            }

            if (_countryRepository.DeleteAsync(countryFromRepo.Result).Result == null)
            {
                throw new Exception($"Deleting country {id} failed on save.");
            }
            return(NoContent());
        }