public IActionResult CreateAnimal([FromBody] AnimalDto animal) { if (animal == null) { _logger.LogInformation($"No animal for creation. {animal} was provided."); return(BadRequest($"No animal for creation. null was provided.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newAnimal = Mapper.Map <Entities.Animal>(animal); _animalInfoRepository.AddAnimal(newAnimal); // If animal is successfully created, map the animal info to Data transfer Object to return if (!_animalInfoRepository.Save()) { return(StatusCode(500, $"{newAnimal} was not saved succesfully.")); } var successfullyCreatedAnimal = Mapper.Map <Models.AnimalDto>(newAnimal); return(CreatedAtRoute("GetAnimal", new { id = newAnimal.Id }, successfullyCreatedAnimal)); }
private void CreateAdopter(AdopterDto adopter) { var currentAdopters = _animalInfoRepository.GetAdopters(); newAdopter = Mapper.Map <Adopter>(adopter); _animalInfoRepository.AddAdopter(newAdopter); if (_animalInfoRepository.Save()) { newAdopterId = newAdopter.Id; } }