Beispiel #1
0
        static public void CreateMessage(messages message)
        {
            var db = new VERK2015_H17Entities1();

            db.messages.Add(message);
            db.SaveChanges();
        }
Beispiel #2
0
        /*
         * <summary>Gets a bubble_group by id</summary>
         * <param name="id"></param>
         * <returns>a bubble_groups object</returns>
         * <author>Andri Rafn</author>
         */
        static public bubble_groups GetGroupById(int id)
        {
            var           db    = new VERK2015_H17Entities1();
            bubble_groups group = (db.bubble_groups.ToList().Where(x => x.C_ID == id)).Single();

            return(group);
        }
Beispiel #3
0
        /* <summary>Gets a user by his email</summary>
         * <param name="email">The email string to search after</param>
         * <returns>Returns a single user that matches the email</returns>
         * <author>Janus</author>
         */
        static public AspNetUsers GetUserByEmail(string email)
        {
            var         db   = new VERK2015_H17Entities1();
            AspNetUsers user = (db.AspNetUsers.ToList().Where(x => x.Email == email)).Single();

            return(user);
        }
Beispiel #4
0
        /* <summary>Gets a user by his email</summary>
         * <param name="email">The email string to search after</param>
         * <returns>Returns a single user that matches the email</returns>
         * <author>Janus</author>
         */
        static public AspNetUsers GetUserById(string id)
        {
            var         db   = new VERK2015_H17Entities1();
            AspNetUsers user = (db.AspNetUsers.ToList().Where(x => x.Id == id)).SingleOrDefault();

            return(user);
        }
Beispiel #5
0
        /* <summary>gets all users in the system</summary>
         * <param name="ID">takes no param</param>
         * <returns>list of all users</returns>
         * <author>Valgeir</author>
         */
        static public List <AspNetUsers> GetAllUsers()
        {
            var db       = new VERK2015_H17Entities1();
            var allUsers = db.AspNetUsers.ToList();

            return(allUsers);
        }
Beispiel #6
0
        /* <summary>
         * Saves a given post to the database
         * </summary>
         * <param name="post">The post to be saved to the database</param>
         * <returns>Nothing</returns>
         * <author>Janus</author>
         */
        static public void SavePostToDB(posts post)
        {
            var db = new VERK2015_H17Entities1();

            db.posts.Add(post);
            db.SaveChanges();
        }
Beispiel #7
0
        /* <summary>Saves a comment by a user on a post</summary>
         * <param name="comment">Post comment model</param>
         * <returns>Nothing</returns>
         * <author>Sveinbjorn</author>
         */
        static public void SaveCommentOnPost(post_comments comment)
        {
            var db = new VERK2015_H17Entities1();

            db.post_comments.Add(comment);
            db.SaveChanges();
        }
