예제 #1
0
 public Post GetById(int id)
 {
     using (var context = new PostsContext(_connectionString))
     {
         return(context.Posts.FirstOrDefault(p => p.Id == id));
     }
 }
예제 #2
0
 public List <Post> GetPosts()
 {
     using (var context = new PostsContext(_connectionString))
     {
         return(context.Posts.OrderByDescending(p => p.DateSubmitted).ToList());
     }
 }
예제 #3
0
 public int GetLikesCount(int Id)
 {
     using (var context = new PostsContext(_connectionString))
     {
         var post = context.Posts.FirstOrDefault(p => p.Id == Id);
         return(post.Likes);
     }
 }
예제 #4
0
 public void AddLike(int Id)
 {
     using (var context = new PostsContext(_connectionString))
     {
         context.Posts.FirstOrDefault(p => p.Id == Id).Likes++;
         context.SaveChanges();
     }
 }
예제 #5
0
 public void AddPost(Post post)
 {
     using (var context = new PostsContext(_connectionString))
     {
         context.Posts.Add(post);
         context.SaveChanges();
     }
 }