Esempio n. 1
0
        public List <POST> GetUserTimeline(string username)
        {
            var listOfPosts = new List <POST>();

            using (var context = new PastebookEntities())
            {
                listOfPosts = context.POSTs.Include("LIKEs").Include("COMMENTs").Include("USER").Include("COMMENTs.USER").Include("LIKEs.USER").Where(p => p.USER1.USER_NAME == username).OrderByDescending(d => d.CREATED_DATE).Take(100).ToList();
            }

            return(listOfPosts);
        }
Esempio n. 2
0
        public int GetProfileOwnerID(int postID)
        {
            POST post = new POST();

            using (var context = new PastebookEntities())
            {
                post = context.POSTs.FirstOrDefault(p => p.ID == postID);
            }

            return(post.POSTER_ID);
        }
Esempio n. 3
0
        public POST GetPost(int postID)
        {
            POST post = new POST();

            using (var context = new PastebookEntities())
            {
                post = context.POSTs.Include("LIKEs").Include("COMMENTs").Include("USER").Include("USER1").Include("COMMENTs.USER").Include("LIKEs.USER").FirstOrDefault(p => p.ID == postID);
            }

            return(post);
        }
Esempio n. 4
0
        public List <USER> GetListOfFriends(int id)
        {
            var listOfFriendsInformation = new List <USER>();

            using (var context = new PastebookEntities())
            {
                listOfFriendsInformation = context.FRIENDs.Include("USER1").Include("USER").Where(f => f.USER_ID == id && f.REQUEST == "N").Select(f => f.USER).ToList();
            }

            return(listOfFriendsInformation);
        }
Esempio n. 5
0
        public List <POST> GetUserNewsFeed(List <int> listOfFriendsID)
        {
            var listOfPosts = new List <POST>();

            using (var context = new PastebookEntities())
            {
                listOfPosts = context.POSTs.Include("LIKEs").Include("COMMENTs").Include("USER").Include("USER1").Include("COMMENTs.USER").Include("LIKEs.USER").Where(p => listOfFriendsID.Contains(p.POSTER_ID)).OrderByDescending(d => d.CREATED_DATE).ToList();
            }

            return(listOfPosts);
        }
Esempio n. 6
0
        public FRIEND GetFriendRelationship(int id)
        {
            FRIEND getSpecificFriend = new FRIEND();

            using (var context = new PastebookEntities())
            {
                getSpecificFriend = context.FRIENDs.FirstOrDefault(f => f.ID == id);
            }

            return(getSpecificFriend);
        }
Esempio n. 7
0
        public FRIEND GetPendingAndApprovedFriends(int userID, int friendID)
        {
            var friend = new FRIEND();

            using (var context = new PastebookEntities())
            {
                friend = context.FRIENDs.Include("USER1").Include("USER").FirstOrDefault(f => (f.USER_ID == userID && f.FRIEND_ID == friendID) || (f.USER_ID == friendID && f.FRIEND_ID == userID));
            }

            return(friend);
        }
Esempio n. 8
0
        public List <FRIEND> GetPendingFriends(int id)
        {
            var listOfFriendsInformation = new List <FRIEND>();

            using (var context = new PastebookEntities())
            {
                listOfFriendsInformation = context.FRIENDs.Include("USER1").Where(f => f.FRIEND_ID == id && f.REQUEST == "Y").ToList();
            }

            return(listOfFriendsInformation);
        }
Esempio n. 9
0
        public List <int> GetListOfFriendsID(int id)
        {
            List <int> listOfFriendsID = new List <int>();

            using (var context = new PastebookEntities())
            {
                listOfFriendsID = context.FRIENDs.Where(f => f.USER_ID == id && f.REQUEST == "N").Select(f => f.FRIEND_ID).ToList();
            }

            return(listOfFriendsID);
        }
Esempio n. 10
0
        public List <REF_COUNTRY> GetCountryList()
        {
            var countryList = new List <REF_COUNTRY>();

            using (var context = new PastebookEntities())
            {
                countryList = context.REF_COUNTRY.ToList();
            }

            return(countryList);
        }
Esempio n. 11
0
        public LIKE GetLike(LIKE like)
        {
            LIKE specificLike = new LIKE();

            using (var context = new PastebookEntities())
            {
                specificLike = context.LIKEs.FirstOrDefault(l => l.LIKED_BY == like.LIKED_BY && l.POST_ID == like.POST_ID);
            }

            return(specificLike);
        }
