/// <summary> /// delete the specie /// </summary> /// <param name="id">specie id</param> /// <returns>index view</returns> // POST: Species/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(new NotFoundViewResult("SpecieNotFound")); } var specie = await _specieRepository.GetByIdAsync(id.Value); if (specie == null) { return(new NotFoundViewResult("SpecieNotFound")); } var pets = await _petRepository.GetPetBySpecieAsync(id.Value); if (pets.Count > 0) { ModelState.AddModelError(string.Empty, "This specie can't be removed."); return(RedirectToAction(nameof(Index))); } try { await _specieRepository.DeleteAsync(specie); } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } return(RedirectToAction(nameof(Index))); }
// GET: SpeciesController/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(StatusCode(404, "Species not Found")); } var specie = await _specieRepository.GetSpecieWithBreedsAsync(id.Value); if (specie == null) { return(StatusCode(404, "Species not Found")); } await _specieRepository.DeleteAsync(specie); return(StatusCode(200, "Species successfully deleted")); }