public async Task <IActionResult> PostAsync([FromBody] CreateAnimalDto createAnimalDto) { var animal = await _animalService.CreateAnimal(_mapper.Map <Animal>(createAnimalDto)); var readAnimalDto = _mapper.Map <ReadAnimalDto>(animal); return(Created(nameof(GetAsync), new Response <ReadAnimalDto>(readAnimalDto))); }
public IActionResult CreateAnimal([FromBody] AnimalEntity animal) { if (animal == null) { return(BadRequest()); } _animalService.CreateAnimal(animal); return(Ok(animal)); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } await _animalservice.CreateAnimal(Animal); return(RedirectToPage("./Index")); }
public async Task <ActionResult <AnimalDto> > Create([FromBody] AnimalForCreationDto animalModel) { try { if (animalModel == null) { return(BadRequest()); } new AnimalModelValidator(animalModel).ValidateModel(); var animal = await _animalService.CreateAnimal(animalModel); return(Ok(animal)); } catch (ValidationException ex) { return(BadRequest(ex.ToString())); } catch (Exception ex) { return(BadRequest(ex.Message)); } }