public ActionResult Edit(int?ID, int?ParentID)
        {
            CMSPage page = new CMSPage()
            {
                ParentID = 0, Visible = true, ViewMenu = true
            };

            if (!ID.HasValue || ID == 0)
            {
                ViewBag.Header = "Создание нового раздела";

                var parent = CMSPage.FullPageTable.FirstOrDefault(x => x.ID == ParentID);
                if (parent != null)
                {
                    parent.RolesList = null;
                    page.RolesList   = parent.RolesList;
                }
            }
            else
            {
                ViewBag.Header = "Редактирование раздела";
                page           = db.CMSPages.FirstOrDefault(x => x.ID == ID);

                if (page == null)
                {
                    RedirectToAction("Index");
                }
                page.LoadLangValues();
            }

            var parents = CMSPage.FullPageTable.Where(x => x.ID != ID).ToList();

            parents.Insert(0, new CMSPage()
            {
                ID = 0, PageName = "Корневой раздел сайта"
            });
            ViewBag.Parents = new SelectList(parents, "ID", "PageName", page.ParentID ?? 0);
            ViewBag.Types   = new SelectList(db.PageTypes.OrderBy(x => x.Ordernum).AsEnumerable(), "ID", "Description");
            return(View(page));
        }
Ejemplo n.º 2
0
        public PartialViewResult Edit(int?ID, int?ParentID, int?vtype)
        {
            CMSPage page = new CMSPage()
            {
                ParentID = 0, Visible = true, ViewMenu = false, Deleted = false, LastMod = DateTime.Now,
            };

            if (!ID.HasValue || ID == 0)
            {
                ViewBag.Header = "Создание нового раздела";

                var parent = CMSPage.FullPageTable.FirstOrDefault(x => x.ID == ParentID);
                if (parent != null)
                {
                    parent.RolesList = null;
                    page.RolesList   = parent.RolesList;
                }
                else
                {
                    var roles = new List <RoleInfo>();
                    roles.AddRange(db.Roles.ToList().Select(x => new RoleInfo()
                    {
                        RoleName = x.Description.IsNullOrEmpty() ? x.RoleName : x.Description,
                        RoleID   = x.RoleId,
                        Selected = true
                    }));
                    roles.Add(new RoleInfo()
                    {
                        RoleName = "Неавторизованные пользователи",
                        RoleID   = new Guid(),
                        Selected = true
                    });
                    page.RolesList = roles;
                }
            }
            else
            {
                ViewBag.Header = "Редактирование раздела";
                page           = db.CMSPages.FirstOrDefault(x => x.ID == ID);

                if (page == null)
                {
                    RedirectToAction("Index");
                }
                page.LoadLangValues();
            }
            if (!vtype.HasValue)
            {
                vtype = 2;
            }
            var parents = CMSPage.FullPageTable.Where(x => x.ID != ID).ToList();

            parents.Insert(0, new CMSPage()
            {
                ID = 0, PageName = "Корневой раздел сайта", LastMod = DateTime.Now,
            });
            ViewBag.Parents = new SelectList(parents, "ID", "PageName", page.ParentID ?? 0);
            ViewBag.Types   = new SelectList(db.PageTypes.Where(x => x.Enabled).OrderBy(x => x.Ordernum).AsEnumerable(), "ID", "Description");
            ViewBag.VType   = vtype;
            return(PartialView(page));
        }