public ActionResult <PetTypeDTO> GetPetTypes(int id) { PetType petType; PetTypeDTO petTypeDTO; List <Pet> pets; try { petType = _petTypeService.SearchById(id); if (_petService.GetPets().Exists(pet => pet.PetTypeID == petType.ID)) { pets = _petService.GetPets().FindAll(pet => pet.PetTypeID == petType.ID); } else { pets = null; } petTypeDTO = new PetTypeDTO(petType.ID, petType.Name, pets); return(Ok(petTypeDTO)); } catch (InvalidDataException e) { return(BadRequest("Something went wrong with your request\n" + e.Message)); } catch (KeyNotFoundException e) { return(NotFound("Could not find requested petType\n" + e.Message)); } catch (DataBaseException e) { return(StatusCode(500, e.Message)); } }
public ActionResult <PetDTO> GetPets(int id) { Pet pet; PetDTO petDTO; try { pet = _petService.SearchById(id); if (pet.PreviousOwnerID != 0) { petDTO = new PetDTO(pet.ID, pet.Name, _petTypeService.SearchById(pet.PetTypeID), pet.BirthDate, pet.SoldDate, pet.Color, _ownerService.SearchById(pet.PreviousOwnerID), pet.Price); } else if (pet.PreviousOwnerID == 0) { petDTO = new PetDTO(pet.ID, pet.Name, _petTypeService.SearchById(pet.PetTypeID), pet.BirthDate, pet.SoldDate, pet.Color, null, pet.Price); } else { throw new DataBaseException("Something went very wrong"); } return(Ok(petDTO)); } catch (InvalidDataException e) { return(BadRequest("Something went wrong with your request\n" + e.Message)); } catch (KeyNotFoundException e) { return(NotFound("Could not find requested pet\n" + e.Message)); } catch (DataBaseException e) { return(StatusCode(500, e.Message)); } }
public ActionResult <PetType> GetPetTypes(int id) { try { return(Ok(_petTypeService.SearchById(id))); } catch (InvalidDataException e) { return(BadRequest("Something went wrong with your request\n" + e.Message)); } catch (KeyNotFoundException e) { return(NotFound("Could not find requested petType\n" + e.Message)); } catch (DataBaseException e) { return(StatusCode(500, e.Message)); } }