public async Task <ActionResult <FoodRelationDto> > Get([FromRoute] Guid id) { FoodRelationDto foodRelation = _mapper.Map <FoodRelationDto>(await _foodRelationService.GetByIdAsync(id)); if (foodRelation == null) { return(NotFound()); } return(Ok(foodRelation)); }
public async Task <ActionResult <FoodRelationDto> > Put([FromRoute] Guid id, [FromBody] FoodRelationDto foodRelation) { foodRelation.Id = id; try { return(Ok(_mapper.Map <FoodRelationDto>(await _foodRelationService.EditAsync(_mapper.Map <FoodRelation>(foodRelation))))); } catch (ApiException ex) { return(StatusCode(ex.StatusCode, new { error = true, message = ex.Message })); } }
public async Task <ActionResult <FoodRelationDto> > Post([FromBody] FoodRelationCreateDto foodRelation) { if (ModelState.IsValid) { try { FoodRelationDto newFoodRelation = _mapper.Map <FoodRelationDto>( await _foodRelationService.AddAsync(_mapper.Map <FoodRelation>(foodRelation)) ); return(CreatedAtAction("Get", new { id = newFoodRelation.Id }, newFoodRelation)); } catch (ApiException ex) { return(StatusCode(ex.StatusCode, new { error = true, message = ex.Message })); } } return(BadRequest()); }