public IActionResult AddComment(String commentContent, String nutritionistId)
        {
            var userId = HttpContext.Session.GetInt32(ReadOnlyValues.UserIdSession);

            if (!userId.HasValue)
            {
                return(View(ReadOnlyValues.HomeLoginViewPath));
            }
            int nutritionistIdInt = Int32.Parse(nutritionistId);

            if (String.IsNullOrEmpty(commentContent) || nutritionistIdInt < 0 || commentContent.Trim().Length <= 0)
            {
                return(Detail(nutritionistIdInt));
            }
            else
            {
                CommentInsertModel comment = new CommentInsertModel()
                {
                    CommentContent = commentContent,
                    NutritionstId  = nutritionistIdInt,
                    UserId         = userId.Value,
                };
                var commentInsertModels = Post <bool>(MyApiRequestModel.PostAddComment, comment, withToken: true);
                var checkCommentInsertBaseResponseError = CheckBaseControllerError(commentInsertModels);
                if (checkCommentInsertBaseResponseError == null)
                {
                    return(Detail(nutritionistIdInt));
                }
                else
                {
                    return(Error(checkCommentInsertBaseResponseError));
                }
            }
        }
Пример #2
0
 public ActionResult <BaseResponseModel> PostAddComment([FromBody] CommentInsertModel commentInsertModel)
 {
     try
     {
         commentService.AddComment(commentInsertModel);
         return(new SuccessResponseModel <bool>(true));
     }
     catch (Exception ex)
     {
         return(new BaseResponseModel(ex.Message));
     }
 }
Пример #3
0
        public void AddComment(CommentInsertModel commentInsertModel)
        {
            Comment comment = mapper.Map <CommentInsertModel, Data.Entities.Comment>(commentInsertModel);

            commentRepository.Add(comment);
        }