Exemple #1
0
        public async Task FollowUserAsync(string userId, string followedUserId)
        {
            var me = await _repo.Users.FirstOrDefaultAsync(m => m.Id == userId, query => query.Include(m => m.Users));

            var user = await _repo.Users.FirstOrDefaultAsync(m => m.Id == followedUserId);

            if (me.Users.All(m => m.Id != user.Id))
            {
                me.Users.Add(user);
                await _repo.Users.AddOrUpdateAndSaveAsync(me);

                var metaData = new Dictionary <string, string>();
                metaData.Add(MetaDataKeys.FromId, userId);
                metaData.Add(MetaDataKeys.UserNotificationType, UserNotificationType.Follow.ToString());
                metaData.Add(MetaDataKeys.UserFullName, me.FirstName + " " + me.LastName);


                PushMsgNotificationModel pushMsgNotificationModel = new PushMsgNotificationModel();
                pushMsgNotificationModel.title       = me.FirstName + " " + me.LastName + " is following you";
                pushMsgNotificationModel.type        = NotificationType.User;
                pushMsgNotificationModel.CreatedById = followedUserId;
                pushMsgNotificationModel.metaData    = metaData;
                pushMsgNotificationModel.content     = "is following you";

                new PushMsgNotification().PushMessageAsync(pushMsgNotificationModel);
                new NotificationService(me.FirstName + " " + me.LastName + " is following you", NotificationType.User).AddUser(followedUserId).AddMetaData(metaData).AddContent("is following you").Send();
            }
        }
