示例#1
0
        public async Task <Notification> Like(FeedLike feedlike)
        {
            if (CheckIsNotLogin())
            {
                return(null);
            }
            if (feedlike == null || feedlike.Feed == null)
            {
                return(null);
            }
            feedlike.LikedTimeUnix = Utils.GetUnixTime();
            string[] receiversId = null;
            if (feedlike.Feed.PostingAs == ActionAsType.Person)
            {
                receiversId = new string[] { feedlike.Feed.PersonId };
            }
            else if (feedlike.Feed.PostingAs == ActionAsType.Page)
            {
                //Get list page's admin
            }
            else if (feedlike.Feed.PostingAs == ActionAsType.Community)
            {
                //get list community's admin
            }
            FeedLike exist = await _feedLikeRepositoryM.Get(feedlike);

            if (exist == null)
            {
                await _feedLikeRepositoryM.Create(feedlike);
            }
            else
            {
                feedlike.Id = exist.Id;
                await _feedLikeRepositoryM.Update(feedlike);
            }
            if (!string.IsNullOrWhiteSpace(feedlike.Id))
            {
                await _postBroadcastPersonRepository.Like(feedlike.BroadCastId, feedlike.Liked);

                string code = Utils.GenerateNotifyCodeCount(feedlike);
                long   countOthersCommentator = await _notifyRepository.CountOthers(code, feedlike.Author.AuthorId, feedlike.PersonId);

                Notification notify = new Notification
                {
                    AuthorId          = feedlike.Author.AuthorId,
                    AuthorType        = (AuthorType)feedlike.Author.AuthorTypeId,
                    AuthorDisplayName = feedlike.Author.DisplayName,
                    NotifyType        = NotifyType.Like,
                    NotifyTimeUnix    = feedlike.LikedTimeUnix,
                    CommentId         = null,
                    FeedType          = feedlike.FeedType,
                    FeedId            = feedlike.FeedId,
                    ReceiversId       = receiversId,
                    TargetId          = feedlike.Feed.PostBy.AuthorId,
                    TargetType        = (NotificationTargetType)feedlike.Feed.PostingAs,
                    OthersCount       = countOthersCommentator
                };
                string       codeExist   = Utils.GenerateNotifyCodeExist(notify);
                Notification existNotifi = await _notifyRepository.GetByCodeExist(codeExist);

                notify.CodeCount = code;
                notify.CodeExist = codeExist;
                if (existNotifi == null)
                {
                    notify.Id = await _notifyRepository.Create(notify);
                }
                else
                {
                    notify.Id = existNotifi.Id;
                    await _notifyRepository.Update(notify);
                }
                await UpdateLikes(feedlike);

                return(notify);
            }
            return(null);
        }
示例#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);
        }