public IEnumerable <string> GetFollowersGroup(string groupId) { using (var entities = new SocialFeedEntities()) { return(entities.GroupFollower.Where(t => t.GroupId == groupId).Select(t => t.FollowerId).ToList()); } }
public IEnumerable <string> GetPostLikes(string postId) { using (var entities = new SocialFeedEntities()) { return(entities.WallPostLike.Where(t => t.WallPostId == postId).Select(t => t.CreatedBy).ToList()); } }
public IEnumerable <string> GetCommentLikes(long commentId) { using (var entities = new SocialFeedEntities()) { return(entities.UserCommentLike.Where(t => t.CommentId == commentId).Select(t => t.CreatedBy).ToList()); } }
public IEnumerable <string> GetFollowersUser(string userId) { using (var entities = new SocialFeedEntities()) { return(entities.UserFollower.Where(t => t.UserId == userId).Select(t => t.FollowerId).ToList()); } }
public IEnumerable <NewsfeedEventModel> Generate(string userId) { using (var context = new SocialFeedEntities()) { var result = context.GetInitialFeedPosts(userId); return(MapInitialFeed(result)); } }
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)); } }
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()); } }
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()); } }
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()); } }
public void RemoveComment(long commentId) { using (var entities = new SocialFeedEntities()) { var comment = entities.UserComment.FirstOrDefault(p => p.Id == commentId); comment.IsDeleted = true; entities.SaveChanges(); } }
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)); } }
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 })); }
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(); } } }
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()); } }
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(); } } }
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(); } } }
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); }
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); } }
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); } }
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 }); } }
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); } }
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); }
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); }
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)); } }
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); }
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); }
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 }); } }
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 }); }
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); }
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 }); }