static public void CreateMessage(messages message) { var db = new VERK2015_H17Entities1(); db.messages.Add(message); db.SaveChanges(); }
/* * <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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(); }
/* <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(); }
/* <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); }
/* <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(); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
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(); }
/* <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(); } }
/* <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); }
/* <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); }
/* <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); }
/* <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); }
/* <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(); } }
/* <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); }