コード例 #1
0
        public virtual ActionResult Save(
            [ModelBinder(typeof (ContentModelBinder)), Bind(Prefix = "NewPageModel")] IPage pageModel,
            dynamic currentPage)
        {
            var parent = currentPage as Page;

            if (!ModelState.IsValid)
            {
                NewPageViewModel viewModel;
                using (IDocumentSession session = this.documentStore.OpenSession())
                {
                    viewModel = new NewPageViewModel
                    {
                        RootModel = session.Advanced.GetStartPage(),
                        ParentModel = parent,
                        NewPageModel = pageModel,
                        SlugsInUse =
                            parent != null
                                ? JsonConvert.SerializeObject(
                                    session.Advanced.GetChildrenFor((IPage) currentPage)
                                        .Select(x => x.Metadata.Slug))
                                : null
                    };
                }

                return View("new", viewModel);
            }

            using (IDocumentSession session = this.documentStore.OpenSession())
            {
                session.Store(pageModel, pageModel.Metadata.IsPublished ? StoreAction.Publish : StoreAction.Save);

                if (parent != null)
                {
                    pageModel.Parent = (Page) currentPage;

                    IPage[] children = session.Advanced.GetChildrenFor((IPage) currentPage).ToArray();

                    int max = children.Length > 0 ? children.Max(x => x.Metadata.SortOrder) : 0;

                    pageModel.Metadata.SortOrder = max + 1;
                }

                session.SaveChanges();
            }
            return RedirectToAction("index", new {currentPage = parent ?? pageModel});
        }
コード例 #2
0
        /// <summary>
        ///     News the specified new page model.
        /// </summary>
        /// <param name="newModel">The new model.</param>
        /// <param name="currentPage">The current page.</param>
        /// <returns></returns>
        public ActionResult New(NewModel newModel, dynamic currentPage)
        {
            if (ModelState.IsValid)
            {
                var parent = currentPage as IPage;

                // create a new page from the selected page model
                var page = Activator.CreateInstance(Type.GetType(newModel.SelectedPageModel)) as IPage;

                using (IDocumentSession session = this.documentStore.OpenSession())
                {
                    var viewModel = new NewPageViewModel
                    {
                        RootModel = page,
                        ParentModel = parent,
                        NewPageModel = page,
                        SlugsInUse =
                            parent != null
                                ? JsonConvert.SerializeObject(
                                    session.Advanced.GetChildrenFor(parent).Select(x => x.Metadata.Slug))
                                : null
                    };

                    ViewBag.Class = "edit";
                    return View("new", viewModel);
                }
            }

            return PartialView("add", newModel);
        }
コード例 #3
0
        public virtual ActionResult Save([ModelBinder(typeof(ContentModelBinder)), Bind(Prefix = "NewPageModel")] IPage pageModel)
        {
            var parent = _currentPage as Page;

            if(!ModelState.IsValid) {
                var viewModel = new NewPageViewModel
                {
                    RootModel = _session.Query<IPage, AllPages>().SingleOrDefault(model => model.Parent == null),
                    ParentModel = parent,
                    NewPageModel = pageModel,
                    SlugsInUse = parent != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPage>(parent.Children).Select(x => x.Metadata.Slug)) : null
                };
                return View("new", viewModel);
            }

            _session.Store(pageModel);

            // Set the parent if it's not the start page
            if (parent != null)
            {
                pageModel.Parent = _currentPage;
                parent.Children.Add(pageModel.Id);

                var children = _session.Load<IPage>(parent.Children);
                var max = children.Max(x => x.Metadata.SortOrder);
                pageModel.Metadata.SortOrder = max + 1;
            }

            // Set changed date
            pageModel.Metadata.Changed = DateTime.Now;
            pageModel.Metadata.ChangedBy = HttpContext.User.Identity.Name;

            // Add page to repository and save changes
            _session.SaveChanges();

            return RedirectToAction("index", new { model = parent ?? pageModel });
        }
コード例 #4
0
        /// <summary>
        /// News the specified new page model.
        /// </summary>
        /// <param name="newModel">The new model.</param>
        /// <returns></returns>
        public ActionResult New(NewModel newModel)
        {
            if (ModelState.IsValid) {

                var parent = _currentPage as IPage;
                // create a new page from the selected page model
                var page = Activator.CreateInstance(Type.GetType(newModel.SelectedPageModel)) as dynamic;

                page.Metadata.Url = parent != null ? VirtualPathUtility.AppendTrailingSlash(parent.Metadata.Url) : String.Empty;
                page.Metadata.Published = DateTime.Now;

                var viewModel = new NewPageViewModel
                {
                    RootModel = _structureInfo != null ? _structureInfo.StartPage : null,
                    ParentModel = parent,
                    NewPageModel = page,
                    SlugsInUse = parent != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPage>(parent.Children).Select(x => x.Metadata.Slug)) : null
                };

                ViewBag.Class = "edit";
                return View("new", viewModel);

            }

            return PartialView("add", newModel);
        }
コード例 #5
0
ファイル: PagesController.cs プロジェクト: sriv/BrickPile
        public virtual ActionResult Save()
        {
            if (ModelState.IsValid) {
                var parent = _model as PageModel;
                // create a new page from the new model
                var page = Activator.CreateInstance(Type.GetType(Request.Form["AssemblyQualifiedName"])) as dynamic;

                if(!TryUpdateModel(page,"NewPageModel")) {
                    var viewModel = new NewPageViewModel
                    {
                        RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null),
                        ParentModel = parent,
                        NewPageModel = page,
                        SlugsInUse = parent != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPageModel>(parent.Children).Select(x => x.Metadata.Slug)) : null
                    };
                    return View("new", viewModel);
                }

                // Update all values
                UpdateModel(page, "NewPageModel");
                // Store the new page
                _session.Store(page);
                // Set the parent if it's not the start page
                if (parent != null) {
                    page.Parent = _model;
                    parent.Children.Add(page.Id);

                    var children = _session.Load<IPageModel>(parent.Children);
                    var max = children.Max(x => x.Metadata.SortOrder);
                    page.Metadata.SortOrder = max + 1;
                }
                // Set changed date
                page.Metadata.Changed = DateTime.Now;
                page.Metadata.ChangedBy = HttpContext.User.Identity.Name;

                // Add page to repository and save changes
                _session.SaveChanges();

                return RedirectToAction("index", new { model = parent ?? page });
            }

            return null;
        }
コード例 #6
0
        /// <summary>
        /// News the specified new page model.
        /// </summary>
        /// <param name="newModel">The new model.</param>
        /// <returns></returns>
        public ActionResult New(NewModel newModel)
        {
            if (ModelState.IsValid) {
                var parent = _model as IPageModel;
                // create a new page from the selected page model
                var page = Activator.CreateInstance(Type.GetType(newModel.SelectedPageModel)) as dynamic;
                page.Metadata.Url = parent != null ? VirtualPathUtility.AppendTrailingSlash(parent.Metadata.Url) : String.Empty;

                var viewModel = new NewPageViewModel
                                    {
                                        RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null),
                                        CurrentModel = parent,
                                        NewPageModel = page,
                                    };

                ViewBag.Class = "edit";
                return View("new", viewModel);
            }

            return PartialView("add", newModel);
        }