public void RemoveFollower(int followeeId, int followerId) { TwitDbContext db = new TwitDbContext(); int id = db.Follows.Where(f => f.FolloweeId == followeeId && f.FollowerId == followerId).FirstOrDefault().Id; db.Follows.Remove(db.Follows.Where(f => f.Id == id).FirstOrDefault()); db.SaveChanges(); }
public int CreateTweet(int posterId, string body) { TwitDbContext db = new TwitDbContext(); db.Tweets.Add(new Tweet(body, posterId)); db.SaveChanges(); return db.Tweets.Where(t => t.Body == body).Last().TweetId; }
public void AddFollower(int followeeId, int followerId) { TwitDbContext db = new TwitDbContext(); if (db.Follows.Where(f => f.FolloweeId == followeeId && f.FollowerId == followerId).FirstOrDefault() != null) { db.Follows.Add(new Follow { FolloweeId = followeeId, FollowerId = followerId }); } db.SaveChanges(); }
public void DeleteTweet(int deleterId, int tweetId) { TwitDbContext db = new TwitDbContext(); Tweet tweet = db.Tweets.Where(t => t.TweetId == tweetId).FirstOrDefault(); int authorId = tweet.Twit.PersonId; if (tweet != null && deleterId == authorId) { tweet.Visible = false; } db.SaveChanges(); }
public int CreatePerson(string name, string aboutMe, string imgUrl, bool isUser) { Person person = new Person(name, aboutMe, imgUrl, isUser); TwitDbContext db = new TwitDbContext(); //check to see if someone else is the user if (isUser) { List<Person> currentUsers = db.People.Where(p => p.IsUser).ToList(); foreach (var p in currentUsers) { p.IsUser = false; } } db.People.Add(person); db.SaveChanges(); return db.People.Last().PersonId; }
public int SetUser(int personId) { TwitDbContext db = new TwitDbContext(); //check to see if anyone else is a user List<Person> currentUsers = db.People.Where(p => p.IsUser).ToList(); foreach (var p in currentUsers) { p.IsUser = false; } db.People.Where(p => p.PersonId == personId).FirstOrDefault().IsUser = true; db.SaveChanges(); return db.People.Where(p => p.IsUser).FirstOrDefault().PersonId; }