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();
     }
 }
        public override void UpdatePost(Post post)
        {
            var context = new BlogsEntities();
            var obj = context.tblBlogs_Posts.Include("Categories").Where(item => item.Id == post.Id).FirstOrDefault();
            post.CopyToObject(obj);

            obj.Categories.Clear();
            if (post.Categories.Count > 0)
            {
                var categories =
                    context.tblBlogs_Categories.Where(
                        Utils.BuildContainsExpression<tblBlogs_Categories, int>(item => item.Id,
                                                                                post.Categories.Select(item => item.Id)));
                foreach (var category in categories)
                {
                    obj.Categories.Add(category);
                }
            }

            context.SaveChanges();
        }
 public override void UpdateComment(Comment comment)
 {
     var context = new BlogsEntities();
     var obj = new tblBlogs_Comments {Id = comment.Id};
     context.AttachTo("tblBlogs_Comments", obj);
     BizObject<Comment, int>.CopyToObject(comment, obj);
     context.SaveChanges();
 }
 public override void UpdateCategory(Category category)
 {
     var context = new BlogsEntities();
     var obj = new tblBlogs_Categories {Id = category.Id};
     context.AttachTo("tblBlogs_Categories", obj);
     BizObject<Category, int>.CopyToObject(category, obj);
     context.SaveChanges();
 }
 public override void UpdateBlogroll(Blogroll blogroll)
 {
     var context = new BlogsEntities();
     var obj = new tblBlogs_Blogrolls {Id = blogroll.Id};
     context.AttachTo("tblBlogs_Blogrolls", obj);
     BizObject<Blogroll, int>.CopyToObject(blogroll, obj);
     context.SaveChanges();
 }
 public override void UpdateBlog(Blog blog)
 {
     var context = new BlogsEntities();
     var obj = new tblBlogs_Blogs {Id = blog.Id};
     context.AttachTo("tblBlogs_Blogs", obj);
     blog.CopyToObject(obj);
     context.SaveChanges();
 }
        public override int InsertPost(Post post)
        {
            var context = new BlogsEntities();
            var obj = new tblBlogs_Posts();
            post.CopyToObject(obj);

            if (post.Categories != null)
            {
                foreach (var category in post.Categories)
                {
                    var item = new tblBlogs_Categories {Id = category.Id};
                    context.AttachTo("tblBlogs_Categories", item);
                    obj.Categories.Add(item);
                }
            }

            context.AddTotblBlogs_Posts(obj);
            context.SaveChanges();
            return obj.Id;
        }
 public override int InsertComment(Comment comment)
 {
     var context = new BlogsEntities();
     var obj = new tblBlogs_Comments();
     BizObject<Comment, int>.CopyToObject(comment, obj);
     context.AddTotblBlogs_Comments(obj);
     context.SaveChanges();
     return obj.Id;
 }
 public override int InsertCategory(Category category)
 {
     var context = new BlogsEntities();
     var obj = new tblBlogs_Categories();
     BizObject<Category, int>.CopyToObject(category, obj);
     context.AddTotblBlogs_Categories(obj);
     context.SaveChanges();
     return obj.Id;
 }
 public override int InsertBlogroll(Blogroll blogroll)
 {
     var context = new BlogsEntities();
     var obj = new tblBlogs_Blogrolls();
     BizObject<Blogroll, int>.CopyToObject(blogroll, obj);
     context.AddTotblBlogs_Blogrolls(obj);
     context.SaveChanges();
     return obj.Id;
 }
 public override void IncreaseViewCount(int postId)
 {
     var context = new BlogsEntities();
     var post = context.tblBlogs_Posts.Where(item => item.Id == postId).First();
     post.ViewCount++;
     context.SaveChanges();
 }