public ActionResult Edit(Guid id, FormCollection collection) { try { Sitecore.Data.Items.Item item = Context.Database.GetItem(new ID(id)); var sampleItem = StandardItemAdapter <Models.SampleItem> .CreateExtendedModelInstance(item, 1); var updateItem = new Models.SampleItem(); updateItem.Initialize(id); if (collection["Title"] != null) { updateItem.Title = collection["Title"]; } if (collection["Text"] != null) { updateItem.Text = collection["Text"]; } StandardItemAdapter <Models.SampleItem> .SaveModel(updateItem, item); return(RedirectToAction("Details", new { @id = id })); } catch { throw; } }
public new ActionResult Index(string scItemPath) { var contextId = new Data.ID(scItemPath); var contextItem = Sitecore.Context.Database.GetItem(contextId); if (contextItem == null) { return(HttpNotFound()); } SetPageContextItem(contextItem); var parentBlogItem = contextItem.Parent.Parent; var blogPostViewData = StandardItemAdapter <BlogPost> .CreateExtendedModelInstance(contextItem, 1); var blogViewData = StandardItemAdapter <Blog> .CreateModelInstance(parentBlogItem, 0); var viewModel = new BlogPostViewModel(blogPostViewData); viewModel.BlogViewModel = new BlogViewModel(blogViewData); ViewData.Model = viewModel; return(GetDefaultAction()); }
// GET: SampleItem/Sitecore/Details/5 public ActionResult Details(Guid id) { Sitecore.Data.Items.Item item = Context.Database.GetItem(new ID(id)); var sampleItem = StandardItemAdapter <Models.SampleItem> .CreateExtendedModelInstance(item, 1); return(Json(sampleItem, JsonRequestBehavior.AllowGet)); }
private void GetViewModel(Item contextItem) { var blogViewData = StandardItemAdapter <Blog> .CreateExtendedModelInstance(contextItem, 1); var blogViewModel = new BlogViewModel(blogViewData); ViewData.Model = blogViewModel; }
// GET: SampleItem/Sitecore public ActionResult Index() { var sampleItemTemplateId = Models.SampleItem.SampleItemTemplateId; Item item = Context.Database.GetItem(new ID(contentItemId)); Item[] contentChildren = item.Children.Where(c => c.TemplateID.Equals(new ID(new Guid(sampleItemTemplateId)))).ToArray(); var sampleItemList = StandardItemAdapter <Models.SampleItem> .GetEnumerator(contentChildren, 1); return(Json(sampleItemList, JsonRequestBehavior.AllowGet)); }
public PartialViewResult PageBanner(string scItemPath) { var contextId = new Data.ID(scItemPath); var contextItem = Sitecore.Context.Database.GetItem(contextId); var viewData = StandardItemAdapter <Models.StandardPage> .CreateExtendedModelInstance(contextItem, 0); ViewData.Model = new PageBannerViewModel(viewData); return(PartialView()); }
public ActionResult List(string scItemPath) { var contextId = new Data.ID(scItemPath); var contextItem = Sitecore.Context.Database.GetItem(contextId); IEnumerable <Blog> viewData = StandardItemAdapter <Blog> .GetEnumerator(contextItem.Children.ToArray(), 0); IEnumerable <BlogListItemViewModel> innerViewModel = viewData.Select(blog => new BlogListItemViewModel(blog)); ViewData.Model = new BlogListViewModel(innerViewModel); return(PartialView()); }
// GET: StandardBlog/Author public ActionResult Index(Guid scItemPath) { var contextId = new Data.ID(scItemPath); var contextItem = Sitecore.Context.Database.GetItem(contextId); if (contextItem == null) { return(HttpNotFound()); } SetPageContextItem(contextItem); Author viewData = StandardItemAdapter <Author> .CreateExtendedModelInstance(contextItem, 0); ViewData.Model = new AuthorViewModel(viewData); return(GetDefaultAction()); }
public ActionResult EditModel(Guid id, [System.Web.Http.FromBody] Models.SampleItem postModel) { Sitecore.Data.Items.Item item = Context.Database.GetItem(new ID(id)); var sampleItem = StandardItemAdapter <Models.SampleItem> .CreateExtendedModelInstance(item, 1); var updateItem = new Models.SampleItem(); updateItem.Initialize(id); if (postModel.Title != null) { updateItem.Title = postModel.Title; } if (postModel.Text != null) { updateItem.Text = postModel.Text; } StandardItemAdapter <Models.SampleItem> .SaveModel(updateItem, item); return(RedirectToAction("Details", new { @id = id })); }
private void GetBlogPostListViewModel() { BlogViewModel blogViewModel = (BlogViewModel)ViewData.Model; var blogFolders = blogViewModel.ViewData.Children.Cast <BlogPostFolder>(); var showFolders = blogFolders.Take(LoadBlogPostFolders).Select(folder => Sitecore.Context.Database.GetItem(new Data.ID(folder.Id))).ToArray(); var getFolders = showFolders.Select(folder => StandardItemAdapter <BlogPostFolder> .CreateExtendedModelInstance(folder, 1)); List <BlogPostListItemViewModel> blogPostList = new List <BlogPostListItemViewModel>(); foreach (BlogPostFolder folder in getFolders) { List <BlogPost> posts = folder.Children.Cast <BlogPost>().ToList(); foreach (BlogPost post in posts) { blogPostList.Add(new BlogPostListItemViewModel(post)); } } var viewModel = new BlogPostListViewModel(blogPostList); blogViewModel.BlogPostListViewModel = new BlogPostListViewModel(blogPostList); }
public void Initialize(Mvc.Presentation.Rendering rendering) { ViewData = StandardItemAdapter <Models.StandardPage> .CreateExtendedModelInstance(rendering.Item, 1); PageContext.Current.HtmlHelper.ViewData.Model = this; }