Exemplo n.º 1
0
 public IEnumerable <string> GetFollowersGroup(string groupId)
 {
     using (var entities = new SocialFeedEntities())
     {
         return(entities.GroupFollower.Where(t => t.GroupId == groupId).Select(t => t.FollowerId).ToList());
     }
 }
Exemplo n.º 2
0
 public IEnumerable <string> GetPostLikes(string postId)
 {
     using (var entities = new SocialFeedEntities())
     {
         return(entities.WallPostLike.Where(t => t.WallPostId == postId).Select(t => t.CreatedBy).ToList());
     }
 }
Exemplo n.º 3
0
 public IEnumerable <string> GetCommentLikes(long commentId)
 {
     using (var entities = new SocialFeedEntities())
     {
         return(entities.UserCommentLike.Where(t => t.CommentId == commentId).Select(t => t.CreatedBy).ToList());
     }
 }
Exemplo n.º 4
0
 public IEnumerable <string> GetFollowersUser(string userId)
 {
     using (var entities = new SocialFeedEntities())
     {
         return(entities.UserFollower.Where(t => t.UserId == userId).Select(t => t.FollowerId).ToList());
     }
 }
Exemplo n.º 5
0
 public IEnumerable <NewsfeedEventModel> Generate(string userId)
 {
     using (var context = new SocialFeedEntities())
     {
         var result = context.GetInitialFeedPosts(userId);
         return(MapInitialFeed(result));
     }
 }
Exemplo n.º 6
0
 public WallPostModel GetPost(string postId)
 {
     using (var entities = new SocialFeedEntities())
     {
         var result = entities.WallPost.Include("UserWall").Include("GroupWall").FirstOrDefault(p => p.Id == postId && p.IsDeleted == false);
         return(MapWallPost(result));
     }
 }
Exemplo n.º 7
0
 public IEnumerable <string> GetGroupWallIds(string groupId, int size)
 {
     using (var entities = new SocialFeedEntities())
     {
         return(entities.GroupWall.Include("WallPost")
                .Where(p => p.GroupId == groupId && p.WallPost.IsDeleted == false)
                .OrderByDescending(p => p.WallPost.CreatedDate).Take(size).Select(p => p.WallPostId).ToList());
     }
 }
Exemplo n.º 8
0
 public ConfigurationParameter FetchParameter(string parameterId)
 {
     using (var entities = new SocialFeedEntities())
     {
         return(entities.ApplicationConfiguration.Where(p => p.Id == parameterId).Select(p => new ConfigurationParameter {
             Id = p.Id, Value = p.Value, Description = p.Description
         }).FirstOrDefault());
     }
 }
Exemplo n.º 9
0
 public List <ConfigurationParameter> FetchConfiguration()
 {
     using (var entities = new SocialFeedEntities())
     {
         return(entities.ApplicationConfiguration.Select(p => new ConfigurationParameter {
             Id = p.Id, Value = p.Value, Description = p.Description
         }).ToList());
     }
 }
Exemplo n.º 10
0
 public void RemoveComment(long commentId)
 {
     using (var entities = new SocialFeedEntities())
     {
         var comment = entities.UserComment.FirstOrDefault(p => p.Id == commentId);
         comment.IsDeleted = true;
         entities.SaveChanges();
     }
 }
Exemplo n.º 11
0
        public IEnumerable <CommentModel> GetPagedComments(string postId, int skip, int size)
        {
            var result = new List <CommentModel>();

            using (var context = new SocialFeedEntities())
            {
                var comments = context.GetComments(postId, skip, size).ToList();
                return(MapCommentProcedureResult(comments));
            }
        }
Exemplo n.º 12
0
        public IEnumerable <WallPostWithDetailsModel> GetGroupWallDetailed(string groupId, DateTime olderThan, int size)
        {
            IEnumerable <GetWall_Result> procedureResult;

            using (var entities = new SocialFeedEntities())
            {
                procedureResult = entities.GetGroupWall(groupId, olderThan, size).ToList();
            }
            return(MapWall(procedureResult, new WallModel {
                OwnerId = groupId, WallOwnerType = WallType.group
            }));
        }
Exemplo n.º 13
0
 public void UnfollowUser(string userId, string followerId)
 {
     using (var entities = new SocialFeedEntities())
     {
         var record = entities.UserFollower.FirstOrDefault(p => p.FollowerId == followerId && p.UserId == userId);
         if (record != null)
         {
             entities.UserFollower.Remove(record);
             entities.SaveChanges();
         }
     }
 }
Exemplo n.º 14
0
 public IEnumerable <WallModel> GetFollowingGroups(string userId)
 {
     //TODO:Update Private/Public condition
     using (var entities = new SocialFeedEntities())
     {
         return(entities.GroupFollower.Where(p => p.FollowerId == userId).Select(p => new WallModel
         {
             OwnerId = p.GroupId,
             WallOwnerType = WallType.group
         }).ToList());
     }
 }
