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); }
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); } } }
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(); } }
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); } }
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(); } }
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(); } }
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(); } }
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); } } }
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); }
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); }
//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); } } }
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); }
//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); } } }
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); }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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
public List <User> GetUser() { using (var context = new TweetContext()) { try { List <User> users = context.Users.ToList(); return(users); } catch (Exception) { return(null); } } }
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); } } }
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); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }