Пример #1
0
        public List <Tweet> GetFollowingTimeline()
        {
            if (user == null)
            {
                throw new Exception("User is not set");
            }
            List <Tweet> timeline = new List <Tweet>();

            using (var context = new TweetContext())
            {
                List <Following> followings = user.Following;
                if (followings == null || followings.Count == 0)
                {
                    return(null);
                }
                foreach (Following following in followings)
                {
                    User followingUser = Twitter.GetUserFromName(following.Name);
                    timeline.AddRange(GetTimeline(followingUser));
                }
                timeline.AddRange(GetTimeline(user));
            }
            timeline = timeline.OrderBy(b => b.DateCreated).ToList();
            return(timeline);
        }
Пример #2
0
 public void DeleteUser(string name)
 {
     using (var context = new TweetContext())
     {
         try{
             List <User> userlist = context.Users.Where(b => b.Name.Equals(name)).ToList();
             if (userlist.Count < 0)
             {
                 throw new Exception("User not exists");
             }
             List <User> followingList = context.Users.Where(b => b.Name.Equals(name)).Include(u => u.Following).ToList();
             foreach (User following in followingList)
             {
                 Twitter t = new Twitter(userlist[0].Name);
                 t.RemoveFollowing(following.Name);
             }
             List <User> followList = context.Users.Where(b => true).Include(u => u.Following).ToList();
             foreach (User follow in followingList)
             {
                 Twitter t = new Twitter(follow.Name);
                 t.RemoveFollowing(userlist[0].Name);
             }
             context.Users.Remove(userlist[0]);
             context.SaveChanges();
         }catch (Exception ex) {
             Console.WriteLine(ex);
         }
     }
 }
Пример #3
0
 public void AddFollowing(string followingName)
 {
     if (user == null)
     {
         throw new Exception("User is not set");
     }
     if (followingName == null)
     {
         throw new Exception("Following not found");
     }
     using (var context = new TweetContext())
     {
         if (user.Following == null)
         {
             user.Following = new List <Following>();
         }
         List <Following> followings = user.Following.Where(b => b.Name == followingName).ToList();
         if (followings.Count > 0)
         {
             return;
         }
         Following following = new Following();
         following.Name = followingName;
         user.Following.Add(following);
         context.Users.Update(user);
         context.SaveChanges();
     }
 }
