BrickPile.UI.Areas.UI.Controllers.PagesController.New C# (CSharp) Method

New() public method

News the specified new page model.
public New ( BrickPile.UI.Areas.UI.Models.NewModel newModel, dynamic currentPage ) : System.Web.Mvc.ActionResult
newModel BrickPile.UI.Areas.UI.Models.NewModel The new model.
currentPage dynamic The current page.
return System.Web.Mvc.ActionResult
        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);
        }