Exemplo n.º 15
0
 public void FollowUser(string userId, string followerId)
 {
     using (var entities = new SocialFeedEntities())
     {
         if (!entities.UserFollower.Any(t => t.UserId == userId && t.FollowerId == followerId))
         {
             entities.UserFollower.Add(new UserFollower {
                 UserId = userId, FollowerId = followerId
             });
             entities.SaveChanges();
         }
     }
 }
Exemplo n.º 16
0
 public void FollowGroup(string groupId, string followerId)
 {
     using (var entities = new SocialFeedEntities())
     {
         if (!entities.GroupFollower.Any(t => t.GroupId == groupId && t.FollowerId == followerId))
         {
             entities.GroupFollower.Add(new GroupFollower {
                 GroupId = groupId, FollowerId = followerId
             });
             entities.SaveChanges();
         }
     }
 }
Exemplo n.º 17
0
 public CommentModel GetComment(string postId, long commentId)
 {
     using (var context = new SocialFeedEntities())
     {
         var result = context.UserComment.FirstOrDefault(t => t.WallPostId == postId && t.Id == commentId && t.IsDeleted == false);
         if (result != null)
         {
             var likeCount = context.UserCommentLike.Count(t => t.CommentId == commentId);
             return(MapComment(result, likeCount));
         }
     }
     return(null);
 }
