Example #1
0
 public void removeUser(int userId)
 {
     using (var ctx = new Models.Model())
     {
         ctx.users.Remove(ctx.users.FirstOrDefault(x => x.userId == userId));
         ctx.SaveChanges();
     }
 }
Example #2
0
 public void removeComment(int commentId)
 {
     using (var ctx = new Models.Model())
     {
         ctx.comments.Remove(ctx.comments.FirstOrDefault(x => x.commentId == commentId));
         ctx.SaveChanges();
     }
 }
Example #3
0
 public void removePost(int postId)
 {
     using (var ctx = new Models.Model())
     {
         ctx.posts.Remove(ctx.posts.FirstOrDefault(x => x.postId == postId));
         ctx.SaveChanges();
     }
 }
Example #4
0
 public Types.Comment updateComment(Types.Comment c)
 {
     using (var ctx = new Models.Model())
     {
         Models.Comment c1 = ctx.comments.FirstOrDefault(x => x.commentId == c.commentId);
         c1.time        = c.time;
         c1.description = c.description;
         c1.upvotes     = c.upvotes;
         ctx.SaveChanges();
         return(c);
     }
 }
Example #5
0
 public Types.User updateUser(Types.User u)
 {
     using (var ctx = new Models.Model())
     {
         Models.User u1 = ctx.users.FirstOrDefault(x => x.userId == u.userId);
         u1.username  = u.username;
         u1.firstName = u.firstName;
         u1.lastName  = u.lastName;
         u1.password  = u.password;
         ctx.SaveChanges();
         return(u);
     }
 }
Example #6
0
 public Types.Post updatePost(Types.Post p)
 {
     using (var ctx = new Models.Model())
     {
         Models.Post p1 = ctx.posts.FirstOrDefault(x => x.postId == p.postId);
         p1.headline    = p.headline;
         p1.time        = p.time;
         p1.description = p.description;
         p1.upvotes     = p.upvotes;
         ctx.SaveChanges();
         return(p);
     }
 }
Example #7
0
 public int addUser(Types.User u)
 {
     using (var ctx = new Models.Model())
     {
         Models.User u1 = new Models.User();
         u1.username  = u.username;
         u1.firstName = u.firstName;
         u1.lastName  = u.lastName;
         u1.password  = u.password;
         ctx.users.Add(u1);
         ctx.SaveChanges();
         return(u1.userId);
     }
 }
Example #8
0
 public int addPost(Types.Post p)
 {
     using (var ctx = new Models.Model())
     {
         Models.Post p1 = new Models.Post();
         p1.headline    = p.headline;
         p1.time        = p.time;
         p1.description = p.description;
         p1.upvotes     = p.upvotes;
         Models.User u = ctx.users.FirstOrDefault(x => x.userId == p.user.userId);
         p1.user = u;
         ctx.posts.Add(p1);
         ctx.SaveChanges();
         return(p1.postId);
     }
 }
Example #9
0
 public int addComment(Types.Comment c)
 {
     using (var ctx = new Models.Model())
     {
         Models.Comment c1 = new Models.Comment();
         c1.time        = c.time;
         c1.description = c.description;
         c1.upvotes     = c.upvotes;
         if (c.replyOfComment != -1)
         {
             c1.replyOfComment = ctx.comments.FirstOrDefault(x => x.commentId == c.replyOfComment);
         }
         Models.User u = ctx.users.FirstOrDefault(x => x.userId == c.user.userId);
         c1.user = u;
         Models.Post p = ctx.posts.FirstOrDefault(x => x.postId == c.post.postId);
         c1.post = p;
         ctx.comments.Add(c1);
         ctx.SaveChanges();
         return(c1.commentId);
     }
 }