예제 #1
0
        public ActionResult AddOrEdit(PageViewModel model)
        {
            var item = new Page();

            item = Mapper.Map(model, item);

            var result = Db.SaveOrUpdate(item);

            return RedirectToAction("List");
        }
예제 #2
0
        public ActionResult AddOrEdit(int? id)
        {
            var model = new PageViewModel();
            if (id.HasValue)
            {
                var item = Db.Get<Page>(id.Value);
                model = Mapper.Map(item, model);
            }

            return View(model);
        }
예제 #3
0
        public ActionResult Preview(int id)
        {
            var model = new PageViewModel();

            var item = Db.Get<Page>(id);
            if (item == null)
            {
                return View("ServerError", (object)"Страница не найдена");
            }
            model = Mapper.Map(item, model);

            return View(model);
        }
예제 #4
0
        public ActionResult AddOrEdit(int? id)
        {
            var model = new PageViewModel();
            if (id.HasValue)
            {
                var item = Db.Get<Page>(id.Value);
                model = Mapper.Map(item, model);

                //TODO дублирует код из FolderController
                var menuItems = MenuItemService.Select();
                model.MenuItems = Mapper.Map<ICollection<SelectListItem>>(menuItems);

                var byUrl = MenuItemService.ByUrl(model.IndexUrl);
                if (byUrl != null)
                {
                    var selected = model.MenuItems.FirstOrDefault(m => m.Value == byUrl.Id.ToString());
                    selected.Selected = true;
                }
            }

            return View(model);
        }