public virtual WishListLinesRenderingModel GetWishListLinesModel() { WishListLinesRenderingModel model = _modelProvider.GetModel <WishListLinesRenderingModel>(); Init(model); model.Initialize(); return(model); }
public JsonResult GetWishList() { BaseJsonResult baseJsonResult; try { baseJsonResult = _wishListLinesRepository.GetWishList(StorefrontContext, _visitorContext); } catch (Exception ex) { baseJsonResult = _modelProvider.GetModel <BaseJsonResult>(); baseJsonResult.SetErrors(nameof(AddWishListLine), ex); } return(Json(baseJsonResult)); }
public ActionResult RemoveProductFromCompareList(string removeFromCompareProductId) { BaseJsonResult baseJsonResult; try { baseJsonResult = _productCompareRepository.RemoveProductFromCompareCollection(_visitorContext, removeFromCompareProductId); } catch (Exception ex) { baseJsonResult = _modelProvider.GetModel <RemoveFromProductCompareModel>(); baseJsonResult.SetErrors(nameof(RemoveProductFromCompareList), ex); } return(Json(baseJsonResult)); }
public JsonResult AddProductToCompareList(string addToCompareCatalogName, string addToCompareProductId, string addToCompareVarientId) { BaseJsonResult baseJsonResult; try { baseJsonResult = _productCompareRepository.AddProductToCompareCollection(StorefrontContext, _visitorContext, addToCompareCatalogName, addToCompareProductId, addToCompareVarientId); } catch (Exception ex) { baseJsonResult = _modelProvider.GetModel <BaseJsonResult>(); baseJsonResult.SetErrors(nameof(AddProductToCompareList), ex); } return(Json(baseJsonResult)); }
protected override void DoRun(IShellContext context) { object model = null; IModelProvider provider = null; if (Model is string) { model = context.Evaluate((string)Model); if (model is IModelProvider) { provider = (IModelProvider)model; model = provider.GetModel(context); } } else if (Model is IModelProvider) { provider = (IModelProvider)Model; model = provider.GetModel(context); } else { model = Model; } _log.InfoFormat("DBSH-00074 Apply template {0}=>{1}", TemplateFile ?? "(inline template)", File); string templateData = LoadTemplate(context); try { string fn = context.ResolveFile(context.Replace(File), ResolveFileMode.Output); context.OutputMessage("Generating file " + fn); using (var sw = new StreamWriter(fn)) { RazorScripting.ParseRazor(templateData, sw.Write, model, provider != null ? provider.InitializeTemplate : (Action <IRazorTemplate, IShellContext>)null, context); } } catch (RazorEngine.Templating.TemplateCompilationException err) { _log.ErrorFormat("DBSH-00075 Error compiling template {0}", TemplateFile); foreach (var error in err.Errors) { _log.Error(error.ToString()); } throw; } }
public T BuildModel <T>() where T : IModel { Type t = typeof(T); IModelProvider modelProvider = GetModelProvider(t); return((T)modelProvider.GetModel()); }
public virtual AddViewCompareButtonModel GetAddViewCompareButtonModel(IStorefrontContext storefrontContext, IVisitorContext visitorContext) { var model = _modelProvider.GetModel <AddViewCompareButtonModel>(); Init(model); Rendering.DataSourceItem.Fields.ReadAll(); model.ViewCompareButtonText = Rendering.DataSourceItem["View Compare Text"]; model.AddToCompareButtonText = Rendering.DataSourceItem["Add to Compare Text"]; if (Sitecore.Context.PageMode.IsExperienceEditor) { model.IsProductInCompareList = false; model.IsEdit = true; model.IsValid = true; } else { var currentCatalogItem = _siteContext.CurrentCatalogItem; if (currentCatalogItem != null && _siteContext.IsProduct) { model.Initialize(currentCatalogItem); } model.CatalogName = StorefrontContext.CurrentStorefront.Catalog; var productCompare = _compareManager.GetCurrentProductCompare(visitorContext, storefrontContext); var productIsInCompare = productCompare?.Result != null && productCompare.Result.Products.Any(x => x.FriendlyId == currentCatalogItem?.Name); model.IsProductInCompareList = productIsInCompare; LinkField linkField = Rendering.DataSourceItem.Fields["Compare Page"]; if (linkField != null && linkField.IsInternal) { model.IsValid = true; model.ComparePageLink = LinkManager.GetItemUrl(linkField.TargetItem); } else { model.IsValid = false; Log.Error("Unable to render add/view compare link, Compare Page field not populated in datasource.", this); } } return(model); }
public IModel BuildModel(Type modelType) { if (!typeof(IModel).IsAssignableFrom(modelType)) { throw new ArgumentException("modelType doesn't implement IModel"); } IModelProvider modelProvider = GetModelProvider(modelType); return(modelProvider.GetModel()); }
private string ExecuteView(ViewLocationResult viewLocationResult, dynamic model) { //Preprocess the location result and inject the global helper TextReader processedContentStream = InjectHelpersToView(viewLocationResult.Contents); var cache = System.Runtime.Caching.MemoryCache.Default; ViewBase view = (ViewBase)cache.Get(viewLocationResult.Location); if (view == null) { view = GetCompiledView <dynamic>(processedContentStream); var cachePolicy = new CacheItemPolicy(); cachePolicy.ChangeMonitors.Add(new HostFileChangeMonitor(new List <string> { viewLocationResult.Location })); cache.Add(new System.Runtime.Caching.CacheItem(viewLocationResult.Location, view), cachePolicy); } view.Global = _modelProvider.GetGlobalModel(); view.Model = model ?? _modelProvider.GetModel(Path.GetFileNameWithoutExtension(viewLocationResult.Location)); view.RenderPartialImpl = (partialViewName, partialModel) => new HtmlStringLiteral(ExecuteView(Conventions.PartialsPrefix + partialViewName, partialModel)); view.Execute(); if (string.IsNullOrEmpty(view.Layout)) { return(view.GetContents()); } else { string layout = ExecuteView(String.Format("{0}{1}", Conventions.LayoutsPrefix, view.Layout), model); return(layout.Replace("{{content}}", view.GetContents())); } }