コード例 #1
0
        public PostListVm[] GetAllPostForGroup(int groupId)
        {
            PostListVm[] postList;

            using (var ctx = new KoombuContext())
            {
                postList = ctx.PostSet.AsNoTracking()
                           .Where(o => o.GroupId == groupId)
                           .Select(o => new PostListVm()
                {
                    Id              = o.PostId,
                    Content         = o.Content,
                    PostOwnerId     = o.OwnerId,
                    GroupOwnerId    = o.GroupId,
                    PictureUrl      = o.PictureUrl,
                    AttachementUrl  = o.AttachementUrl,
                    AttachementName = o.AttachementName,
                    PostDate        = o.PostDate
                }).ToArray();
            }

            foreach (var post in postList)
            {
                post.Likes        = GetLikesNumber(post.Id);
                post.CommentsList = GetAllCommentForPost(post.Id);
                post.PostOwner    = GetUser(post.PostOwnerId);
            }

            return(postList);
        }
コード例 #2
0
        public PostListVm[] GetAllPostForUser(int userId)
        {
            PostListVm[] postList;
            IList <int>  l = GetFollowedUsersId(userId);

            l.Add(userId);
            using (var ctx = new KoombuContext())
            {
                postList = ctx.PostSet.AsNoTracking()
                           .Where(o => l.Contains(o.OwnerId) && o.GroupId == 0)
                           .Select(o => new PostListVm()
                {
                    Id              = o.PostId,
                    Content         = o.Content,
                    PostOwnerId     = o.OwnerId,
                    GroupOwnerId    = o.GroupId,
                    PictureUrl      = o.PictureUrl,
                    AttachementUrl  = o.AttachementUrl,
                    AttachementName = o.AttachementName,
                    PostDate        = o.PostDate
                }).ToArray();
            }

            foreach (var post in postList)
            {
                post.Likes        = GetLikesNumber(post.Id);
                post.CommentsList = GetAllCommentForPost(post.Id);
            }

            return(postList);
        }
コード例 #3
0
        public void DeleteGroup(int groupId)
        {
            using (var ctx = new KoombuContext())
            {
                var x = (from g in ctx.GroupSet
                         where g.Id == groupId
                         select g).FirstOrDefault();

                var groupList = (from gm in ctx.GroupMembersSet
                                 where gm.GroupId == groupId
                                 select gm).ToList();
                if (x != null)
                {
                    ctx.GroupSet.Remove(x);
                    ctx.SaveChanges();
                }
                if (groupList != null)
                {
                    foreach (var y in groupList)
                    {
                        ctx.GroupMembersSet.Remove(y);
                    }

                    ctx.SaveChanges();
                }
            }
        }
コード例 #4
0
        public User GetUser(int userId)
        {
            using (var ctx = new KoombuContext())
            {
                var user = ctx.UserSet.AsNoTracking().SingleOrDefault(o => o.UserId == userId);

                return(user);
            }
        }
コード例 #5
0
 public UserFollow[] GetFollowedUserList(int userId)
 {
     using (var ctx = new KoombuContext())
     {
         return(ctx.UserFollowsSet.AsNoTracking()
                .Where(o => o.UserId == userId)
                .ToArray());
     }
 }
コード例 #6
0
        public Group GetGroup(int groupId)
        {
            using (var ctx = new KoombuContext())
            {
                var group = ctx.GroupSet.AsNoTracking().SingleOrDefault(o => o.Id == groupId);

                return(group);
            }
        }
コード例 #7
0
        public User SignIn(string userEmail, string userPassword)
        {
            using (var ctx = new KoombuContext())
            {
                var user = ctx.UserSet.AsNoTracking()
                           .SingleOrDefault(o => o.EmailAdress == userEmail && o.Password == userPassword);

                return(user);
            }
        }
コード例 #8
0
 public void AddProfilPic(int userId, string urlPicture)
 {
     using (var ctx = new KoombuContext())
     {
         (from x in ctx.UserSet
          where x.UserId == userId
          select x).ToList().ForEach(xx => xx.ProfilPicture = urlPicture);
         ctx.SaveChanges();
     }
 }
コード例 #9
0
        public GroupMembers[] GroupMembersObjects(int groupId)
        {
            using (var ctx = new KoombuContext())
            {
                var groupMembers = ctx.GroupMembersSet.AsNoTracking()
                                   .Where(o => o.GroupId == groupId)
                                   .ToArray();

                return(groupMembers);
            }
        }
