Пример #1
0
 public static bool RemovePost(this DBEntities DB, int Id)
 {
     BeginTransaction(DB);
     DB.DoRemovePost(Id);
     Commit();
     return(true);
 }
Пример #2
0
        public static bool DoRemovePost(this DBEntities DB, int Id)
        {
            Post postToDelete = DB.Posts.Find(Id);

            if (postToDelete != null)
            {
                var childs = DB.PostsChilds.Where(pc => pc.PostId == Id).ToArray();

                if (childs != null)
                {
                    for (int i = 0; i < childs.Count(); i++)
                    {
                        DB.DoRemovePost(childs[i].ChildPostId);
                    }
                }
                PostsChild childpostToDelete = DB.PostsChilds.Where(pc => pc.ChildPostId == Id).FirstOrDefault();
                if (childpostToDelete != null)
                {
                    DB.PostsChilds.Remove(childpostToDelete);
                }
                DB.Posts.Remove(postToDelete);
                DB.SaveChanges();
                PostsLastUpdate = DateTime.Now;
                return(true);
            }
            return(false);
        }