Exemple #2
0
        public async Task LikeCommentAsync(string commentId, string userId)
        {
            var commentLike = await _repo.CommentLikes.FirstOrDefaultAsync(m => m.CommentId == commentId && m.CreatedById == userId);

            if (commentLike == null)
            {
                commentLike             = new Data.Entities.CommentLike();
                commentLike.CommentId   = commentId;
                commentLike.CreatedById = userId;
                await _repo.CommentLikes.AddOrUpdateAndSaveAsync(commentLike);

                var comment = await _repo.Comments.FirstOrDefaultAsync(m => m.Id == commentId);

                var me = await _repo.Users.FirstOrDefaultAsync(m => m.Id == userId);


                var metaData = new Dictionary <string, string>();
                metaData.Add(MetaDataKeys.FromId, userId);
                metaData.Add(MetaDataKeys.UserNotificationType, UserNotificationType.CommentLike.ToString());
                metaData.Add(MetaDataKeys.PostId, comment.PostId);
                metaData.Add(MetaDataKeys.CommentId, comment.Id);
                metaData.Add(MetaDataKeys.UserFullName, me.FirstName + " " + me.LastName);

                PushMsgNotificationModel pushMsgNotificationModel = new PushMsgNotificationModel();
                pushMsgNotificationModel.title       = me.FirstName + " " + me.LastName + " liked your comment";
                pushMsgNotificationModel.type        = NotificationType.User;
                pushMsgNotificationModel.CreatedById = comment.CreatedById;
                pushMsgNotificationModel.metaData    = metaData;
                pushMsgNotificationModel.content     = "liked your comment";

                new PushMsgNotification().PushMessageAsync(pushMsgNotificationModel);
                new NotificationService(me.FirstName + " " + me.LastName + " liked your comment", NotificationType.User).AddUser(comment.CreatedById).AddMetaData(metaData).AddContent("liked your comment").Send();
            }
        }
        public async Task SaveCommentAsync(Comment comment, string userId)
        {
            var dbComment = comment.Map <Data.Entities.Comment>();

            dbComment.CreatedById = userId;
            var me = await _repo.Users.FirstOrDefaultAsync(m => m.Id == userId);

            await _repo.Comments.AddOrUpdateAndSaveAsync(dbComment);

            var post = _repo.Posts.FirstOrDefault(m => m.Id == dbComment.PostId, posts => posts.Include(j => j.CreatedBy));

            if (string.IsNullOrEmpty(post.ContentSourceId + post.TeamId + post.SchoolId + post.FeedId))
            {
                var metaData = new Dictionary <string, string>();
                metaData.Add(MetaDataKeys.FromId, userId);
                metaData.Add(MetaDataKeys.UserNotificationType, UserNotificationType.Comment.ToString());
                metaData.Add(MetaDataKeys.PostId, dbComment.PostId);
                metaData.Add(MetaDataKeys.UserFullName, post.CreatedBy.FirstName + " " + post.CreatedBy.LastName);

                PushMsgNotificationModel pushMsgNotificationModel = new PushMsgNotificationModel();
                pushMsgNotificationModel.title       = me.FirstName + " " + me.LastName + " commented on your post";
                pushMsgNotificationModel.type        = NotificationType.User;
                pushMsgNotificationModel.CreatedById = post.CreatedById;
                pushMsgNotificationModel.metaData    = metaData;
                pushMsgNotificationModel.content     = "commented on your post";

                new PushMsgNotification().PushMessageAsync(pushMsgNotificationModel);

                new NotificationService(me.FirstName + " " + me.LastName + " commented on your post", NotificationType.User).AddUser(post.CreatedById).AddMetaData(metaData).AddContent("commented on your post").Send();

                if (!string.IsNullOrEmpty(dbComment.ParentCommentId))
                {
                    var parentComment = await _repo.Comments.FirstOrDefaultAsync(m => m.Id == dbComment.ParentCommentId);

                    var metaDataReply = new Dictionary <string, string>();
                    metaDataReply.Add(MetaDataKeys.FromId, userId);
                    metaDataReply.Add(MetaDataKeys.UserNotificationType, UserNotificationType.Comment.ToString());
                    metaDataReply.Add(MetaDataKeys.PostId, dbComment.PostId);
                    metaDataReply.Add(MetaDataKeys.CommentId, dbComment.Id);
                    metaDataReply.Add(MetaDataKeys.UserFullName, post.CreatedBy.FirstName + " " + post.CreatedBy.LastName);


                    PushMsgNotificationModel parentPushMsgNotificationModel = new PushMsgNotificationModel();
                    parentPushMsgNotificationModel.title       = me.FirstName + " " + me.LastName + " replied to your comment";
                    parentPushMsgNotificationModel.type        = NotificationType.User;
                    parentPushMsgNotificationModel.CreatedById = parentComment.CreatedById;
                    parentPushMsgNotificationModel.metaData    = metaDataReply;
                    parentPushMsgNotificationModel.content     = "replied to your comment";

                    new PushMsgNotification().PushMessageAsync(pushMsgNotificationModel);
                    new NotificationService(me.FirstName + " " + me.LastName + " replied to your comment", NotificationType.User).AddUser(parentComment.CreatedById).AddMetaData(metaDataReply).AddContent("replied to your comment").Send();
                }
            }
        }
        public async Task LikePostAsync(string postId, string userId)
        {
            var like = await _repo.PostLikes.FirstOrDefaultAsync(m => m.PostId == postId && m.CreatedById == userId);

            var CreatedPostUserData = await _repo.Posts.FirstOrDefaultAsync(m => m.Id == postId);

            if (like == null)
            {
                like             = new Data.Entities.PostLike();
                like.PostId      = postId;
                like.CreatedById = userId;


                await _repo.PostLikes.AddOrUpdateAndSaveAsync(like);

                var me = await _repo.Users.FirstOrDefaultAsync(m => m.Id == userId);

                var post = _repo.Posts.FirstOrDefault(m => m.Id == postId, posts => posts.Include(j => j.CreatedBy));

                if (string.IsNullOrEmpty(post.ContentSourceId + post.TeamId + post.SchoolId + post.FeedId))
                {
                    var metaData = new Dictionary <string, string>();
                    metaData.Add(MetaDataKeys.FromId, userId);
                    metaData.Add(MetaDataKeys.UserNotificationType, UserNotificationType.Like.ToString());
                    metaData.Add(MetaDataKeys.PostId, postId);
                    metaData.Add(MetaDataKeys.UserFullName, post.CreatedBy.FirstName + " " + post.CreatedBy.LastName);
                    metaData.Add(MetaDataKeys.PostUserID, CreatedPostUserData.CreatedById);


                    PushMsgNotificationModel pushMsgNotificationModel = new PushMsgNotificationModel();
                    pushMsgNotificationModel.title       = me.FirstName + " " + me.LastName + " liked your post";
                    pushMsgNotificationModel.type        = NotificationType.User;
                    pushMsgNotificationModel.CreatedById = post.CreatedById;
                    pushMsgNotificationModel.metaData    = metaData;
                    pushMsgNotificationModel.content     = "liked your post";

                    new PushMsgNotification().PushMessageAsync(pushMsgNotificationModel);
                    new NotificationService(me.FirstName + " " + me.LastName + " liked your post", NotificationType.User).AddUser(post.CreatedById).AddMetaData(metaData).AddContent("liked your post").Send();
                }
            }
        }
