Ejemplo n.º 1
0
        public async Task <ActionResult <Commentary> > PostCommentary(int promotionId, [FromBody] Commentary commentary)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var commentaryCreated = await commentsService.AddCommentaryAsync(promotionId, commentary);

                return(Created($"/api/promotions/{promotionId}/comments/{commentary.id}", commentaryCreated));
            }
            catch (InvalidOperationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (NotFoundItemException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }