public void FieldWithSpacesReturningNullIssue() { /* * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper * project. When two interfaces have similar names are created as proxies * the method GetTypeConfiguration returns the wrong config. */ //Assign string path = "/sitecore/content/Tests/Misc/FieldWithSpace"; string expected = "Hello space"; string imageValue = "<image mediaid=\"{C2CE5623-1E36-4535-9A01-669E1541DDAF}\" mediapath=\"/Tests/Dayonta\" src=\"~/media/C2CE56231E3645359A01669E1541DDAF.ashx\" />"; var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field With Space"] = expected; item["Image Field"] = imageValue; } var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); //Act var instance = scContext.GetItem<FieldWithSpaceIssue>(path); //Assert Assert.AreEqual(expected, instance.FieldWithSpace); Assert.IsNotNull(instance.ImageSpace); }
public void InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName() { /* * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper * project. When two interfaces have similar names are created as proxies * the method GetTypeConfiguration returns the wrong config. */ //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); var instance = scContext.GetItem<IBasePage>("/sitecore"); //Act glassHtml.Editable(instance, x => x.Title); //This method should execute without error }
public void ItemPropertySave_SavesItemOnProperty_SetsField() { /* * Tests that we can save to an item property. */ //Assign var context = Context.Create(Utilities.CreateStandardResolver()); var db = Factory.GetDatabase("master"); var scContext = new SitecoreContext(db); string path = "/sitecore/content/Tests/Misc/ItemPropertySave"; var expected = "some expected value"; var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field1"] = string.Empty; } var instance = scContext.GetItem<ItemPropertySaveStub>(path); //Act instance.Field1 = expected; using (new SecurityDisabler()) { scContext.Save(instance); } //Assert Assert.AreEqual(expected, instance.Item["Field1"]); }
public void RenderImage_MatchesSitecoreOutput_Issue133() { //Assign string targetPath = "/sitecore/content/Tests/GlassHtml/RenderImage/Target"; var db = Sitecore.Configuration.Factory.GetDatabase("master"); var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var service = new SitecoreContext(db); var html = new GlassHtml(service); string fieldValue= "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />"; var item = db.GetItem(targetPath); var field = item.Fields["Image"]; using (new ItemEditing(item, true)) { field.Value = fieldValue; } var model = service.GetItem<StubClassWithImage>(targetPath); var scControl = new Sitecore.Web.UI.WebControls.Image(); scControl.Item = item; scControl.Field = "Image"; scControl.Parameters = "mw=200"; var doc = new XmlDocument(); doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); siteContext.SetDisplayMode(DisplayMode.Normal); Sitecore.Context.Site = siteContext; StringBuilder sb = new StringBuilder(); HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb)); //Act scControl.RenderControl(writer); var scResult = sb.ToString(); var result = html.RenderImage(model, x => x.Image, new {mw=200}); //Assert Assert.AreEqual(result,scResult); }
public void DropSave() { ISitecoreContext context = new SitecoreContext(); DemoItem current = context.GetCurrentItem<DemoItem>(); OtherItem other = context.GetItem<OtherItem>("/sitecore/content/home/someOtherItem"); current.Drop = other; context.Save(current); }
public void Editable_InEditMode_StringFieldWithEditReturned() { //Assign string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target"; var db = Sitecore.Configuration.Factory.GetDatabase("master"); var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var service = new SitecoreContext(db); var html = new GlassHtml(service); var model = service.GetItem<StubClass>(targetPath); var fieldValue = "test content field"; model.StringField = fieldValue ; using (new SecurityDisabler()) { service.Save(model); } var doc = new XmlDocument(); doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); siteContext.SetDisplayMode(DisplayMode.Edit); Sitecore.Context.Site = siteContext; //Act string result; using (new SecurityDisabler()) { result = html.Editable(model, x => x.StringField); } //Assert Assert.IsTrue(result.Contains(fieldValue)); //this is the webedit class Assert.IsTrue(result.Contains("scWebEditInput")); Console.WriteLine("result "+result); }
public void MultiTreeRead() { ISitecoreContext context = new SitecoreContext(); DemoItem current = context.GetCurrentItem<DemoItem>(); OtherItem forRemoval = current.Multi.First(); current.Multi.Remove(forRemoval); OtherItem toAdd = context.GetItem<OtherItem>("/sitecore/content/home/someOtherItem"); current.Multi.Add(toAdd); context.Save(current); }
public void RenderLink_LinkContainsAnchor_Issue155() { //Assign string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target"; var db = Sitecore.Configuration.Factory.GetDatabase("master"); var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var service = new SitecoreContext(db); var html = new GlassHtml(service); string fieldValue = "<link text='text' linktype='anchor' anchor='footer' title='' class='' />"; string expected = "<a href='#footer' >text</a>"; var item = db.GetItem(targetPath); var field = item.Fields["StringField"]; using (new ItemEditing(item, true)) { field.Value = fieldValue; } var model = service.GetItem<IStubLinkClass>(targetPath); var doc = new XmlDocument(); doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); siteContext.SetDisplayMode(DisplayMode.Normal); Sitecore.Context.Site = siteContext; StringBuilder sb = new StringBuilder(); //Act var result = html.RenderLink(model, x => x.Link); //Assert Assert.AreEqual(expected, result); }
public override ActionResult Index() { var model = GetDataSourceItem <Models.NewsList>(); Models.NewsList newsmodel = new Models.NewsList(); if (model.NewsRoot != Guid.Empty) { newsmodel = SitecoreContext.GetItem <Models.NewsList>(model.NewsRoot); newsmodel.NewsItems = model.NewsItems.OrderByDescending(x => x.Date).Take(3); newsmodel.Title = model.Title; } else { newsmodel.Title = "Ingen nyheder at vise"; } return(PartialView("/Views/NewsList.cshtml", newsmodel)); }
// GET: Media public ActionResult Carousel() { var item = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item; var context = new SitecoreContext(); var result = context.GetItem <CarouselViewModel>(item.Paths.Path); //var slideIds = Sitecore.Data.ID.ParseArray(item["Selected Items"]); //var viewModel = new CarouselViewModel //{ // CarouselSlides = // slideIds.Select(i => // new CarouselSlideViewModel // { // Item = item.Database.GetItem(i) // }).ToList() //}; return(View("Carousel", result)); }
public void FieldWithSpacesReturningNullIssue() { /* * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper * project. When two interfaces have similar names are created as proxies * the method GetTypeConfiguration returns the wrong config. */ //Assign string path = "/sitecore/content/Tests/Misc/FieldWithSpace"; string expected = "Hello space"; string imageValue = "<image mediaid=\"{C2CE5623-1E36-4535-9A01-669E1541DDAF}\" mediapath=\"/Tests/Dayonta\" src=\"~/media/C2CE56231E3645359A01669E1541DDAF.ashx\" />"; var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field With Space"] = expected; item["Image Field"] = imageValue; } var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); //Act var instance = scContext.GetItem <FieldWithSpaceIssue>(path); //Assert Assert.AreEqual(expected, instance.FieldWithSpace); Assert.IsNotNull(instance.ImageSpace); }
public string LocalImageFullUrl() { //Build the URL for the image to include the server name. This is required when adding the image in the header since this header // is also render on 3rd party site string retValue = ""; if (this.LocalImage != null) { var context = new SitecoreContext(); var imageItem = context.GetItem <Item>(this.LocalImage.MediaId); if (imageItem != null) { var mediaOptions = new MediaUrlOptions { AlwaysIncludeServerUrl = true }; retValue = MediaManager.GetMediaUrl((MediaItem)imageItem, mediaOptions); } } return(retValue); }
// GET: Banner public ActionResult Index() { //Template template = TemplateManager.GetTemplate(new Sitecore.Data.ID("{03FADF59-F22D-48C6-B13F-48A9B7281BC2}"), Sitecore.Context.Database); Database database = Sitecore.Context.Database; Item myItem = database.GetItem(new Sitecore.Data.ID("{42CDF7FF-6D07-4FC3-A609-D2FF4EF1181A}")); var fieldValue = myItem.Fields["Title"].Value; string desc = myItem.Fields["Desc"].Value; string Title = myItem.Fields["Title"].Value; string LinkText = myItem.Fields["LinkText"].Value; //template.GetField("LinkText").DefaultValue; // string desc = template.GetField("Desc").DefaultValue; //TemplateField[] allFields = template.GetFields(false); var model = _context.GetItem <RYWebsite.Models.Banner>(new Guid(_renderingContext.GetDataSource())); model.Desc = desc; model.Title = Title; model.LinkText = LinkText; return(View(model)); }
public void OrderOfIgnoreIssue2_ConfiguredShouldBeSet_TitleShouldBeIgnored() { //Assign string path = "/sitecore/content/Tests/Misc/FieldConfigOrder"; string expected = "Hello space"; var fluentConfig = new SitecoreFluentConfigurationLoader(); var typeConfig = fluentConfig.Add <FieldOrderOnIgnore>(); typeConfig.AutoMap(); typeConfig.Field(x => x.ConfiguredTitle).FieldName("Title"); typeConfig.Ignore(x => x.Title); var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(fluentConfig); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Title"] = expected; } var scContext = new SitecoreContext(db); //Act var instance = scContext.GetItem <FieldOrderOnIgnore>(path); //Assert Assert.AreEqual(expected, instance.ConfiguredTitle); Assert.IsNullOrEmpty(instance.Title); }
public void InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName() { /* * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper * project. When two interfaces have similar names are created as proxies * the method GetTypeConfiguration returns the wrong config. */ //Assign var templateId = ID.NewID; var targetId = ID.NewID; var fieldName = "Field"; using (Db database = new Db { new DbTemplate(templateId) { { fieldName, "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(IBase))); context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(IBasePage))); var db = database.Database; var scContext = new SitecoreContext(db); var glassHtml = GetGlassHtml(scContext); var instance = scContext.GetItem <IBasePage>("/sitecore"); //Act glassHtml.Editable(instance, x => x.Title); //This method should execute without error } }
public ActionResult NotificationAction() { Notification notification = new Notification(); var context = new SitecoreContext(); notification = context.GetItem <Notification>(RenderingContext.Current.Rendering.DataSource); HttpCookie myCookie = null; if (Request.Cookies["Notifications"] == null) { myCookie = new HttpCookie("Notifications"); if (notification.Notificationitems != null) { int count = notification.Notificationitems.ToList().Count - 1; myCookie.Values["count"] = count.ToString(); myCookie.Values[notification.Notificationitems[0].id.ToString()] = "read"; Response.Cookies.Add(myCookie); } } return(View(notification)); }
public override ActionResult Index() { var model = GetDataSourceItem <Models.NewsList>(); var newsmodel = new Models.NewsList(); newsmodel.Title = _dictionaryService.GetDictionaryValue("newsrootnotset"); if (model.NewsRoot != Guid.Empty) { newsmodel = SitecoreContext.GetItem <Models.NewsList>(model.NewsRoot); if (newsmodel != null) { newsmodel.Title = _dictionaryService.GetDictionaryValue("nonewstoshow"); if (newsmodel.NewsItems != null) { newsmodel.NewsItems = newsmodel.NewsItems.OrderByDescending(x => x.Date).Take(3); newsmodel.Title = model.Title; } } } newsmodel.ReadNewsLinkText = _dictionaryService.GetDictionaryValue("readnewslinktext"); return(PartialView("/Views/NewsList.cshtml", newsmodel)); }
public ActionResult AccountsBalance(AccountViewModel account) { AccountsBalanceHelper accountsBalanceHelper = new AccountsBalanceHelper(); try { if (!ModelState.IsValid || !accountsBalanceHelper.ValidateAccountData(account)) { throw new Exception(); } Session.Add("AccountDetails", account); //Session["PaymentProjNo"] = account.GroupID; //Session["ProjectName"] = account.GroupTitle; //Session["TotalDue"] = account.UserPayInfoList.Select(x => x.PaymentAmount).Sum(); //var accountData = accountsBalanceHelper.GetAccountInfoForProject(account.GroupID); //var accList = account.UserPayInfoList.Select<AccountBalanceInfo, AccountDetailsForACH>(x => GetAccountDetailsForACH(x, account.GroupID)).ToList(); //Session["AccountList"] = accList; //Session["accNumList"] = accList.Select(x => x.accountNumber).ToList(); //Session["PaymentPayments"] = accList.Select(x => x.paymentamount).ToList(); //Session["ArdaCollections"] = account.UserPayInfoList.Select(x => !x.IsARDAAmount && x.ARDAAmount > 0 ? "Y" : "").ToList(); var context = new SitecoreContext(); PaymentsConfiguration getContextItem = context.GetItem <PaymentsConfiguration>(PaymentsConfiguration.PaymentsConfigurationItem); var pathInfo = getContextItem?.PaymentsOptionPage?.Url; PaymentUtils.RedirectToPage(pathInfo); ModelState.Clear(); return(null); } catch (Exception ex) { ModelState.Clear(); return(AccountsBalance()); } }
public void InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName() { /* * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper * project. When two interfaces have similar names are created as proxies * the method GetTypeConfiguration returns the wrong config. */ //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration.Sc7")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); var instance = scContext.GetItem <Sc7SitecoreItem>("/sitecore"); //Act //This method should execute without error }
public static TGlassModel MapItem <TGlassModel>(Guid guid) where TGlassModel : class { SitecoreContext context = new SitecoreContext(); return(context.GetItem <TGlassModel>(guid)); }
// GET: Identity public ActionResult SiteIdentity() { var cportalPage = SitecoreContext.GetItem <LogoItem>(Templates.Site.Fields.Path); return(PartialOrEmpty(Constants.Views.SiteIdentify, cportalPage)); }
public static TGlassModel MapItem <TGlassModel>(string itemPath) where TGlassModel : class { SitecoreContext context = new SitecoreContext(); return(context.GetItem <TGlassModel>(itemPath)); }
public void OrderOfIgnoreIssue2_ConfiguredShouldBeSet_TitleShouldBeIgnored() { //Assign string path = "/sitecore/content/Tests/Misc/FieldConfigOrder"; string expected = "Hello space"; var fluentConfig = new SitecoreFluentConfigurationLoader(); var typeConfig = fluentConfig.Add<FieldOrderOnIgnore>(); typeConfig.AutoMap(); typeConfig.Field(x => x.ConfiguredTitle).FieldName("Title"); typeConfig.Ignore(x => x.Title); var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(fluentConfig); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Title"] = expected; } var scContext = new SitecoreContext(db); //Act var instance = scContext.GetItem<FieldOrderOnIgnore>(path); //Assert Assert.AreEqual(expected, instance.ConfiguredTitle); Assert.IsNullOrEmpty(instance.Title); }
public IHttpActionResult VoteStar(StarVote objvote) { var context = new SitecoreContext(); var masterSV = new SitecoreService("master"); if (objvote.idParent == null) { return(Ok(false)); } else { var idCurrent = context.GetItem <Item>(objvote.idParent.ToString()); List <Item> list = idCurrent.GetChildren().ToList(); Item idParent = null; foreach (var item in list) { if (Guid.Parse(item.TemplateID.ToString()) == Guid.Parse(IStarVoteConstants.TemplateIdString.ToString())) { if (item.Children.Count != 0) { foreach (var items in item.GetChildren().ToList()) { Item itemCheck = Sitecore.Context.Database.Items.GetItem(items.ID); if (itemCheck.Fields["Email"].ToString() == objvote.Email.ToString()) { idParent = null; return(Ok(false)); } else { idParent = context.GetItem <Item>(item.ID.ToString()); } } } else { idParent = context.GetItem <Item>(item.ID.ToString()); } } } if (idParent == null) { string nameList = "Vote-list"; var tempParentVote = context.GetItem <Item>(objvote.idParent); using (new SecurityDisabler()) { var templateId = new TemplateItem(tempParentVote); var itemChild = idParent.Add(nameList, templateId); idParent = context.GetItem <Item>(itemChild.ID.ToString()); } } else { string nameVote = "user" + DateTime.Now.ToString("dd-MM-yy-hh-ss"); var templateVote = context.GetItem <Item>(IStarVoteConstants.TemplateIdString); using (new SecurityDisabler()) { var templateId = new TemplateItem(templateVote); var itemChild = idParent.Add(nameVote, templateId); itemChild.Editing.BeginEdit(); itemChild.Fields["Email"].Value = objvote.Email; itemChild.Fields["number star"].Value = objvote.Number_Star.ToString(); itemChild.Fields["time vote"].Value = Sitecore.DateUtil.ToIsoDate(DateTime.Now); itemChild.Editing.EndEdit(); numberVote(objvote.idParent.ToString()); } } } return(Ok(true)); }
public static IEnumerable<AgendaModel> GetPastAgendaItemsForPerson(PersonModel model) { ISitecoreContext context = new SitecoreContext(); var archiveItem = context.GetItem<AgendaOverviewModel>(new Guid("{BA01B6B5-BF68-46DE-900F-BCE1227E72B0}")); return archiveItem.ChildrenAsAgendaItems.Where(agendaModel => agendaModel.Speakers.Any(personModel => personModel.Id.ToString() == model.Id.ToString())).ToList(); }
// GET: Search public ActionResult Search() { var model = _context.GetItem <SearchModel>(new Guid(_renderingcontext.GetDataSource())); return(View("/Views/Header/Search.cshtml", model)); }
// GET: PrimaryNavigation public ActionResult Index() { var model = _context.GetItem <PrimaryNav>(new Guid(_renderingContext.GetDataSource())); return(View("/Views/Header/PrimaryNav.cshtml", model)); }
public void Editable_ComplexLambdaInEditMode_StringFieldWithEditReturned() { //Assign string targetPath = "/sitecore/content/target"; var templateId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { new DbField("StringField") { Type = "text" } }, new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId) { {"StringField", ""} } }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass))); var service = new SitecoreContext(database.Database); var html = GetGlassHtml(service); var model = service.GetItem<StubClass>(targetPath); var fieldValue = "test content field"; model.StringField = fieldValue; using (new SecurityDisabler()) { service.Save(model); } var doc = new XmlDocument(); doc.LoadXml( "<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); using (new EnableWebEditMode()) { using (new SiteContextSwitcher(siteContext)) { //Act string result; using (new SecurityDisabler()) { result = html.Editable(model, x => x.EnumerableSubStub.First().StringField); } //Assert Assert.IsTrue(result.Contains(fieldValue)); Console.WriteLine("result " + result); //this is the webedit class Assert.IsTrue(result.Contains("scWebEditInput")); } } } }
public void RenderLink_LinkContainsAnchor_Issue155() { //Assign string path = "/sitecore/content/target"; using (Db database = new Db { new Sitecore.FakeDb.DbItem("Target") { {"StringField","" } } }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass))); var service = new SitecoreContext(database.Database); var html = GetGlassHtml(service); string fieldValue = "<link text='text' linktype='anchor' anchor='footer' title='' class='' />"; string expected = "<a href='#footer' >text</a>"; var item = database.GetItem(path); var field = item.Fields["StringField"]; using (new ItemEditing(item, true)) { field.Value = fieldValue; } var model = service.GetItem<IStubLinkClass>(path); var doc = new XmlDocument(); doc.LoadXml( "<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); siteContext.SetDisplayMode(DisplayMode.Normal); Sitecore.Context.Site = siteContext; StringBuilder sb = new StringBuilder(); //Act var result = html.RenderLink(model, x => x.Link); //Assert AssertHtml.AreHtmlElementsEqual(expected, result,"a"); } }
public ViewResult FooterLinksDisclosure() { return(View(_sitecoreContext.GetItem <MenuLink>(Consts.Ids.FooterLinksDisclosure))); }
//Data organized within constructor public GenericTileRowViewModel(GenericTileRowParametersRenderingModel rowParamsModel, SitecoreContext context = null) { context = context ?? new SitecoreContext(); GuidId = "row-" + Guid.NewGuid().ToString().Replace("-", ""); FullWidthContainer = rowParamsModel.FullWidthContainer; PaddingClass = !rowParamsModel.PaddingBetweenCells ? "nopadding" : string.Empty; RowDefinition = context.GetItem <IGeneric_Row_Definition>(rowParamsModel.RowType); //Pull the tile objects into a collection Tiles = new List <object>(); TileCshtmlViews = new List <string>(); foreach (var tGuid in rowParamsModel.Tiles) { var item = context.GetItem <Item>(tGuid); switch (item.TemplateID.Guid.ToString()) { case IGeneric_Rich_Text_TileConstants.TemplateIdString: Tiles.Add(context.CreateType <IGeneric_Rich_Text_Tile>(item)); TileCshtmlViews.Add(RichTextView); break; case IGeneric_Media_TileConstants.TemplateIdString: Tiles.Add(context.CreateType <IGeneric_Media_Tile>(item)); TileCshtmlViews.Add(MediaTileView); break; default: break; } } //Other rendering params ContainerClass = FullWidthContainer ? "container-fluid" : "container"; Margins = FullWidthContainer ? "" : "no-margin"; Columns = RowDefinition.Columns.ToList(); CssClasses = string.Join(" ", rowParamsModel.CssClasses.Select(g => context.GetItem <ICssClass>(g)).Select(c => c.Class)); CssClasses += " " + string.Join(" ", RowDefinition.CssClasses.Select(c => c.Class)); InLineCss = rowParamsModel.InLineCssStyling; BreakpointOverrides = rowParamsModel.Breakpoint_Overrides?.Select(gid => context.GetItem <IGeneric_Row_Flex_Breakpoint>(gid)); DesktopBgImage = GetAvailableImage(new List <Image>() { rowParamsModel.DesktopImage, rowParamsModel.TabletImage, rowParamsModel.MobileImage }); TabletBgImage = GetAvailableImage(new List <Image>() { rowParamsModel.TabletImage, rowParamsModel.DesktopImage, rowParamsModel.MobileImage }); MobileBgImage = GetAvailableImage(new List <Image>() { rowParamsModel.MobileImage, rowParamsModel.TabletImage, rowParamsModel.DesktopImage }); if (HasBackgroundImage) { ForceHeightToMatchBgImage = rowParamsModel.ForceHeightToMatchBgImageFieldName; DesktopBgImageHeight = (rowParamsModel.DesktopImage?.Height.ToString() ?? string.Empty) + "px"; TabletBgImageHeight = (rowParamsModel.TabletImage?.Height.ToString() ?? string.Empty) + "px"; MobileBgImageHeight = (rowParamsModel.MobileImage?.Height.ToString() ?? string.Empty) + "px"; } FlexPoints = rowParamsModel.OverrideFlexBreakpoints ? BreakpointOverrides != null ? string.Join(" ", BreakpointOverrides.Select(f => f.BreakpointCssClassName)) : string.Empty : string.Join(" ", RowDefinition.FlexBreakpoints.Select(f => f.BreakpointCssClassName)); }
// GET: LeftContainer public override ActionResult Index() { var model = SitecoreContext.GetItem <LeftContainerModel>(Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.DataSource); return(View("~/Views/Common/LeftContainer.cshtml", model)); }
// GET: Footer public override ActionResult Index() { var model = SitecoreContext.GetItem <FooterModel>(GlobalProperties.FooterItemPath); return(View("~/Views/Common/Footer.cshtml", model)); }
public void RenderImage_MatchesSitecoreOutput_Issue133_Test3() { //Assign string targetPath = "/sitecore/content/target"; var mediaID = new ID("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}"); var templateId = ID.NewID; using (Db database = new Db { new DbTemplate("MediaTemplate", templateId) { new DbField("Image") { Type = "image" } }, new Sitecore.FakeDb.DbItem("Target", new ID(), templateId) { {"Image", ""} }, new Sitecore.FakeDb.DbItem("media", mediaID) { } }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass))); var service = new SitecoreContext(database.Database); var html = GetGlassHtml(service); Sitecore.Resources.Media.MediaProvider mediaProvider = NSubstitute.Substitute.For<Sitecore.Resources.Media.MediaProvider>(); mediaProvider .GetMediaUrl(Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == mediaID)) .Returns("/myimage"); using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider)) { string fieldValue = "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />"; var item = database.GetItem(targetPath); var field = item.Fields["Image"]; using (new ItemEditing(item, true)) { field.Value = fieldValue; } var model = service.GetItem<StubClassWithImage>(targetPath); var scControl = new Sitecore.Web.UI.WebControls.Image(); scControl.Item = item; scControl.Field = "Image"; scControl.Parameters = "width=200&as=true"; var doc = new XmlDocument(); doc.LoadXml( "<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); siteContext.SetDisplayMode(DisplayMode.Normal); Sitecore.Context.Site = siteContext; StringBuilder sb = new StringBuilder(); HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb)); //Act scControl.RenderControl(writer); var scResult = sb.ToString(); var result = html.RenderImage(model, x => x.Image, new { width = 200 }); //Assert Assert.AreEqual(result, scResult); } } }
public void FieldWithSpacesAutoMap() { //Assign var templateId = ID.NewID; var targetId = ID.NewID; var fieldName1 = "Field With Space"; var fieldName2 = "Field With Space 1"; var fieldName3 = "Image Space"; using (Db database = new Db { new DbTemplate(templateId) { { fieldName1, "" }, { fieldName2, "" }, { fieldName3, "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { string path = "/sitecore/content/Target"; string expected = "Hello space"; string expectedSpace1 = "Hello space"; string imageValue = "<image mediaid=\"{C2CE5623-1E36-4535-9A01-669E1541DDAF}\" mediapath=\"/Tests/Dayonta\" src=\"~/media/C2CE56231E3645359A01669E1541DDAF.ashx\" />"; var resolver = Utilities.CreateStandardResolver(); resolver.DataMapperResolverFactory.Add(() => new AbstractDataMapperFieldsWithSpace()); var context = Context.Create(resolver); context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(FieldWithSpaceAutoMap))); ; var db = Factory.GetDatabase("master"); var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field With Space"] = expected; item["Field With Space 1"] = expectedSpace1; item["Image Space"] = imageValue; } var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); //Act var instance = scContext.GetItem <FieldWithSpaceAutoMap>(path); //Assert Assert.AreEqual(expected, instance.FieldWithSpace); Assert.IsNotNull(instance.ImageSpace); SitecoreFieldConfiguration imageFieldTypeConfig = scContext.GlassContext.TypeConfigurations[typeof(FieldWithSpaceAutoMap)].Properties.First( x => x.PropertyInfo.Name == "ImageSpace") as SitecoreFieldConfiguration; Assert.AreEqual("Image Space", imageFieldTypeConfig.FieldName); SitecoreFieldConfiguration stringFieldTypeConfig = scContext.GlassContext.TypeConfigurations[typeof(FieldWithSpaceAutoMap)].Properties.First( x => x.PropertyInfo.Name == "FieldWithSpace") as SitecoreFieldConfiguration; Assert.AreEqual("Field With Space", stringFieldTypeConfig.FieldName); SitecoreFieldConfiguration stringNumberFieldTypeConfig = scContext.GlassContext.TypeConfigurations[typeof(FieldWithSpaceAutoMap)].Properties.First( x => x.PropertyInfo.Name == "FieldWithSpace1") as SitecoreFieldConfiguration; Assert.AreEqual("Field With Space 1", stringNumberFieldTypeConfig.FieldName); } }
public ActionResult PrimaryMenu() { var homeItem = SitecoreContext.GetItem <HomeItem>("08D1C4DA-CEB5-4B91-99D2-7A35B58CFC17"); return(View(homeItem)); }
public ActionResult Print() { const int PAGE_WIDTH = 612; const int PAGE_HEIGHT = 792; const int INCH = 72; const int MARGIN = INCH / 2; const int FOOTER_HEIGHT = 30; const int COL_WIDTH = 100; const int TITLE_FONT_SIZE = 24; const int SUBTITLE_FONT_SIZE = 18; const int CONTENT_FONT_SIZE = 14; const int FOOTER_FONT_SIZE = 10; const int LINE_BREAK_FONT_SIZE = 12; const string LINE_BREAK = "<br />"; Doc theDoc = new Doc(); int theID, contentStartPage, contentEndPage; string content; //get sections Item home = SitecoreContext.GetHomeItem <Item>(); ChildList sections = home.GetChildren(); foreach (Item section in sections) { ChildList items = section.GetChildren(); //create a new page and set our page pointer to the new page theDoc.Page = theDoc.AddPage(); //get item as IContent ISection sectionItem = SitecoreContext.GetItem <ISection>(section.ID.Guid); //reset text position theDoc.TextStyle.HPos = 0; theDoc.TextStyle.VPos = 0; //set container to full page (no footer on section page) theDoc.Rect.Position(MARGIN, MARGIN); theDoc.Rect.Width = PAGE_WIDTH - MARGIN - MARGIN; theDoc.Rect.Height = PAGE_HEIGHT - MARGIN - MARGIN; //title theDoc.FontSize = TITLE_FONT_SIZE; theDoc.AddHtml("<h1>" + sectionItem.Title + "</h1>"); theDoc.FontSize = LINE_BREAK_FONT_SIZE; theDoc.AddHtml(LINE_BREAK); //intro if (!sectionItem.Intro.IsEmptyOrNull()) { theDoc.FontSize = CONTENT_FONT_SIZE; theDoc.AddHtml("<p>" + sectionItem.Intro + "</p>"); theDoc.FontSize = LINE_BREAK_FONT_SIZE; theDoc.AddHtml(LINE_BREAK); } //subtitle theDoc.FontSize = SUBTITLE_FONT_SIZE; theDoc.AddHtml("<p>In this section:</p>"); theDoc.FontSize = LINE_BREAK_FONT_SIZE; theDoc.AddHtml(LINE_BREAK); //children //TODO: Print ul in 3 or 4 columns content = "<ul>"; foreach (Item itm in items) { content += "<li>" + itm.DisplayName + "</li>"; } content += "</ul>"; theDoc.FontSize = CONTENT_FONT_SIZE; theID = theDoc.AddHtml(content); if (theDoc.Chainable(theID)) { while (theDoc.Chainable(theID)) { theDoc.Page = theDoc.AddPage(); theID = theDoc.AddHtml("", theID); } } //section pages foreach (Item itm in items) { if (itm.TemplateID != Constants.Templates.Page) { //create a new page and set our page pointer to the new page theDoc.Page = theDoc.AddPage(); //track which page we are starting on contentStartPage = theDoc.PageNumber; //get item dynamic contentItem; if (itm.TemplateID == Constants.Templates.Promotion) { contentItem = SitecoreContext.GetItem <IPromotion>(itm.ID.Guid); } else { contentItem = SitecoreContext.GetItem <IContent>(itm.ID.Guid); } contentItem.Version = itm.Version.Number; contentItem.Updated = itm.Statistics.Updated; contentItem.Parent = itm.Parent; //reset text position theDoc.TextStyle.HPos = 0; theDoc.TextStyle.VPos = 0; //set container theDoc.Rect.Position(MARGIN, MARGIN + FOOTER_HEIGHT); theDoc.Rect.Width = PAGE_WIDTH - MARGIN - MARGIN; theDoc.Rect.Height = PAGE_HEIGHT - MARGIN - MARGIN - FOOTER_HEIGHT; //title theDoc.FontSize = TITLE_FONT_SIZE; theDoc.AddHtml("<h1>" + contentItem.Title + "</h1>"); theDoc.FontSize = LINE_BREAK_FONT_SIZE; theDoc.AddHtml(LINE_BREAK); //content content = "<p>" + contentItem.Content + "</p>"; if (!String.IsNullOrEmpty(contentItem.Notes)) { content += "<p>Notes:<br />" + contentItem.Notes + "</p>"; } if (!String.IsNullOrEmpty(contentItem.InstructorNotes)) { content += "<p>Instructor Notes:<br />" + contentItem.Notes + "</p>"; } theDoc.FontSize = CONTENT_FONT_SIZE; theID = theDoc.AddHtml(content); if (theDoc.Chainable(theID)) { while (theDoc.Chainable(theID)) { theDoc.Page = theDoc.AddPage(); theID = theDoc.AddHtml("", theID); } } //track which page we are ending on contentEndPage = theDoc.PageCount; //add tags to last page if (itm.TemplateID == Constants.Templates.Content && contentItem.Tags != null && contentItem.Tags.Count > 0) { List <string> tags = new List <string>(); foreach (ITag tag in contentItem.Tags) { tags.Add(tag.Name); } theDoc.Rect.Position(MARGIN, MARGIN + FOOTER_HEIGHT); theDoc.Rect.Width = PAGE_WIDTH - MARGIN - MARGIN; theDoc.Rect.Height = FOOTER_HEIGHT; theDoc.TextStyle.HPos = 0; theDoc.TextStyle.VPos = 0; theDoc.FontSize = FOOTER_FONT_SIZE; theDoc.PageNumber = contentEndPage; theDoc.AddHtml("<p>Tags: " + string.Join(", ", tags.ToArray()) + "</p>"); } //add footer to all pages for this item theDoc.Rect.Position(MARGIN, MARGIN); theDoc.Rect.Width = PAGE_WIDTH - MARGIN - MARGIN; theDoc.Rect.Height = FOOTER_HEIGHT; theDoc.TextStyle.HPos = 0.5; theDoc.TextStyle.VPos = 0.5; theDoc.FontSize = FOOTER_FONT_SIZE; for (int i = contentStartPage; i <= contentEndPage; i++) { theDoc.PageNumber = i; theDoc.AddHtml(contentItem.Title + LINE_BREAK + "Section: " + contentItem.Parent.DisplayName + " - Version " + contentItem.Version + " - Updated " + contentItem.Updated.ToString("yyyy-MM-dd")); } } } } //TODO: Print Index Pages //create save path string tempPathRel = Sitecore.Configuration.Settings.TempFolderPath; string tempPathAbs = Sitecore.IO.FileUtil.MapPath(tempPathRel); string fileName = "usacjj." + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"; ViewBag.Path = tempPathRel + "/" + fileName; theDoc.Save(tempPathAbs + "\\" + fileName); theDoc.Clear(); return(View("~/Views/UsaCjj/Print.cshtml")); }
public DictionaryService() { _dictionary = SitecoreContext.GetItem <Models.Dictionary>(Guid.Parse("{BDB1D35B-9BD5-4069-9887-192454328A48}")); }
// GET: Logo public ActionResult Logo() { var model = _context.GetItem <Logo>(new Guid(_renderingContext.GetDataSource())); return(View("/Views/Header/Logo.cshtml", model)); }
protected JsonResult Json <TAgent, TViewModel, TRequestData>(Guid itemId, TRequestData agentParameters) where TAgent : Agent <TViewModel> where TViewModel : BaseViewModel, new() { var agentContext = new AgentContext(IgnitionControllerContext, SitecoreContext, new NullPage(), SitecoreContext.GetItem <IModelBase>(itemId)) { AgentParameters = agentParameters, }; var agent = AgentFactory.CreateAgent <TAgent, TViewModel>(agentContext); agent.PopulateModel(); return(Json(agent.ViewModel)); }
// GET: Dine public override ActionResult Index() { var model = SitecoreContext.GetItem <Dine>(Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.DataSource); return(View("~/Views/Pages/Dine.cshtml", model)); }
public static MediaFolderModel GetTypedMediaFolderModel(Guid mediaFolderGuid) { ISitecoreContext context = new SitecoreContext(); return(context.GetItem <MediaFolderModel>(mediaFolderGuid)); }
public ActionResult ArticleBox(Guid id) { var item = SitecoreContext.GetItem <IBlogArticle>(id); return(View("~/Views/Feature/Blog/_BoxBlog.cshtml", item)); }
public static MediaFolderModel GetTypedMediaFolderModel(Guid mediaFolderGuid) { ISitecoreContext context = new SitecoreContext(); return context.GetItem<MediaFolderModel>(mediaFolderGuid); }