Esempio n. 1
0
        public ActionResult Delete(int id)
        {
            using (NewsContext context = new NewsContext())
            {
                DeleteNodes(context, id);
                context.SaveChanges();
            }

            return RedirectToAction("Index");
        }
Esempio n. 2
0
        public ActionResult Add(int? parentId, string title)
        {
            using (NewsContext context = new NewsContext())
            {
                var newNews = new News()
                {
                    ParentId = parentId,
                    Title = title
                };
                context.News.Add(newNews);
                context.SaveChanges();
            }

            return RedirectToAction("Index");
        }
Esempio n. 3
0
        public ActionResult Move(int nodeId, int? newParentId)
        {
            if (nodeId == newParentId)
            {
                return RedirectToAction("Index");
            }
            using (NewsContext context = new NewsContext())
            {
                if (newParentId.HasValue && ContainsChilds(context, nodeId, newParentId.Value))
                {
                    return RedirectToAction("Index");
                }
                var node = context.News.Where(x => x.Id == nodeId).Single();
                node.ParentId = newParentId;
                context.SaveChanges();
            }

            return RedirectToAction("Index");
        }