コード例 #10
0
        public int GetLikesNumber(int postId)
        {
            PostLike[] pL;
            using (var ctx = new KoombuContext())
            {
                pL = ctx.PostLikeSet.AsNoTracking()
                     .Where(o => o.PostId == postId)
                     .ToArray();
            }

            return(pL.Length);
        }
コード例 #11
0
 public void RemovePost(int postId)
 {
     using (var ctx = new KoombuContext())
     {
         var x = (from y in ctx.PostSet
                  where y.PostId == postId
                  select y).FirstOrDefault();
         if (x != null)
         {
             ctx.PostSet.Remove(x);
             ctx.SaveChanges();
         }
     }
 }
コード例 #12
0
 public void RemoveUserFromGroup(int userToRemoveId, int groupId)
 {
     using (var ctx = new KoombuContext())
     {
         var x = (from y in ctx.GroupMembersSet
                  where y.GroupId == groupId && y.UserId == userToRemoveId
                  select y).FirstOrDefault();
         if (x != null)
         {
             ctx.GroupMembersSet.Remove(x);
             ctx.SaveChanges();
         }
     }
 }
コード例 #13
0
        public void RemoveComment(int commentId)
        {
            using (var ctx = new KoombuContext())
            {
                var comment = (from y in ctx.CommentSet
                               where y.Id == commentId
                               select y).FirstOrDefault();

                if (comment != null)
                {
                    ctx.CommentSet.Remove(comment);
                    ctx.SaveChanges();
                }
            }
        }
コード例 #14
0
        public void UnlikePost(int postId, int userId)
        {
            using (var ctx = new KoombuContext())
            {
                var like = (from y in ctx.PostLikeSet
                            where y.PostId == postId && y.UserId == userId
                            select y).FirstOrDefault();

                if (like != null)
                {
                    ctx.PostLikeSet.Remove(like);
                    ctx.SaveChanges();
                }
            }
        }
コード例 #15
0
        public void UnFollowUser(int userId, int userIdToUnFollowId)
        {
            using (var ctx = new KoombuContext())
            {
                var user = (from y in ctx.UserFollowsSet
                            where y.UserId == userId && y.FollowedUserId == userIdToUnFollowId
                            select y).FirstOrDefault();

                if (user != null)
                {
                    ctx.UserFollowsSet.Remove(user);
                    ctx.SaveChanges();
                }
            }
        }
コード例 #16
0
        public bool CheckEmail(string email)
        {
            bool exist = false;

            using (var ctx = new KoombuContext())
            {
                var existEmail = ctx.UserSet.Count(a => a.EmailAdress == email);
                if (existEmail != 0)
                {
                    exist = true;
                }

                return(exist);
            }
        }
コード例 #17
0
        public void CommentPost(string content, int postId, int userId)
        {
            Comment comment = new Comment();

            comment.Content = content;
            comment.OwnerId = userId;
            comment.PostId  = postId;
            comment.Date    = DateTime.Now;

            using (var ctx = new KoombuContext())
            {
                ctx.CommentSet.Add(comment);

                ctx.SaveChanges();
            }
        }
コード例 #18
0
        public void CreateGroup(int groupOwnerId, string groupName, string groupDescription, string groupImgtUrl)
        {
            Group group = new Group();

            group.GroupOwnerId     = groupOwnerId;
            group.GroupName        = groupName;
            group.GroupDescription = groupDescription;
            group.GroupPicture     = groupImgtUrl;

            using (var ctx = new KoombuContext())
            {
                ctx.GroupSet.Add(group);

                ctx.SaveChanges();
            }
        }
コード例 #19
0
        public void LikePost(int postId, int userId)
        {
            PostLike postLike = new PostLike();

            postLike.UserId = userId;
            postLike.PostId = postId;

            using (var ctx = new KoombuContext())
            {
                var exist = ctx.PostLikeSet.AsNoTracking().SingleOrDefault(o => o.UserId == userId && o.PostId == postId);
                if (exist == null)
                {
                    ctx.PostLikeSet.Add(postLike);
                    ctx.SaveChanges();
                }
            }
        }
コード例 #20
0
        public void AddUserToGroup(int userToAddId, int groupId)
        {
            GroupMembers groupMember = new GroupMembers();
            User         user        = GetUser(userToAddId);

            groupMember.GroupId       = groupId;
            groupMember.UserId        = userToAddId;
            groupMember.UserFirstName = user.FirstName;
            groupMember.UserLastName  = user.LastName;
            groupMember.UserPicture   = user.ProfilPicture;
            using (var ctx = new KoombuContext())
            {
                ctx.GroupMembersSet.Add(groupMember);

                ctx.SaveChanges();
            }
        }
