예제 #1
0
        private async Task <ViewWordViewModel> GetWordDetailsVM(string currentUserId, string wordId)
        {
            // get current word info
            Word currentWord = await this.m_learnWordService.GetWordByIdAsync(wordId);

            // Current page index, default by 1
            // Get comments
            IList <WordComment> wordComments = await this.m_commentService
                                               .GetWordCommentsAsync(wordId, currentUserId, 1, NUMBER_OF_COMMENTS_PER_PAGE);

            // Convert to comment view model
            IList <WordCommentViewModel> comments = new List <WordCommentViewModel>();

            // Mapping
            foreach (WordComment wordComment in wordComments)
            {
                WordCommentViewModel comment = new WordCommentViewModel
                {
                    Comment       = wordComment,
                    IsLiked       = await this.m_commentService.IsLikedCommentAsync(currentUserId, wordComment.Id),
                    IsAllowDelete = currentUserId == wordComment.UserId ? true : false,
                };
                comments.Add(comment);
            }
            // Create view model
            ViewWordViewModel model = new ViewWordViewModel(comments, currentWord);

            return(model);
        }
예제 #2
0
        public async Task <ActionResult> InterestedFilter(string wordId)
        {
            // Set filter type
            Session["FilterType"] = "Votes";
            // Get user id
            string currentUserId = User.Identity.GetUserId();
            // get all word comment, order by date
            IList <WordComment> wordComments = await this.m_commentService
                                               .GetWordCommentsAsync(wordId, currentUserId, 1, NUMBER_OF_COMMENTS_PER_PAGE, "Votes");

            // create list comment model
            IList <WordCommentViewModel> comments = new List <WordCommentViewModel>();

            foreach (WordComment wordComment in wordComments)
            {
                WordCommentViewModel comment = new WordCommentViewModel
                {
                    Comment       = wordComment,
                    IsLiked       = await this.m_commentService.IsLikedCommentAsync(currentUserId, wordComment.Id),
                    IsAllowDelete = currentUserId == wordComment.UserId ? true : false,
                };
                comments.Add(comment);
            }
            // Updatge partial view
            ListWordCommentViewModel cmms = new ListWordCommentViewModel(comments);

            return(PartialView("_ListWordCommentPartial", cmms));
        }
예제 #3
0
        public async Task <ActionResult> GetMoreCommentItems(string wordId, int page)
        {
            string filterType = "";

            if (Session["FilterType"] != null)
            {
                filterType = Session["FilterType"].ToString();
            }
            else
            {
                filterType = "Date";
            }
            string currentUserId = User.Identity.GetUserId();

            if (filterType == "Votes")
            {
                // Select Interested
                IList <WordComment> wordComments = await this.m_commentService
                                                   .GetWordCommentsAsync(wordId, currentUserId, page, NUMBER_OF_COMMENTS_PER_PAGE, "Votes");

                IList <WordCommentViewModel> comments = new List <WordCommentViewModel>();
                foreach (WordComment wordComment in wordComments)
                {
                    WordCommentViewModel comment = new WordCommentViewModel
                    {
                        Comment       = wordComment,
                        IsLiked       = await this.m_commentService.IsLikedCommentAsync(currentUserId, wordComment.Id),
                        IsAllowDelete = currentUserId == wordComment.UserId ? true : false,
                    };
                    comments.Add(comment);
                }
                // Update partial view
                ListWordCommentViewModel cmms = new ListWordCommentViewModel(comments);
                // Update partial view
                return(PartialView("_ListWordCommentPartial", cmms));
            }
            else
            {
                // Select DateTime
                IList <WordComment> wordComments = await this.m_commentService
                                                   .GetWordCommentsAsync(wordId, currentUserId, page, NUMBER_OF_COMMENTS_PER_PAGE);

                IList <WordCommentViewModel> comments = new List <WordCommentViewModel>();
                foreach (WordComment wordComment in wordComments)
                {
                    WordCommentViewModel comment = new WordCommentViewModel
                    {
                        Comment = wordComment,
                        IsLiked = await this.m_commentService.IsLikedCommentAsync(currentUserId, wordComment.Id),
                    };
                    comments.Add(comment);
                }
                if (comments.Count > 0)
                {
                    ListWordCommentViewModel cmms = new ListWordCommentViewModel(comments);
                    // Update partial view
                    return(PartialView("_ListWordCommentPartial", cmms));
                }
                else
                {
                    string end = "end";
                    return(Json(end, JsonRequestBehavior.AllowGet));
                }
            }
        }