Esempio n. 12
0
        /// <summary>
        /// This method checks the database if the username was already existing.
        /// </summary>
        /// <param name="username">Username that is inputted by the user.</param>
        /// <returns>True if the username exists, false if it is available.</returns>
        public bool CheckUsername(string username)
        {
            bool result = false;

            using (var context = new PastebookEntities())
            {
                result = context.USERs.Any(u => u.USER_NAME == username);
            }

            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// This method checks the database if the email address was already existing.
        /// </summary>
        /// <param name="email">Email Address that is inputted by the user.</param>
        /// <returns>True if the email address exists, false if it is available.</returns>
        public bool CheckEmail(string email)
        {
            bool result = false;

            using (var context = new PastebookEntities())
            {
                result = context.USERs.Any(u => u.EMAIL_ADDRESS == email);
            }

            return(result);
        }
Esempio n. 14
0
        public List <NOTIFICATION> GetListOfNotifications(int id)
        {
            List <NOTIFICATION> listOfNotifications = new List <NOTIFICATION>();

            using (var context = new PastebookEntities())
            {
                listOfNotifications = context.NOTIFICATIONs.Include("USER").Include("USER1").Where(n => n.RECEIVER_ID == id).OrderByDescending(n => n.CREATED_DATE).ToList();
            }

            return(listOfNotifications);
        }
Esempio n. 15
0
        /// <summary>
        /// This method get the user from the database.
        /// </summary>
        /// <param name="email">Email that is inputted by the user.</param>
        /// <returns>User information.</returns>
        public USER GetUser(string email, string username)
        {
            var selectedUser = new USER();

            using (var context = new PastebookEntities())
            {
                selectedUser = context.USERs.Include("REF_COUNTRY").FirstOrDefault(u => u.EMAIL_ADDRESS == email || u.USER_NAME == username);
            }

            return(selectedUser);
        }
Esempio n. 16
0
        public NOTIFICATION GetNotificationForFriendRequest(FRIEND friend)
        {
            NOTIFICATION notification = new NOTIFICATION();

            using (var context = new PastebookEntities())
            {
                notification = context.NOTIFICATIONs.FirstOrDefault(n => n.SENDER_ID == friend.USER_ID && n.RECEIVER_ID == friend.FRIEND_ID && n.NOTIF_TYPE == "F");
            }

            return(notification);
        }
Esempio n. 17
0
        public NOTIFICATION GetNotificationForLike(LIKE like)
        {
            NOTIFICATION notification = new NOTIFICATION();

            using (var context = new PastebookEntities())
            {
                notification = context.NOTIFICATIONs.FirstOrDefault(n => n.POST_ID == like.POST_ID && n.SENDER_ID == like.LIKED_BY && n.NOTIF_TYPE == "L");
            }

            return(notification);
        }
Esempio n. 18
0
        public List <NOTIFICATION> GetListOfNotSeenNotifications(int id)
        {
            List <NOTIFICATION> listOfNotifications = new List <NOTIFICATION>();

            using (var context = new PastebookEntities())
            {
                listOfNotifications = context.NOTIFICATIONs.Include("USER").Include("USER1").Where(n => n.RECEIVER_ID == id && n.SEEN == "N").ToList();
            }

            return(listOfNotifications);
        }
Esempio n. 19
0
        public int GetCountOfNotSeenNotifications(int id)
        {
            int count = 0;

            using (var context = new PastebookEntities())
            {
                count = context.NOTIFICATIONs.Include("USER").Include("USER1").Where(n => n.RECEIVER_ID == id && n.SEEN == "N").ToList().Count;
            }

            return(count);
        }
Esempio n. 20
0
        public int Create(T items)
        {
            int result = 0;

            using (var context = new PastebookEntities())
            {
                context.Entry(items).State = EntityState.Added;
                result = context.SaveChanges();
            }

            return(result);
        }
Esempio n. 21
0
        public List <USER> GetListOfUsers(string name, int id)
        {
            List <USER> listOfUsers = new List <USER>();

            using (var context = new PastebookEntities())
            {
                //http://stackoverflow.com/questions/5676040/search-two-columns-in-linq-to-sql

                listOfUsers = (from user in context.USERs
                               let fullname = user.FIRST_NAME + " " + user.LAST_NAME
                                              where fullname == name || user.FIRST_NAME == name || user.LAST_NAME == name
                                              select user).ToList();
            }

            return(listOfUsers);
        }