Ejemplo n.º 1
0
        private AnsweredNotificationViewModel GetAnsweredNotificationModel(Answer answer, bool seen)
        {
            var type = AnsweredNotificationViewModel.AnswerNotificationTypeEnum.OtherAnswers;
            if (IsCurrentUser(answer.QuestionDetail.AskedBy.UserName))
            {
                type = AnsweredNotificationViewModel.AnswerNotificationTypeEnum.CurrentUserAnswer;
            } else if (_notificationsService.IsCurrentFollowing(answer.User.UserName))
            {
                type = AnsweredNotificationViewModel.AnswerNotificationTypeEnum.FollowingAnswer;
            }

            var model = new AnsweredNotificationViewModel(answer, seen)
            {
                AnswerId = answer.AnswerId,
                QuestionDetailId = answer.QuestionDetailId,
                TimeStamp = answer.TimeStamp,
                AnswerNotificationType = type,
                AnsweringUser = GetProfileFor(answer.User),
                AskingUser = GetProfileFor(answer.QuestionDetail.AskedBy)
            };
            return model;
        }
Ejemplo n.º 2
0
 public Answer SaveAnswer(string answeringUserName, string content, int questionDetailId)
 {
     if (string.IsNullOrWhiteSpace(content))
     {
         return null;
     }
     var answeringUser = GetUserWithName(answeringUserName);
     if (answeringUser == null)
     {
         return null;
     }
     var questionDetail = _context.QuestionDetails.FirstOrDefault(qstDetail => qstDetail.QuestionDetailId == questionDetailId);
     if (questionDetail == null)
     {
         return null;
     }
     var answer = new Answer()
     {
         Content = content,
         Active = true,
         QuestionDetailId = questionDetailId,
         QuestionDetail = questionDetail,
         TimeStamp = DateTime.Now,
         User = answeringUser
     };
     try
     {
         using (var transaction = _context.Database.BeginTransaction())
         {
             questionDetail.Answered = true;
             questionDetail.SeenByUser = true;
             _context.Answers.Add(answer);
             _context.SaveChanges();
             answer.AddNotification();
             _context.SaveChanges();
             transaction.Commit();
             return answer;
         }
     }
     catch (Exception e)
     {
         return null;
     }
 }
Ejemplo n.º 3
0
 private List<CommentViewModel> ExtractFirstCommentViewModels(Answer answer)
 {
     var comments = answer.Comments.Where(comment => comment.Active).OrderBy(comment => comment.TimeStamp).Take(CommentPageSize);
     return GetCommentModels(comments.ToList());
 }
Ejemplo n.º 4
0
 private IQueryable<Comment> GetCommentsFor(Answer answer)
 {
     return _context.Comments.Where(cmnt => cmnt.AnswerId == answer.AnswerId && cmnt.Active);
 }
Ejemplo n.º 5
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
         }
     };
 }
Ejemplo n.º 6
0
 private ActionResult GetAnswerNotificationPartialView(Answer answer, bool seen)
 {
     var model = GetAnsweredNotificationModel(answer, seen);
     return PartialView("AnswerNotification", model);
 }