예제 #1
0
 public async Task <bool> UpdateComments(StatusPost post)
 {
     return(await m_StatuspostRepositoryM.UpdateComments(post.Id, true));
 }
예제 #2
0
        public async Task <Notification> Create(Comment comment)
        {
            if (comment == null || comment.Feed == null)
            {
                return(null);
            }
            string[] receiversId = null;
            if (comment.Feed.PostingAs == ActionAsType.Person)
            {
                receiversId = new string[] { comment.Feed.PersonId };
            }
            else if (comment.Feed.PostingAs == ActionAsType.Page)
            {
                //Get list page's admins
            }
            else if (comment.Feed.PostingAs == ActionAsType.Community)
            {
                //get list pcommunity's admin
            }
            comment.CommentTime     = DateTime.UtcNow;
            comment.CommentTimeUnix = Utils.GetUnixTime();

            string id = await _commentRepositoryM.Create(comment);

            if (!string.IsNullOrWhiteSpace(id))
            {
                comment.Id = id;
                await _statusPostRepository.UpdateComments(comment.FeedId, true);// update number of comment.

                string code = Utils.GenerateNotifyCodeCount(comment);
                long   countOthersCommentator = await _notifyRepository.CountOthers(code, comment.Commentator.AuthorId, comment.Feed.PersonId);

                Notification notify = new Notification
                {
                    AuthorId          = comment.Commentator.AuthorId,
                    AuthorType        = (AuthorType)comment.Commentator.AuthorTypeId,
                    AuthorDisplayName = comment.Commentator.DisplayName,
                    NotifyType        = NotifyType.Comment,
                    NotifyTimeUnix    = comment.CommentTimeUnix,
                    CommentId         = comment.Id,
                    FeedType          = comment.FeedType,
                    FeedId            = comment.FeedId,
                    ReceiversId       = receiversId,
                    TargetId          = comment.Feed.PostBy.AuthorId,
                    TargetType        = (NotificationTargetType)comment.Feed.PostingAs,
                    OthersCount       = countOthersCommentator
                };
                string codeExist = Utils.GenerateNotifyCodeExist(notify);
                notify.CodeCount = code;
                notify.CodeExist = codeExist;
                Notification exist = await _notifyRepository.GetByCodeExist(codeExist);

                if (exist == null)
                {
                    notify.Id = await _notifyRepository.Create(notify);
                }
                else
                {
                    notify.Id = exist.Id;
                    await _notifyRepository.Update(notify);
                }
                if (string.IsNullOrWhiteSpace(notify.Id))
                {
                    return(null);
                }
                return(notify);
            }
            return(null);
        }