Пример #1
0
        public IActionResult CreateComment([FromBody] CommentViewModel c, int id)
        {
            var recipes = RecipeManager.Get(id);

            if (recipes == null)
            {
                return(NotFound("404: Not found."));
            }

            string        commenterId = User.Claims.FirstOrDefault(cl => cl.Type == "UserId").Value;
            List <string> errorCodes  = CommentsController.ControlComment(c, id, commenterId);

            if (errorCodes.Count > 0)
            {
                return(BadRequest(errorCodes));
            }

            var comment = RecipeManager.AddComment(id, commenterId, c);

            //return CreatedAtRoute("CreateComment", RecipeManager.AddComment(id, commenterId, c));
            return(CreatedAtRoute("GetComment", new { comment.Id }, comment));
        }