Exemplo n.º 18
0
 public bool RemovePost(string postId)
 {
     using (var entities = new SocialFeedEntities())
     {
         var post = entities.WallPost.FirstOrDefault(p => p.Id == postId);
         if (post != null)
         {
             post.IsDeleted = true;
             entities.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 19
0
        public bool UnlikePost(string postId, string userId)
        {
            using (var entities = new SocialFeedEntities())
            {
                var likeEntry = entities.WallPostLike.FirstOrDefault(t => t.CreatedBy == userId && t.WallPostId == postId);

                if (likeEntry != null)
                {
                    entities.WallPostLike.Remove(likeEntry);
                    entities.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }
Exemplo n.º 20
0
        public FollowerPagedModel GetFollowersGroupPaged(string groupId, int skip, int size)
        {
            using (var entities = new SocialFeedEntities())
            {
                var followers  = entities.GroupFollower.Where(p => p.GroupId == groupId).Select(p => p.FollowerId);
                var resultSet  = followers.OrderBy(p => p).Skip(skip).Take(size).ToList();
                var totalCount = followers.Count();

                return(new FollowerPagedModel
                {
                    Records = resultSet,
                    TotalCount = totalCount
                });
            }
        }
Exemplo n.º 21
0
 public bool LikePost(string postId, string userId)
 {
     using (var entities = new SocialFeedEntities())
     {
         if (!entities.WallPostLike.Any(t => t.CreatedBy == userId && t.WallPostId == postId))
         {
             entities.WallPostLike.Add(new WallPostLike {
                 CreatedDate = DateTime.Now, WallPostId = postId, CreatedBy = userId
             });
             entities.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 22
0
 public bool LikeComment(long commentId, string userId)
 {
     using (var entities = new SocialFeedEntities())
     {
         if (!entities.UserCommentLike.Any(t => t.CreatedBy == userId && t.CommentId == commentId))
         {
             entities.UserCommentLike.Add(new UserCommentLike {
                 CreatedDate = DateTime.Now, CommentId = commentId, CreatedBy = userId
             });
             entities.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 23
0
 public DateTime?UpdatePost(WallPostUpdateRequest model)
 {
     using (var entities = new SocialFeedEntities())
     {
         var post = entities.WallPost.FirstOrDefault(p => p.Id == model.PostId && p.IsDeleted == false);
         if (post != null)
         {
             post.Body         = model.Body;
             post.ModifiedDate = DateTime.Now;
             post.PostType     = (byte)model.PostType;
             entities.SaveChanges();
             return(post.ModifiedDate.Value);
         }
     }
     return(null);
 }
Exemplo n.º 24
0
        public IEnumerable <WallPostModel> GetUserWall(string userId, DateTime olderThan, int size)
        {
            List <UserWall> posts;

            using (var entities = new SocialFeedEntities())
            {
                posts = entities.UserWall.Include("WallPost")
                        .Where(p => p.UserId == userId && p.WallPost.CreatedDate < olderThan && p.WallPost.IsDeleted == false)
                        .OrderByDescending(p => p.WallPost.CreatedDate).Take(size).ToList();
            }

            foreach (var post in posts)
            {
                yield return(MapWallPost(post.WallPost));
            }
        }
Exemplo n.º 25
0
        public WallPostWithDetailsModel GetPostDetailed(string postId)
        {
            GetWallPost_Result postResult;
            IEnumerable <GetLatestComments_Result> commentResult;

            using (var entities = new SocialFeedEntities())
            {
                postResult = entities.GetWallPost(postId).FirstOrDefault();
                if (postResult != null)
                {
                    commentResult = entities.GetLatestComments(postId).ToList();
                    return(MapWallPost(postResult, commentResult));
                }
            }
            return(null);
        }
Exemplo n.º 26
0
 public DateTime?UpdateComment(CommentUpdateRequest model)
 {
     using (var entities = new SocialFeedEntities())
     {
         var comment = entities.UserComment.FirstOrDefault(p => p.Id == model.CommentId &&
                                                           p.IsDeleted == false);
         if (comment != null)
         {
             comment.ModifiedDate = DateTime.Now;
             comment.Body         = model.Body;
             entities.SaveChanges();
             return(comment.ModifiedDate.Value);
         }
     }
     return(null);
 }
Exemplo n.º 27
0
        public EntryLikePagedModel GetPostLikesPaged(string postId, int skip, int size)
        {
            using (var entities = new SocialFeedEntities())
            {
                var totalCount = entities.WallPostLike.Where(p => p.WallPostId == postId).Count();

                var records = entities.WallPostLike.Where(p => p.WallPostId == postId)
                              .OrderByDescending(p => p.CreatedDate)
                              .Skip(skip).Take(size).Select(p => p.CreatedBy).ToList();

                return(new EntryLikePagedModel
                {
                    Records = records,
                    TotalCount = totalCount
                });
            }
        }
Exemplo n.º 28
0
        public CommentCreateResponse SaveComment(CommentCreateRequest model)
        {
            var entry = new UserComment
            {
                WallPostId  = model.WallPostId,
                Body        = model.Body,
                CreatedBy   = model.CreatedBy,
                CreatedDate = DateTime.Now,
                IsDeleted   = false
            };

            using (var entities = new SocialFeedEntities())
            {
                entities.UserComment.Add(entry);
                entities.SaveChanges();
            }

            return(new CommentCreateResponse {
                Id = entry.Id, CreatedDate = entry.CreatedDate
            });
        }
Exemplo n.º 29
0
        public IEnumerable <GroupWallResponseModel> GetGroupWall(string groupId, int skip, int size)
        {
            //TODO:Optimize with sp
            List <GroupWallResponseModel> response = new List <GroupWallResponseModel>();

            using (var entities = new SocialFeedEntities())
            {
                var posts = entities.GroupWall.Include("WallPost")
                            .Where(p => p.GroupId == groupId && p.WallPost.IsDeleted == false)
                            .OrderByDescending(p => p.WallPost.CreatedDate).Skip(skip).Take(size).ToList();

                //TODO:Optimize with sp
                foreach (var post in posts)
                {
                    var postLikes    = entities.WallPostLike.Count(p => p.WallPostId == post.WallPostId);
                    var postComments = entities.UserComment.Count(p => p.WallPostId == post.WallPostId);

                    var item = new GroupWallResponseModel
                    {
                        Body         = post.WallPost.Body,
                        CommentCount = postComments,
                        CreatedDate  = post.WallPost.CreatedDate,
                        Id           = post.WallPostId,
                        LikeCount    = postLikes,
                        ModifiedDate = post.WallPost.ModifiedDate,
                        PostedBy     = post.WallPost.CreatedBy,
                        PostType     = post.WallPost.PostType,
                        WallOwner    = new WallModel {
                            OwnerId = post.GroupId, WallOwnerType = WallType.group
                        }
                    };

                    response.Add(item);
                }
            }
            return(response);
        }
Exemplo n.º 30
0
        public WallPostCreateResponse SavePost(WallPostCreateRequest model)
        {
            var newEntryId = Guid.NewGuid().ToString();
            var entry      = new WallPost
            {
                Body        = model.Body,
                CreatedBy   = model.PostedBy,
                Id          = newEntryId,
                CreatedDate = DateTime.Now,
                PostType    = (byte)model.PostType,
                IsDeleted   = false
            };

            if (model.TargetWall.WallOwnerType == WallType.user)
            {
                entry.UserWall = new UserWall {
                    UserId = model.TargetWall.OwnerId, WallPostId = newEntryId
                };
            }
            else
            {
                entry.GroupWall = new GroupWall {
                    GroupId = model.TargetWall.OwnerId, WallPostId = newEntryId
                };
            }

            using (var entities = new SocialFeedEntities())
            {
                entities.WallPost.Add(entry);
                entities.SaveChanges();
            }

            return(new WallPostCreateResponse {
                PostId = newEntryId, CreatedDate = entry.CreatedDate
            });
        }