Пример #1
0
 public bool dellPost(int id)
 {
     PostsContext _db = new PostsContext();
     var comment = _db.posts.Where(p => p.id == id).FirstOrDefault();
     if (comment != null)
     {
         _db.posts.Remove(comment);
         _db.SaveChanges();
     }
     return false;
 }
Пример #2
0
 public Post EditPost(Post newPost)
 {
     if (newPost.id_user != null && newPost.id_user != 0 && newPost.title.Trim() != "")
     {
         PostsContext _db = new PostsContext();
         _db.Entry(newPost).State = EntityState.Modified;
         _db.SaveChanges();
         return newPost;
     }
     return null;
 }
Пример #3
0
 public Post AddPost(Post newPost)
 {
     if (newPost.id_user != null && newPost.id_user != 0 && newPost.title.Trim() != "")
     {
         PostsContext _db = new PostsContext();
         _db.posts.Add(newPost);
         _db.SaveChanges();
         var postId = _db.posts.Select(id => id.id).Max();
         newPost.id = postId;
         return newPost;
     }
     return null;
 }