Beispiel #8
0
        /* <summary>user removes a friend</summary>
         * <param name="userAdder">obj of the user that removes friend</param>
         * <param name="userFriend>obj of the user that was removed</param>
         * <returns>no return</returns>
         * <author>Valgeir</author>
         */
        static public bool RemoveFriend(AspNetUsers userAdder, AspNetUsers userFriend)
        {
            var db = new VERK2015_H17Entities1();

            //Selects friend that you added
            var friendRemoved = (from x in db.friends_added
                                 .Where(y => y.FK_friends_added_users_Added == userAdder.Id)
                                 .Where(z => z.FK_friends_added_users_Addee == userFriend.Id)
                                 select x).SingleOrDefault();
            //Selects friend that added you
            var friendAddeRemoved = (from x in db.friends_added
                                     .Where(y => y.FK_friends_added_users_Added == userFriend.Id)
                                     .Where(z => z.FK_friends_added_users_Addee == userAdder.Id)
                                     select x).SingleOrDefault();

            if (friendRemoved != null && friendAddeRemoved != null)
            {
                //If the friend was added by you, then change friended = false
                if (friendRemoved.FK_friends_added_users_Added != null)
                {
                    friendRemoved.friended = false;
                    db.SaveChanges();
                    return(true);
                }
                //If the friend added you, then change friended to false
                else if (friendAddeRemoved.FK_friends_added_users_Added != null)
                {
                    friendAddeRemoved.friended = false;
                    db.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Beispiel #9
0
        /* <summary>Logs error into database</summary>
         * <param name="error">Obj of error</param>
         * <returns>no return</returns>
         * <author>Valgeir</author>
         */
        public void LogErrorToDB(bubble_errors error)
        {
            var db = new VERK2015_H17Entities1();

            db.bubble_errors.Add(error);
            db.SaveChanges();
        }
Beispiel #10
0
        /* <summary>Returns an event with the given id</summary>
         * <param name="user">Takes an int</param>
         * <returns>Event object</returns>
         * <author>Andri Rafn</author>
         */
        static public events GetEventById(int id)
        {
            var db  = new VERK2015_H17Entities1();
            var eve = (from x in db.events.Where(x => x.C_ID == id)
                       select x).SingleOrDefault();

            return(eve);
        }
Beispiel #11
0
        /* <summary></summary>
         * <param name="ID"></param>
         * <returns></returns>
         * <author></author>
         */
        public static List <bubble_groups> SearchGroupByName(bubble_groups gr)
        {
            var db     = new VERK2015_H17Entities1();
            var groups = (from x in db.bubble_groups.Where(y => y.group_name.Contains(gr.group_name))
                          select x).ToList();

            return(groups);
        }
Beispiel #12
0
        /* <summary>Searches for users by username</summary>
         * <param name="user">Takes in obj of a user</param>
         * <returns>list of users</returns>
         * <author></author>
         */
        public static List <AspNetUsers> SearchUsersByName(AspNetUsers user)
        {
            var db    = new VERK2015_H17Entities1();
            var users = (from x in db.AspNetUsers.Where(y => y.NickName.Contains(user.NickName))
                         select x).ToList();

            return(users);
        }
Beispiel #13
0
        /* <summary>Gets all groups</summary>
         * <param name=""></param>
         * <returns>A list of all groups</returns>
         * <author>Sveinbjorn</author>
         */
        static public List <bubble_groups> GetAllGroups()
        {
            var db     = new VERK2015_H17Entities1();
            var groups = (from x in db.bubble_groups
                          select x).ToList();

            return(groups);
        }
Beispiel #14
0
        /* <summary>Gets a list of posts in group</summary>
         * <param name="bubbleGroup">Group model</param>
         * <returns>List of posts in the group</returns>
         * <author>Sveinbjorn</author>
         */
        static public List <posts> GetAllGroupPosts(bubble_groups bubbleGroup)
        {
            var db         = new VERK2015_H17Entities1();
            var groupPosts = (from x in db.posts.Where(y => y.FK_posts_bubble_groups == bubbleGroup.C_ID)
                              select x).ToList();

            return(groupPosts);
        }
Beispiel #15
0
        /* <summary>Gets all events a specified user created</summary>
         * <param name="email">Takes in the email/username of user</param>
         * <returns>list of events created by user</returns>
         * <author>Valgeir</author>
         */
        static public List <events> GetAllEventsCreatedByUser(AspNetUsers user)
        {
            var db         = new VERK2015_H17Entities1();
            var userEvents = (from events in db.events.Where(x => x.FK_events_owner == user.Id)
                              select events).ToList();

            return(userEvents);
        }
Beispiel #16
0
        /* <summary></summary>
         * <param name="ID"></param>
         * <returns></returns>
         * <author></author>
         */
        public static List <chats> SearchChatByName(chats chat)
        {
            var db      = new VERK2015_H17Entities1();
            var chatRes = (from x in db.chats.Where(y => y.chat_name.Contains(chat.chat_name))
                           select x).ToList();

            return(chatRes);
        }
Beispiel #17
0
        /* <summary>Creates a group</summary>
         * <param name="group">bubble group model</param>
         * <returns>New group</returns>
         * <author>Sveinbjorn</author>
         */
        static public bubble_groups CreateGroup(bubble_groups group)
        {
            var db = new VERK2015_H17Entities1();

            db.bubble_groups.Add(group);
            db.SaveChanges();
            return(group);
        }
Beispiel #18
0
        /* <summary></summary>
         * <param name="ID"></param>
         * <returns></returns>
         * <author></author>
         */
        public static List <events> SearchEventsByName(events eventName)
        {
            var db     = new VERK2015_H17Entities1();
            var bEvent = (from x in db.events.Where(y => y.event_name.Contains(eventName.event_name))
                          select x).ToList();

            return(bEvent);
        }
Beispiel #19
0
        /* <summary>Counts the bursts on a post</summary>
         * <param name="postBurst">Post model</param>
         * <returns>Number of bursts on a post</returns>
         * <author>Sveinbjorn</author>
         */
        static public List <post_likes> GetBurstCount(posts postBurst)
        {
            var db         = new VERK2015_H17Entities1();
            var burstCount = (from x in db.post_likes.Where(y => y.posts.C_ID == postBurst.C_ID && y.post_burst == true)
                              select x).ToList();

            return(burstCount);
        }
Beispiel #20
0
        /* <summary>Gets chat users by ID</summary>
         * <param name="chat">Chat model</param>
         * <returns>list of chaat users</returns>
         * <author>Janus</author>
         */
        static public List <AspNetUsers> GetChatUsers(chats chat)
        {
            var db        = new VERK2015_H17Entities1();
            var chatUsers = (from x in db.chat_members.Where(y => y.FK_chat_members_chat == chat.C_ID)
                             select x.AspNetUsers).ToList();

            return(chatUsers);
        }
Beispiel #21
0
        /* <summary>Gets messeages by ID</summary>
         * <param name="chat">Chat model</param>
         * <returns>list of messages</returns>
         * <author>Janus</author>
         */
        static public List <messages> GetMessages(chats chat)
        {
            var db       = new VERK2015_H17Entities1();
            var messages = (from x in db.messages.Where(y => y.FK_messages_chat_id == chat.C_ID)
                            select x).ToList();

            return(messages);
        }
Beispiel #22
0
        /* <summary>Creates an Event</summary>
         * <param name="ev">Event model</param>
         * <returns>New Event</returns>
         * <author>Sveinbjorn</author>
         */
        static public events CreateEvent(events ev)
        {
            var db = new VERK2015_H17Entities1();

            db.events.Add(ev);
            db.SaveChanges();

            return(ev);
        }
Beispiel #23
0
        static public void RenameChat(chats chat)
        {
            var db      = new VERK2015_H17Entities1();
            var getChat = (from x in db.chats.Where(y => y.C_ID == chat.C_ID)
                           select x).SingleOrDefault();

            getChat.chat_name = chat.chat_name;
            db.SaveChanges();
        }
Beispiel #24
0
        /* <summary>
         * Creates a like or a burst into the database depending on the values in the parameter
         * </summary>
         * <param name="postLike">likes_comments object, either with the burst or like value set as 1</param>
         * <returns>Nothing</returns>
         * <author>Janus</author>
         */
        static public void SaveLikeComment(like_comments commentLike)
        {
            var db = new VERK2015_H17Entities1();
            int allowUserToLike = (from x in db.post_likes.Where(y => y.FK_group_post_like_users == commentLike.AspNetUsers.UserName &&
                                                                 y.FK_group_post_likes_group_posts == commentLike.FK_like_comments_post_comments)
                                   select x).Count();

            if (allowUserToLike == 0)
            {
                db.like_comments.Add(commentLike);
                db.SaveChanges();
            }
        }
Beispiel #25
0
        /* <summary>Gets all the chats for a specified user</summary>
         * <param name="user">Takes in obj of user</param>
         * <returns>list of chats for the user</returns>
         * <author>Valgeir</author>
         */
        static public List <chats> GetAllChats(AspNetUsers user)
        {
            //TODO: Change from string to object of user

            var db = new VERK2015_H17Entities1();

            List <chats> chats = (from connection in db.chat_members
                                  where connection.FK_chat_members_user == user.Id
                                  join chat in db.chats on connection.FK_chat_members_chat equals chat.C_ID
                                  select chat).ToList();


            return(chats);
        }
Beispiel #26
0
        /* <summary>Updates profile img for specified user</summary>
         * <param name="user">Takes in obj of user</param>
         * <returns>returns bool, true for success</returns>
         * <author></author>
         */
        static public bool UpdateUserProfileImage(AspNetUsers user)
        {
            var db  = new VERK2015_H17Entities1();
            var usr = (from x in db.AspNetUsers.Where(y => y.UserName == user.UserName)
                       select x).SingleOrDefault();

            if (usr != null)
            {
                usr.profile_image = user.profile_image;
                db.SaveChanges();

                return(true);
            }
            return(false);
        }
Beispiel #27
0
        /* <summary>Gets all the friends of a specified user</summary>
         * <param name="user">Takes in obj of user</param>
         * <returns>list of friends of the user</returns>
         * <author>Valgeir</author>
         */
        static public List <AspNetUsers> GetAllFriends(AspNetUsers user)
        {
            var db = new VERK2015_H17Entities1();

            //Gets a list of friends that user added
            List <AspNetUsers> friendsAdded = (from friend in db.friends_added
                                               .Where(y => y.FK_friends_added_users_Added == user.Id && y.friended == true)
                                               select friend.AspNetUsers1).ToList();
            //Gets a list of friends that added the user
            List <AspNetUsers> friendsAddee = (from friend in db.friends_added
                                               .Where(y => y.FK_friends_added_users_Addee == user.Id && y.friended == true)
                                               select friend.AspNetUsers).ToList();

            //Combines the two lists together
            friendsAdded.AddRange(friendsAddee);
            return(friendsAdded);
        }
Beispiel #28
0
        /* <summary>
         * Creates a like or a burst into the database depending on the values in the parameter
         * </summary>
         * <param name="postLike">post_likes object, either with the burst or like value set as 1</param>
         * <returns>Nothing</returns>
         * <author>Janus</author>
         */
        static public int SaveLikePost(post_likes postLike)
        {
            var db = new VERK2015_H17Entities1();
            int allowUserToLike = (from x in db.post_likes.Where(y => y.FK_group_post_like_users == postLike.FK_group_post_like_users &&
                                                                 y.FK_group_post_likes_group_posts == postLike.FK_group_post_likes_group_posts &&
                                                                 y.post_like == true)
                                   select x).Count();

            if (allowUserToLike == 0)
            {
                db.post_likes.Add(postLike);
                db.SaveChanges();
            }
            int totalPostLikes = (from x in db.post_likes.Where(y => y.FK_group_post_likes_group_posts == postLike.FK_group_post_likes_group_posts &&
                                                                y.post_like == true)
                                  select x).Count();

            return(totalPostLikes);
        }
Beispiel #29
0
        /* <summary>Adds user to chat</summary>
         * <param name="chat">The chat we add the user too</param>
         * <param name="user">The user we add to the chat</param>
         * <returns>nothing</returns>
         * <author>Janus</author>
         */
        static public void AddChatUsers(chats chat, AspNetUsers user)
        {
            var db = new VERK2015_H17Entities1();

            List <chat_members> allChatMemberEntries = GetAllChatMemberEntries();

            bool addUser = (from isMember in allChatMemberEntries
                            where isMember.FK_chat_members_user == user.Id && isMember.FK_chat_members_chat == chat.C_ID
                            select false).DefaultIfEmpty(true).Single();

            if (addUser)
            {
                chat_members member = new chat_members();
                member.FK_chat_members_chat = chat.C_ID;
                member.FK_chat_members_user = user.Id;
                db.chat_members.Add(member);
                db.SaveChanges();
            }
        }
Beispiel #30
0
        /* <summary>Counts the burst on the bubble</summary>
         * <param name="burst">Post like model</param>
         * <returns>The number of bubble bursts</returns>
         * <author>Sveinbjorn</author>
         */
        static public int SaveBurstPost(post_likes burst)
        {
            var db = new VERK2015_H17Entities1();
            int allowUserToBurst = (from x in db.post_likes.Where(y => y.FK_group_post_like_users == burst.FK_group_post_like_users &&
                                                                  y.FK_group_post_likes_group_posts == burst.FK_group_post_likes_group_posts &&
                                                                  y.post_burst == true)
                                    select x).Count();

            if (allowUserToBurst == 0)
            {
                db.post_likes.Add(burst);
                db.SaveChanges();
            }

            var burstCount = (from x in db.post_likes.Where(y => y.FK_group_post_likes_group_posts == burst.FK_group_post_likes_group_posts &&
                                                            y.post_burst == true)
                              select x).Count();

            return(burstCount);
        }