public static void DeleteTweet(int id) { using (var ctx = new EFMVCContext()) { var tweet = ctx.Tweets.FirstOrDefault(a => a.tweet_id == id); ctx.Tweets.Remove(tweet); ctx.SaveChanges(); } }
public static void DeletePerson(string id) { using (var ctx = new EFMVCContext()) { var person = ctx.People.FirstOrDefault(a => a.user_id == id); person.active = false; ctx.Entry(person).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public static void EditTweet(TweetModel model) { using (var ctx = new EFMVCContext()) { var tweet = ctx.Tweets.FirstOrDefault(a => a.tweet_id == model.TweetId); tweet.message = model.Message; ctx.Tweets.Remove(model.GetTweet()); ctx.SaveChanges(); } }
public static void Signup(PersonModel personModel) { using (var ctx = new EFMVCContext()) { personModel.Joined = DateTime.Now; personModel.Active = true; personModel.Password = CreateMD5(personModel.Password); ctx.People.Add(personModel.GetPerson()); ctx.SaveChanges(); } }
public static TweetModel AddTweet(TweetModel model) { using (var ctx = new EFMVCContext()) { if (model.TweetId == 0) { model.Created = DateTime.Now; var tweet = model.GetTweet(); ctx.Tweets.Add(tweet); ctx.SaveChanges(); return(tweet.GetTweetModel()); } else { var tweet = ctx.Tweets.FirstOrDefault(a => a.tweet_id == model.TweetId); tweet.message = model.Message; ctx.Entry(tweet).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); return(tweet.GetTweetModel()); } } }
public static PersonModel Profile(PersonModel personModel) { using (var ctx = new EFMVCContext()) { var person = ctx.People.FirstOrDefault(a => a.user_id == personModel.UserId); person.password = CreateMD5(personModel.Password); person.fullName = personModel.FullName; person.email = personModel.Email; ctx.People.Add(person); ctx.Entry(person).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); return(person.GetPersonModel()); } }
public static List <PersonModel> FollowPerson(string id, string currentuserid) { using (var ctx = new EFMVCContext()) { var person = ctx.People.FirstOrDefault(a => a.user_id == id); var currentuser = ctx.People.FirstOrDefault(a => a.user_id == currentuserid); if (person.Person1.Where(a => a.user_id == currentuserid).Count() > 0) { person.Person1.Remove(currentuser); } else { currentuser.People.Add(person); } ctx.SaveChanges(); return(currentuser.Person1.Select(a => a.GetPersonModel()).ToList()); } }