public override void DeleteComment(int id) { var context = new BlogsEntities(); var obj = new tblBlogs_Comments {Id = id}; context.AttachTo("tblBlogs_Comments", obj); context.DeleteObject(obj); context.SaveChanges(); }
public override void DeletePost(int id) { var context = new BlogsEntities(); using (var transaction = new TransactionScope()) { var post = context.tblBlogs_Posts.Include("Categories").Where(item => item.Id == id).FirstOrDefault(); post.Categories.Clear(); context.SaveChanges(); var comments = context.tblBlogs_Comments.Where(item => item.PostId == post.Id); foreach (var comment in comments) { context.DeleteObject(comment); } context.DeleteObject(post); context.SaveChanges(); transaction.Complete(); } }
public override void DeleteBlog(int id) { var context = new BlogsEntities(); var obj = context.tblBlogs_Blogs.Where(item => item.Id == id).FirstOrDefault(); if (obj != null) { context.DeleteObject(obj); context.SaveChanges(); } }