예제 #1
0
 private void _markMyReplies(GanjoorCommentSummaryViewModel parent, Guid userId)
 {
     foreach (var reply in parent.Replies)
     {
         reply.MyComment = reply.UserId == userId;
         _markMyReplies(reply, userId);
     }
 }
예제 #2
0
 public _CommentPartialModel GetCommentModel(GanjoorCommentSummaryViewModel comment)
 {
     return(new _CommentPartialModel()
     {
         Comment = comment,
         Error = "",
         InReplyTo = null,
         LoggedIn = LoggedIn,
         DivSuffix = $"-{comment.CoupletIndex}"
     });
 }
 public _CommentPartialModel GetCommentModel(GanjoorCommentSummaryViewModel comment)
 {
     return(new _CommentPartialModel()
     {
         Comment = comment,
         Error = "",
         InReplyTo = Comment,
         LoggedIn = LoggedIn,
         DivSuffix = DivSuffix
     });
 }
예제 #4
0
        /// <summary>
        /// comment
        /// </summary>
        /// <param name="comment"></param>
        /// <param name="poemId"></param>
        /// <param name="inReplytoId"></param>
        /// <returns></returns>
        public async Task <ActionResult> OnPostComment(string comment, int poemId, int inReplytoId)
        {
            using (HttpClient client = new HttpClient())
            {
                if (await GanjoorSessionChecker.PrepareClient(client, Request, Response))
                {
                    var stringContent = new StringContent(
                        JsonConvert.SerializeObject
                        (
                            new GanjoorCommentPostViewModel()
                    {
                        HtmlComment = comment,
                        InReplyToId = inReplytoId == 0 ? null : inReplytoId,
                        PoemId      = poemId
                    }
                        ),
                        Encoding.UTF8, "application/json");
                    var response = await client.PostAsync($"{APIRoot.Url}/api/ganjoor/comment", stringContent);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        GanjoorCommentSummaryViewModel resComment = JsonConvert.DeserializeObject <GanjoorCommentSummaryViewModel>(await response.Content.ReadAsStringAsync());


                        return(new PartialViewResult()
                        {
                            ViewName = "_CommentPartial",
                            ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
                            {
                                Model = new _CommentPartialModel()
                                {
                                    Comment = resComment
                                }
                            }
                        });
                    }
                    else
                    {
                        return(new PartialViewResult()
                        {
                            ViewName = "_CommentPartial",
                            ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
                            {
                                Model = new _CommentPartialModel()
                                {
                                    Comment = null,
                                    Error = await response.Content.ReadAsStringAsync()
                                }
                            }
                        });
                    }
                }
                else
                {
                    return(new PartialViewResult()
                    {
                        ViewName = "_CommentPartial",
                        ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
                        {
                            Model = new _CommentPartialModel()
                            {
                                Comment = null,
                                Error = "لطفا از گنجور خارج و مجددا به آن وارد شوید."
                            }
                        }
                    });
                }
            }
        }