Пример #4
0
 public static string GenSession(string username)
 {
     try
     {
         using (MD5 md5 = MD5.Create())
         {
             md5.Initialize();
             md5.ComputeHash(Encoding.UTF8.GetBytes(username + DateTime.Now.ToString()));
             // It's annoying that toString is not working here.
             StringBuilder sbhash = new StringBuilder();
             byte[]        hash   = md5.Hash;
             for (int i = 0; i < hash.Length; i++)
             {
                 sbhash.Append(hash[i].ToString("x2"));
             }
             string newSession = sbhash.ToString();
             //Update session.
             using (var context = new TweetContext())
             {
                 List <User> users = context.Users.Where(b => b.Name.Equals(username)).ToList();
                 User        aUser = users[0];
                 aUser.Session = newSession;
                 context.Users.Update(aUser);
                 context.SaveChanges();
             }
             return(newSession);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Пример #5
0
 public static void DeleteUser(string name)
 {
     using (var context = new TweetContext())
     {
         List <User> user = context.Users.Where(b => b.Name.Equals(name)).ToList();
         context.Users.Remove(user[0]);
         context.SaveChanges();
     }
 }
Пример #6
0
 public void RemoveUser(string R_user)
 {
     using (var context = new TweetContext())
     {
         List <User> user = context.Users.Where(b => b.Name.Equals(R_user)).ToList();
         context.Users.Remove(user[0]);
         context.SaveChanges();
     }
 }
Пример #7
0
 public static void RemoveSession(string username)
 {
     using (var context = new TweetContext())
     {
         List <User> users = context.Users.Where(b => b.Name.Equals(username)).ToList();
         User        aUser = users[0];
         aUser.Session = null;
         context.Users.Update(aUser);
         context.SaveChanges();
     }
 }
Пример #8
0
 Private List <User> GetUser()
 {
     using (var newContext = new TweetContext()){
         try{
             List <User> users = newContext.Users.Where(b => true).Include(base => base.Following).ToList();
             return(users);
         }
         catch (Exception) {
             return(null);
         }
     }
 }
Пример #9
0
 public static bool Check_Username(string name)
 {
     using (var context = new TweetContext())
     {
         List <User> userlist = context.Users.Where(b => b.Name.Equals(name)).ToList();
         if (userlist.Count == 1) //check if there is any user in the list
         {
             return(true);
         }
     }
     return(false);
 }
Пример #10
0
 public static bool UserCheck(string name)
 {
     using (var context = new TweetContext())
     {
         List <User> userlist = context.Users.Where(b => b.Name.Equals(name)).ToList();
         if (userlist.Count == 1)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #11
0
 //get following list
 private List <User> GetListFollowing(string user)
 {
     using (var context = new TweetContext()){
         try{
             List <User> users = context.Users.Where(u => u.Name.Equals(user)).Include(u => u.Following).ToList();
             return(users);
         }catch (Exception ex) {
             Console.WriteLine(ex.ToString());
             return(null);
         }
     }
 }
Пример #12
0
 public static bool IsValidUser(string name, string password)
 {
     using (var context = new TweetContext())
     {
         List <User> userlist = context.Users.Where(b => b.Name.Equals(name) && b.Password.Equals(password)).ToList();
         if (userlist.Count == 1)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #13
0
 //get user list
 private List <User> GetListUser()
 {
     // ref TwitterPlugin.cs
     using (var context = new TweetContext()){
         try{
             List <User> users = context.Users.Where(b => true).Include(b => b.Following).ToList();// using true for all user in db
             return(users);
         }catch (Exception ex) {
             Console.WriteLine(ex.ToString());
             return(null);
         }
     }
 }
Пример #14
0
        public List <Tweet> GetTimeline(User aUser)
        {
            if (aUser == null)
            {
                throw new Exception("User is not set");
            }
            List <Tweet> timeline;

            using (var context = new TweetContext())
            {
                timeline = context.Tweets.Where(b => b.User.Equals(aUser.Name)).OrderBy(b => b.DateCreated).ToList();
            }
            return(timeline);
        }
Пример #15
0
 private List <Following> ListFollow(string F)
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> ListFollow = context.Users.Where(b => b.Name.Equals(F)).Include(b => b.Following).ToList(); //ListFollow users store in ListFollow
             return(ListFollow[0].Following);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #16
0
 public static User GetUserFromSession(string session)
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> users = context.Users.Where(b => b.Session.Equals(session)).Include(b => b.Following).ToList();
             return(users[0]);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #17
0
 public bool chack(string follow)
 {
     using (var context = new TweetContext())
     {
         List <User> user = context.Users.Where(b => b.Name.Equals(follow)).ToList();
         if (user.Count == 1) //if any follow in user return true
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Пример #18
0
 private User GetUser(string name)
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> users = context.Users.Where(b => b.Name.Equals(name)).Include(b => b.Following).ToList();
             return(users[0]);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #19
0
 private List <User> ListUsers()
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> users = context.Users.ToList(); //list users store in users .
             return(users);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #20
0
 public List <Following> GetFollowing(string name)
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> followings = context.Users.Where(b => b.Name.Equals(name)).Include(b => b.Following).ToList();
             return(followings[0].Following);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #21
0
 public List <User> GetAllUsers()
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> users = context.Users.Where(b => true).Include(b => b.Following).ToList();
             return(users);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #22
0
 public List <Following> GetFollowing()
 {
     if (user == null)
     {
         throw new Exception("User is not set");
     }
     using (var newContext = new TweetContext()){
         List <Following> following = user.Following;
         if (following == null || following.Count == 0)
         {
             return(null);
         }
         return(following);
     }
 }//taught by 600611001
Пример #23
0
 public List <User> GetUser()
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> users = context.Users.ToList();
             return(users);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #24
0
 private User AllUsers()//all user
 {
     using (var context = new TweetContext())
     {
         try
         {
             List <User> users = context.Users.Where(b => true).Include(b => b.Following).ToList();
             return(users[0]);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Пример #25
0
 public List <Following> GetFollowing()
 {
     if (user == null)
     {
         throw new Exception("User is not set");
     }
     using (var context = new TweetContext())
     {
         List <Following> followings = user.Following;
         if (followings == null || followings.Count == 0)
         {
             return(null);
         }
         return(followings);
     }
 }
Пример #26
0
        public static void DeleteUser(string name)
        {
            User user = new User();

            user.Name = name;
            using (var context = new TweetContext())
            {
                List <User> userlist = context.Users.Where(b => b.Name.Equals(name)).ToList();
                if (userlist.Count <= 0)
                {
                    throw new Exception("User not exists");
                }
                context.Users.Remove(userlist[0]);
                context.SaveChanges();
            }
        }
Пример #27
0
        public static void AddUser(string name, string password)
        {
            User user = new User();

            user.Name     = name;
            user.Password = password;
            using (var context = new TweetContext())
            {
                List <User> userlist = context.Users.Where(b => b.Name.Equals(name)).ToList();
                if (userlist.Count > 0)
                {
                    throw new Exception("User already exists");
                }
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Пример #28
0
        public void PostTweet(string message)
        {
            if (user == null)
            {
                throw new Exception("User is not set");
            }
            Tweet tweet = new Tweet();

            tweet.User        = user.Name;
            tweet.Message     = message;
            tweet.DateCreated = DateTime.Now;
            using (var context = new TweetContext())
            {
                context.Tweets.Add(tweet);
                context.SaveChanges();
            }
        }
Пример #29
0
 public static void RemoveUser(string user)
 {
     if (user == null)
     {
         throw new Exception("User is not set");
     }
     using (var context = new TweetContext())
     {
         List <User> listuser = context.Users.Where(b => b.Name.Equals(user)).ToList();
         if (listuser.Count < 1)
         {
             throw new Exception("User not found");
         }
         context.Users.Remove(listuser[0]);
         context.SaveChanges();
     }
 }
Пример #30
0
        public static void DeleteUser(string name, string password)
        {
            User user = new User();

            user.Name     = name;
            user.Password = password;
            using (var context = new TweetContext())
            {
                List <User> userlist = context.Users.Where(b => b.Name.Equals(name)).ToList();

                if (userlist.Count == 0)
                {
                    throw new Exception("Not found User");
                }
                context.Users.Remove(user);
                context.SaveChanges();
            }
        }