コード例 #21
0
        public void FollowUser(int userId, int userIdToFollowId)
        {
            UserFollow uF = new UserFollow();

            uF.UserId         = userId;
            uF.FollowedUserId = userIdToFollowId;
            using (var ctx = new KoombuContext())
            {
                var exist = ctx.UserFollowsSet.AsNoTracking()
                            .SingleOrDefault(o => o.UserId == userId && o.FollowedUserId == userIdToFollowId);
                if (exist == null)
                {
                    ctx.UserFollowsSet.Add(uF);
                    ctx.SaveChanges();
                }
            }
        }
コード例 #22
0
 public UsersListVm[] GetAllUsers()
 {
     using (var ctx = new KoombuContext())
     {
         return(ctx.UserSet.AsNoTracking()
                .Select(o => new UsersListVm()
         {
             UserId = o.UserId,
             FirstName = o.FirstName,
             LastName = o.LastName,
             ProfilPicture = o.ProfilPicture,
             EmailAdress = o.EmailAdress,
             Department = o.Department,
             Title = o.Title,
             DateOfBirth = o.DateOfBirth
         }).ToArray());
     }
 }
コード例 #23
0
        public GroupVm[] GetAllGroupsForUser(int userId)
        {
            ICollection <GroupVm> groupList   = new List <GroupVm>();
            ICollection <int>     groupIdList = new List <int>();

            using (var ctx = new KoombuContext())
            {
                groupList = ctx.GroupSet.AsNoTracking()
                            .Where(o => o.GroupOwnerId == userId)
                            .Select(o => new GroupVm()
                {
                    Id               = o.Id,
                    GroupName        = o.GroupName,
                    GroupDescription = o.GroupDescription,
                    GroupPicture     = o.GroupPicture,
                    GroupOwnerId     = o.GroupOwnerId
                }).ToList();

                groupIdList = ctx.GroupMembersSet.AsNoTracking()
                              .Where(g => g.UserId == userId)
                              .Select(g => g.GroupId)
                              .ToList();
            }


            foreach (var groupId in groupIdList)
            {
                var group = GetGroup(groupId);
                groupList.Add(new GroupVm()
                {
                    Id               = group.Id,
                    GroupOwnerId     = group.GroupOwnerId,
                    GroupDescription = group.GroupDescription,
                    GroupName        = group.GroupName,
                    GroupPicture     = group.GroupPicture,
                });
            }

            foreach (var group in groupList)
            {
                group.Owner = GetUser(group.GroupOwnerId);
            }
            return(groupList.ToArray());
        }
コード例 #24
0
        public void CreatePost(string content, int postUserId, int groupOwnerId, string postImgtUrl,
                               string postAttachementUrl, string attachementName)
        {
            Post post = new Post
            {
                Content         = content,
                OwnerId         = postUserId,
                GroupId         = groupOwnerId,
                PictureUrl      = postImgtUrl,
                AttachementUrl  = postAttachementUrl,
                AttachementName = attachementName,
                PostDate        = DateTime.Now
            };

            using (var ctx = new KoombuContext())
            {
                ctx.PostSet.Add(post);
                ctx.SaveChanges();
            }
        }
コード例 #25
0
        public CommentListVm[] GetAllCommentForPost(int postId)
        {
            CommentListVm[] list;
            using (var ctx = new KoombuContext())
            {
                list = ctx.CommentSet.AsNoTracking()
                       .Where(o => o.PostId == postId)
                       .Select(o => new CommentListVm()
                {
                    Id      = o.Id,
                    Content = o.Content,
                    OwnerId = o.OwnerId,
                    PostId  = o.PostId,
                    Date    = o.Date,
                }).ToArray();
            }

            var commentList = SetUsersToComments(list);

            return(commentList);
        }
コード例 #26
0
        public User RegisterUser(string firstName, string lastName, string email, DateTime birthDate, string password,
                                 string department, string title)
        {
            User user = new User
            {
                FirstName   = firstName,
                LastName    = lastName,
                EmailAdress = email,
                Password    = password,
                Department  = department,
                Title       = title,
                DateOfBirth = birthDate
            };

            using (var ctx = new KoombuContext())
            {
                ctx.UserSet.Add(user);

                ctx.SaveChanges();
            }

            return(user);
        }