Beispiel #1
0
 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();
     }
 }
Beispiel #2
0
 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();
     }
 }
Beispiel #3
0
 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();
     }
 }
Beispiel #4
0
 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();
     }
 }
Beispiel #5
0
 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());
         }
     }
 }
Beispiel #6
0
 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());
     }
 }
Beispiel #7
0
 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());
     }
 }