Exemplo n.º 1
0
 private ActionResult GetLikeResult(int answerId, LikesService likesService, bool result)
 {
     if (result)
     {
         if (Request.IsAjaxRequest())
         {
             var likesModel = likesService.GetLikeButtonViewModel(answerId);
             return PartialView("LikeButton", likesModel);
         }
         else
         {
             return RedirectToPrevious();
         }
     }
     return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
 }
Exemplo n.º 2
0
 private AnswerProfileViewModel GetAnswerModel(Answer answer, bool allComments)
 {
     var likesService = new LikesService(_context, _pageSize);
     var comments = allComments ? GetCommentModels(GetCommentsFor(answer).ToList()) : ExtractFirstCommentViewModels(answer);
     return new AnswerProfileViewModel()
     {
         Answer = answer,
         AnswerParagraphs = answer.Content.SplitLines(),
         QuestionParagraphs = answer.QuestionDetail.Question.Content.SplitLines(),
         AskerAvatarUrl = GetAvatarUrl(answer.QuestionDetail.AskedBy),
         ReplierAvatarUrl = GetAvatarUrl(answer.User),
         LikesModel = new AnswerLikeViewModel()
         {
             HasLiked = likesService.HasLikedAnswer(GetCurrentUserName(), answer.AnswerId),
             LikeCount = likesService.GetLikesCount(answer.AnswerId),
             AnswerId = answer.AnswerId
         },
         Comments = comments,
         CommentsMoreButton = new MoreButtonViewModel()
         {
             HasMore = !allComments
         }
     };
 }
Exemplo n.º 3
0
 public ActionResult ListLikedAnswers(string userName, int page = 1)
 {
     if (page < 1)
     {
         page = 1;
     }
     var likesService = new LikesService(Context, GetPageSize());
     if (_answersService.ExistsUser(userName))
     {
         var answers = likesService.GetLikedAnswerListProfileModel(userName, page);
         InitializeMoreButton(answers.AnswerList);
         if (Request.IsAjaxRequest())
         {
             return PartialView("AnswerList", answers.AnswerList);
         }
         else
         {
             if (answers.AnswerList.Answers.Any() == false)
             {
                 ViewBag.NoAnswersMessage = AnswerStrings.NoLikes;
                 ViewBag.Title = userName + " - " + AnswerStrings.NoLikesTitle;
                 return View("NoAnswers", answers.Profile);
             }
             ViewBag.Title = answers.Profile.ScreenName + AnswerStrings.Likes;
             ViewBag.HeaderImage = answers.Profile.HeaderUrl;
             return View("ProfileAnswerList", answers);
         }
     }
     else
     {
         return GetUserNotFoundError();
     }
 }
Exemplo n.º 4
0
 public ActionResult UnlikeAnswer(int answerId)
 {
     var likesService = new LikesService(Context, this.GetPageSize());
     var result = likesService.UnlikeAnswer(answerId);
     return GetLikeResult(answerId, likesService, result);
 }