public User GetUserById(int id) { using (var dbContext = new TwitterEntities()) { var userForUpdate = dbContext.Users.FirstOrDefault(currentUser => currentUser.id_user == id); return userForUpdate; } }
public Tweet Get(int id) { using (var dbItem = new TwitterEntities()) { var findTweet = dbItem.Tweets.FirstOrDefault(currentTweet => currentTweet.id_tweet == id); return findTweet; } }
public List<User> GetAll() { using (var dbContext = new TwitterEntities()) { var allUsers = dbContext.Users.ToList(); return allUsers; } }
public bool Add(Tweet tweet) { using (var dbItem = new TwitterEntities()) { dbItem.Tweets.Add(tweet); return dbItem.SaveChanges() > 0; } }
public bool Save(Tweet tweet) { using (var dbItem = new TwitterEntities()) { dbItem.Tweets.Attach(tweet); dbItem.Entry(tweet).State = EntityState.Modified; return dbItem.SaveChanges() > 0; } }
public bool ConfirmActivated(string email) { using (var dbContext = new TwitterEntities()) { var activated = dbContext.Users.Any(currentUser => currentUser.Email == email && currentUser.Activated == true); if (activated == true) return true; else return false; } }
public List<Tweet> GetAll(int id) { using (var dbItem = new TwitterEntities()) { var findTweet = from myTweet in dbItem.Tweets where myTweet.id_user==id select myTweet; return findTweet.ToList(); } }
public bool Add(User user) { using (var dbContext = new TwitterEntities()) { user.Password = Encryptdata(user.Password); dbContext.Users.Add(user); if (dbContext.SaveChanges() > 0) return true; else return false; } }
public bool Delete(int id) { using (var dbItem = new TwitterEntities()) { var _tweet = dbItem.Tweets.Find(id); if (!(_tweet).Equals(null)) { dbItem.Tweets.Remove(_tweet); } return dbItem.SaveChanges() > 0; } }
public bool Activated(string email) { using (var dbContext = new TwitterEntities()) { var result = dbContext.Users.Where(currentUser => currentUser.Email == email).FirstOrDefault(); result.Activated = true; dbContext.Users.Attach(result); dbContext.Entry(result).State = EntityState.Modified; if ( dbContext.SaveChanges() > 0) return true; else return false; } }
public bool Delete(int id) { using (var dbContext = new TwitterEntities()) { var userToDelete = dbContext.Users.FirstOrDefault(currentUser => currentUser.id_user == id); var tweetToDelete = from tweet in dbContext.Tweets where tweet.id_user == id select tweet; foreach(var tweet in tweetToDelete){ dbContext.Tweets.Remove(tweet); } dbContext.Users.Remove(userToDelete); if (dbContext.SaveChanges() > 0) return true; else return false; } }
public User GetUserForLogin(string email) { using (var dbContext = new TwitterEntities()) { var user=dbContext.Users.Where(currentUser => currentUser.Email == email).FirstOrDefault(); return user; } }
public bool Save(User user) { using (var dbContext = new TwitterEntities()) { dbContext.Users.Attach(user); dbContext.Entry(user).State = EntityState.Modified; dbContext.SaveChanges(); return true; } }