/// <summary> /// Responsible for providing the Edit view with data from the current page /// </summary> /// <returns></returns> public ActionResult Edit(IPage currentPage) { using (IDocumentSession session = this.documentStore.OpenSession()) { var viewModel = new EditViewModel { RootModel = session.Advanced.GetStartPage(), CurrentModel = session.Advanced.GetDraftFor<IPage>(currentPage) ?? currentPage, ParentModel = session.Advanced.GetParentFor<IPage>(currentPage), IlligalSlugs = currentPage.Parent != null ? JsonConvert.SerializeObject( session.Advanced.GetChildrenFor(currentPage) .Select(x => x.Metadata.Slug)) : null }; ViewBag.Class = "edit"; return View(viewModel); } }
public virtual ActionResult Update(dynamic currentPage, FormCollection collection) { using (IDocumentSession session = this.documentStore.OpenSession()) { if (!TryUpdateModel(currentPage, "CurrentModel", collection)) { var viewModel = new EditViewModel { RootModel = session.Advanced.GetStartPage(), CurrentModel = currentPage, ParentModel = session.Advanced.GetParentFor<IPage>((IPage) currentPage), }; return View("edit", viewModel); } session.Store((IPage) currentPage, currentPage.Metadata.IsPublished ? StoreAction.Publish : StoreAction.Save); session.SaveChanges(); if (currentPage.Parent != null) { currentPage = session.Advanced.GetParentFor<IPage>((IPage) currentPage); } return RedirectToAction("index", new {currentPage}); } }
public virtual ActionResult Update(FormCollection collection) { if (!TryUpdateModel(_currentPage, "CurrentModel", collection)) { var viewModel = new EditViewModel { RootModel = _structureInfo.StartPage, CurrentModel = _structureInfo.CurrentPage, ParentModel = _structureInfo.ParentPage, }; return View("edit", viewModel); } _currentPage.Metadata.Changed = DateTime.Now; _currentPage.Metadata.ChangedBy = HttpContext.User.Identity.Name; _session.SaveChanges(); var page = _currentPage as IPage; if (page.Parent != null) { _currentPage = _structureInfo.ParentPage; } return RedirectToAction("index", new { model = _currentPage }); }
/// <summary> /// Responsible for providing the Edit view with data from the current page /// </summary> /// <returns></returns> public ActionResult Edit() { var viewModel = new EditViewModel { RootModel = _structureInfo.StartPage, CurrentModel = _structureInfo.CurrentPage, ParentModel = _structureInfo.ParentPage, IlligalSlugs = _structureInfo.ParentPage != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPage>(_structureInfo.ParentPage.Children).Select(x => x.Metadata.Slug)) : null }; ViewBag.Class = "edit"; return View(viewModel); }
/// <summary> /// Responsible for providing the Edit view with data from the current page /// </summary> /// <returns></returns> public ActionResult Edit() { IPageModel parent = _model.Parent != null ? _session.Load<IPageModel>(_model.Parent.Id) : null; var viewModel = new EditViewModel { RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null), CurrentModel = _model, ParentModel = parent, IlligalSlugs = parent != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPageModel>(parent.Children).Select(x => x .Metadata.Slug)) : null }; if (Request.IsAjaxRequest()) { return PartialView("Edit", viewModel); } ViewBag.Class = "edit"; return View(viewModel); }
public virtual ActionResult Update() { if (!TryUpdateModel(_model, "CurrentModel")) { var parentId = _model.Parent != null ? (string)_model.Parent.Id : null; var viewModel = new EditViewModel { RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null), CurrentModel = _model, ParentModel = parentId != null ? _session.Load<IPageModel>(parentId) : null, }; return View("edit", viewModel); } UpdateModel(_model); _model.Metadata.Changed = DateTime.Now; _model.Metadata.ChangedBy = HttpContext.User.Identity.Name; _session.SaveChanges(); var page = _model as IPageModel; if (page.Parent != null) { _model = _session.Load<IPageModel>(page.Parent.Id); } return RedirectToAction("index", new { model = _model }); }
/// <summary> /// Responsible for providing the Edit view with data from the current page /// </summary> /// <returns></returns> public ActionResult Edit() { var parentId = _model.Parent != null ? (string) _model.Parent.Id : null; var viewModel = new EditViewModel { RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null), CurrentModel = _model, ParentModel = parentId != null ? _session.Load<IPageModel>(parentId) : null, }; ViewBag.Class = "edit"; return View(viewModel); }