Пример #1
0
        public ActionResult <string> PostNewestComment([FromBody] InsertCommentDTO insertCommentDTO)
        {
            InsertResultEnum resultEnum = this.dataAccess.AddCommentIfPermitted(insertCommentDTO);

            switch (resultEnum)
            {
            case InsertResultEnum.Success:
                return(new CreatedResult($"/product/{insertCommentDTO.ProductName}", insertCommentDTO.ProductName));

            case InsertResultEnum.NotPermitted:
                return(ValidationProblem("The latest comment id is not valid!"));

            default:
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a new comment to the given product if the provided latest comment Id is the same as in the Azure Table.
        /// </summary>
        public InsertResultEnum AddCommentIfPermitted(InsertCommentDTO insertDTO)
        {
            string latestStoredComment = GetLatestComment(insertDTO.ProductName);

            if (latestStoredComment.Equals(insertDTO.LatestComment))
            {
                try
                {
                    AddComment(insertDTO.ProductName, insertDTO.CommentContent);
                }
                catch (CommentsDemoException)
                {
                    return(InsertResultEnum.Failure);
                }

                return(InsertResultEnum.Success);
            }

            return(InsertResultEnum.NotPermitted);
        }
Пример #3
0
        public ActionResult <string> PostComment([FromBody] InsertCommentDTO insertCommentDTO)
        {
            this.dataAccess.AddComment(insertCommentDTO.ProductName, insertCommentDTO.CommentContent);

            return(new CreatedResult($"/product/{insertCommentDTO.ProductName}", insertCommentDTO.ProductName));
        }