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)); } }
/// <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); }
public ActionResult <string> PostComment([FromBody] InsertCommentDTO insertCommentDTO) { this.dataAccess.AddComment(insertCommentDTO.ProductName, insertCommentDTO.CommentContent); return(new CreatedResult($"/product/{insertCommentDTO.ProductName}", insertCommentDTO.ProductName)); }