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