Beispiel #1
0
        private void DeleteLoop(WA_Blogs blog)
        {
            var Blogs1 = blog.WA_Blogs1.ToList();

            for (int i = 0; i < Blogs1.Count; i++)
            {
                DeleteLoop(Blogs1[i]);
            }
            var Posts = blog.WA_Posts.ToList();

            for (int i = 0; i < Posts.Count; i++)
            {
                WA_Posts wa_posts = Posts[i];
                if (wa_posts != null)
                {
                    var comments = wa_posts.WA_Comments.ToList();
                    for (int j = 0; j < comments.Count; j++)
                    {
                        DeleteComments(comments[j]);
                    }
                    var likes = wa_posts.WA_Likes.ToList();
                    for (int j = 0; j < likes.Count; j++)
                    {
                        db.WA_Likes.Remove(likes[j]);
                        db.SaveChanges();
                    }
                    db.WA_Posts.Remove(wa_posts);
                    db.SaveChanges();
                }
            }

            db.WA_Blogs.Remove(blog);
            db.SaveChanges();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            WA_Posts wa_posts = db.WA_Posts.Single(n => n.PostID == id);

            if (wa_posts != null)
            {
                var blogs = wa_posts.WA_Blogs.ToList();
                for (int i = 0; i < blogs.Count; i++)
                {
                    WA_Blogs blog = blogs[i];
                    blog.WA_Posts.Remove(wa_posts);
                    db.Entry(blog).State = EntityState.Modified;
                    db.SaveChanges();
                }
                var comments = wa_posts.WA_Comments.ToList();
                for (int i = 0; i < comments.Count; i++)
                {
                    DeleteComments(comments[i]);
                }
                var likes = wa_posts.WA_Likes.ToList();
                for (int i = 0; i < likes.Count; i++)
                {
                    db.WA_Likes.Remove(likes[i]);
                    db.SaveChanges();
                }
                db.WA_Posts.Remove(wa_posts);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        private List <WA_Posts> GetAllPost(WA_Blogs blog)
        {
            List <WA_Posts> listpost = blog.WA_Posts.ToList();

            foreach (var item in blog.WA_Blogs1)
            {
                listpost.AddRange(GetAllPost(item));
            }
            return(listpost);
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "BlogID,Name,Parent,Order,Active")] WA_Blogs wa_blogs)
        {
            if (ModelState.IsValid)
            {
                db.WA_Blogs.Add(wa_blogs);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(wa_blogs));
        }
Beispiel #5
0
        // GET: /Blogs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WA_Blogs wa_blogs = db.WA_Blogs.Find(id);

            if (wa_blogs == null)
            {
                return(HttpNotFound());
            }
            return(View(wa_blogs));
        }
Beispiel #6
0
        public ActionResult QuickEdit([Bind(Include = "BlogID,Name,Parent,Order")] WA_Blogs wa_blogs, HttpPostedFileBase filebase)
        {
            if (ModelState.IsValid)
            {
                WA_Blogs change = db.WA_Blogs.Find(wa_blogs.BlogID);
                change.Name   = wa_blogs.Name;
                change.Parent = wa_blogs.Parent;
                change.Order  = wa_blogs.Order;

                db.Entry(change).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(wa_blogs));
        }
Beispiel #7
0
        public ActionResult Edit([Bind(Include = "BlogID,Name,Parent,Order,Active")] WA_Blogs wa_blogs)
        {
            if (ModelState.IsValid)
            {
                WA_Blogs change = db.WA_Blogs.Find(wa_blogs.BlogID);
                change.Name   = wa_blogs.Name;
                change.Parent = wa_blogs.Parent;
                change.Active = wa_blogs.Active;

                db.Entry(change).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(wa_blogs));
        }
Beispiel #8
0
        //GET: //Blogs/Name-Blog
        public ActionResult ViewBlogs(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            WA_Blogs wa_blogs = db.WA_Blogs.FirstOrDefault(x => x.BlogID == id);

            if (wa_blogs == null)
            {
                return(HttpNotFound());
            }
            ViewBag.NameBlogs = wa_blogs.Name;
            var listPost = GetAllPost(wa_blogs).OrderByDescending(x => x.Created).Distinct().ToList();

            //string titleEncode = UrlEncode.ToFriendlyUrl(wa_blogs.Name);
            return(View(listPost));
        }
Beispiel #9
0
        // GET: /Blogs/Edit/5
        public ActionResult Edit(int?id)
        {
            List <SelectListItem> selectlist = new SelectList(db.WA_Blogs.Where(x => x.Active == true).ToList(), "BlogID", "Name").ToList();

            selectlist.Insert(0, new SelectListItem
            {
                Selected = true,
                Text     = "",
                Value    = null
            });
            ViewBag.Parent = selectlist.ToList();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WA_Blogs wa_blogs = db.WA_Blogs.Find(id);

            if (wa_blogs == null)
            {
                return(HttpNotFound());
            }
            return(View(wa_blogs));
        }