public async Task <PetModel> AddNewPet(AddNewPetViewModel model) { try { var dbModel = _mapper.Map <Domain.Models.Pet>(model); await _context.Pets.AddAsync(dbModel); await _context.SaveChangesAsync(); return(_mapper.Map <PetModel>(dbModel)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> AddPet([FromBody] AddNewPetViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _petService.AddNewPet(model); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }