예제 #1
0
 public User GetUserById(int id)
 {
     using (var dbContext = new TwitterEntities())
     {
         var userForUpdate = dbContext.Users.FirstOrDefault(currentUser => currentUser.id_user == id);
         return userForUpdate;
     }
 }
예제 #2
0
 public Tweet Get(int id)
 {
     using (var dbItem = new TwitterEntities())
     {
         var findTweet = dbItem.Tweets.FirstOrDefault(currentTweet => currentTweet.id_tweet == id);
         return findTweet;
     }
 }
예제 #3
0
 public List<User> GetAll()
 {
     using (var dbContext = new TwitterEntities())
     {
         var allUsers = dbContext.Users.ToList();
         return allUsers;
     }
 }
예제 #4
0
 public bool Add(Tweet tweet)
 {
     using (var dbItem = new TwitterEntities())
     {
         dbItem.Tweets.Add(tweet);
         return dbItem.SaveChanges() > 0;
     }
 }
예제 #5
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;
     }
 }
예제 #6
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;
     }
 }
예제 #7
0
 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();
     }
 }
예제 #8
0
 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;
     }
 }
예제 #9
0
 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;
     }
 }
예제 #10
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;
     }
 }
예제 #11
0
 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;
     }
 }
예제 #12
0
 public User GetUserForLogin(string email)
 {
     using (var dbContext = new TwitterEntities())
     {
         var user=dbContext.Users.Where(currentUser => currentUser.Email == email).FirstOrDefault();
         return user;
     }
 }
예제 #13
0
 public bool Save(User user)
 {
     using (var dbContext = new TwitterEntities())
     {
         dbContext.Users.Attach(user);
         dbContext.Entry(user).State = EntityState.Modified;
         dbContext.SaveChanges();
         return true;
     }
 }