Exemple #5
0
        public void SendPush(string id)
        {
            var repo  = new ApplicationRepository(new ApplicationDbContext());
            var model = repo.NewsNotifications.FirstOrDefault(m => m.Id == id);

            var metaData = new Dictionary <string, string>();

            metaData.Add(MetaDataKeys.UserNotificationType, UserNotificationType.NewsNotification.ToString());
            if (!string.IsNullOrEmpty(model.ContentSourceId))
            {
                metaData.Add(MetaDataKeys.FromId, model.ContentSourceId);
                metaData.Add(MetaDataKeys.FromIdType, FeedType.ContentSource.ToString());
            }
            else if (!string.IsNullOrEmpty(model.TeamId))
            {
                metaData.Add(MetaDataKeys.FromId, model.TeamId);
                metaData.Add(MetaDataKeys.FromIdType, FeedType.Team.ToString());
            }
            else if (!string.IsNullOrEmpty(model.SchoolId))
            {
                metaData.Add(MetaDataKeys.FromId, model.SchoolId);
                metaData.Add(MetaDataKeys.FromIdType, FeedType.School.ToString());
            }
            else if (!string.IsNullOrEmpty(model.SportId))
            {
                metaData.Add(MetaDataKeys.FromId, model.SportId);
                metaData.Add(MetaDataKeys.FromIdType, FeedType.Sport.ToString());
            }
            metaData.Add(MetaDataKeys.NewsNotificationMessage, model.Content);

            PushMsgNotificationModel pushMsgNotificationModel = new PushMsgNotificationModel();

            pushMsgNotificationModel.title    = model.Title;
            pushMsgNotificationModel.type     = NotificationType.UsersSuppliedAtNotificationEvent;
            pushMsgNotificationModel.metaData = metaData;
            pushMsgNotificationModel.content  = model.Content;

            new PushMsgNotification().PushMessageAsync(pushMsgNotificationModel);

            new NotificationService(model.Title, NotificationType.UsersSuppliedAtNotificationEvent).AddMetaData(metaData).AddContent(model.Content).Send();
        }
        public async Task SaveShareAsync(string postId, string userId)
        {
            var share = new Data.Entities.PostShare();

            share.CreatedById = userId;
            share.PostId      = postId;
            var existing = _repo.PostShares.FirstOrDefault(m => m.PostId == postId && m.CreatedById == userId);

            if (existing != null)
            {
                return;
            }

            await _repo.PostShares.AddOrUpdateAndSaveAsync(share);

            var me = await _repo.Users.FirstOrDefaultAsync(m => m.Id == userId);

            var createdById = await _repo.Posts.Where(m => m.Id == postId).Select(m => m.CreatedById).FirstOrDefaultAsync();

            var metaData = new Dictionary <string, string>();

            metaData.Add(MetaDataKeys.FromId, userId);
            metaData.Add(MetaDataKeys.UserNotificationType, UserNotificationType.Share.ToString());
            metaData.Add(MetaDataKeys.PostId, postId);
            metaData.Add(MetaDataKeys.UserFullName, me.FirstName + " " + me.LastName);


            PushMsgNotificationModel pushMsgNotificationModel = new PushMsgNotificationModel();

            pushMsgNotificationModel.title       = me.FirstName + " " + me.LastName + " shared your post";
            pushMsgNotificationModel.type        = NotificationType.User;
            pushMsgNotificationModel.CreatedById = createdById;
            pushMsgNotificationModel.metaData    = metaData;
            pushMsgNotificationModel.content     = "shared your post";

            new PushMsgNotification().PushMessageAsync(pushMsgNotificationModel);

            new NotificationService(me.FirstName + " " + me.LastName + " shared your post", NotificationType.User).AddUser(createdById).AddMetaData(metaData).AddContent("shared your post").Send();
        }