Error executing template "/Designs/Swift/Swift_Email/Paragraph/GBG_EmailButton.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_61b61da5fc304334a85cd69ad07103dc.Execute() in D:\dynamicweb.net\Solutions\Degree\granberg.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Swift_Email\Paragraph\GBG_EmailButton.cshtml:line 134
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
2 @using Dynamicweb.Ecommerce.ProductCatalog
3 @using Dynamicweb.Rendering;
4 @using System.Web;
5 @using Dynamicweb.Security.UserManagement;
6
7 @functions {
8 private string GetFontStack()
9 {
10 return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
11 }
12
13 private string GetTableReset()
14 {
15 return "border:0;margin:0;outline:0;padding:0;";
16 }
17 }
18
19 @{
20 string blockType = "button_block";
21
22 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
23 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
24 var blockId = Model.ID;
25 var block = Model.Item;
26
27 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
28 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
29 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
30
31 var rowId = Dynamicweb.Content.Services.Paragraphs.GetParagraph(blockId).GridRowId;
32 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
33 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
34 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
35 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
36 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
37
38 var blockThemeId = block.GetRawValueString("Theme");
39 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
40 var blockTheme = blockThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph)?.Item : rowTheme is object ? rowTheme : emailContentTheme;
41
42 string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
43 string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
44 string borderColor = blockTheme != null ? blockTheme.GetString("BorderColor", "transparent") : string.Empty;
45 string borders = block.GetRawValueString("Borders", "none");
46 string borderThicknes = block.GetRawValueString("BorderThicknes", "0") + "px";
47 string borderClass = string.Empty;
48
49 var signInPage = "/Default.aspx?ID=" + GetPageIdByNavigationTag("SignInPage");
50
51
52 switch (borders)
53 {
54 case "top":
55 borderClass = $"border-top:{borderThicknes} solid {borderColor};";
56 break;
57 case "bottom":
58 borderClass = $"border-bottom:{borderThicknes} solid {borderColor};";
59 break;
60 case "top-bottom":
61 borderClass = $"border-top:{borderThicknes} solid {borderColor}; border-bottom:{borderThicknes} solid {borderColor}; border-left:0;border-right:0;";
62 break;
63 case "all":
64 borderClass = $"border:{borderThicknes} solid {borderColor};";
65 break;
66 }
67
68 string title = block.GetString("Title", string.Empty);
69 string padding = block.GetRawValueString("Padding", "0");
70 string align = block.GetRawValueString("Align", "left");
71 var link = new Dynamicweb.Frontend.LinkViewModel();
72 string linkType = block.GetRawValueString("LinkType", "page");
73
74 if (linkType == "page" && block.GetLink("PageLink") != null)
75 {
76 if (!block.GetLink("PageLink").IsExternal)
77 {
78 link = new Dynamicweb.Frontend.LinkViewModel()
79 {
80 Url = Dynamicweb.Context.Current.Request.Url.Scheme + "://" + Dynamicweb.Context.Current.Request.Url.Host + "/Default.aspx?ID=" + block.GetLink("PageLink").PageId
81 };
82 } else {
83 link = new Dynamicweb.Frontend.LinkViewModel()
84 {
85 Url = block.GetLink("PageLink").Url
86 };
87 }
88 }
89
90 if (linkType == "product-group")
91 {
92 IList<ProductGroupViewModel> selectedGroups = block.GetValue<IList<ProductGroupViewModel>>("ProductGroupLink");
93 IList<string> groupIds = new List<string> { };
94
95 if (selectedGroups != null)
96 {
97 foreach (var fromGroup in selectedGroups)
98 {
99 groupIds.Add(fromGroup.Id);
100 }
101 }
102
103 link = new Dynamicweb.Frontend.LinkViewModel()
104 {
105 Url = Dynamicweb.Context.Current.Request.Url.Scheme + "://" + Dynamicweb.Context.Current.Request.Url.Host + "/Default.aspx?ID=" + GetPageIdByNavigationTag("Shop") + "&GroupID=" + string.Join(",", groupIds)
106 };
107 }
108
109 if (linkType == "product")
110 {
111 ProductListViewModel products = block.GetValue<ProductListViewModel>("ProductLink");
112 IList<string> productIds = new List<string> { };
113
114 if (products != null && products.Products.Any())
115 {
116 foreach (var product in products.Products)
117 {
118 productIds.Add(product.Id);
119 }
120 string productParameter = productIds.Count == 1 ? "ProductID" : "MainProductId";
121 string productLink = "/" + products.Products?.FirstOrDefault()?.GetProductLink(GetPageIdByNavigationTag("Shop"), false);
122 productLink = productIds.Count != 1 ? "/Default.aspx?ID=" + GetPageIdByNavigationTag("Shop") + "&" + productParameter + "=" + string.Join(",", productIds).Trim() : productLink;
123
124 link = new Dynamicweb.Frontend.LinkViewModel()
125 {
126 Url = Dynamicweb.Context.Current.Request.Url.Scheme + "://" + Dynamicweb.Context.Current.Request.Url.Host + productLink
127 };
128 }
129 }
130
131 if (linkType == "command")
132 {
133 string command = block.GetRawValueString("SystemCommand");
134 var user = Pageview.Context.GetValue("User") as User;
135 if (user != null)
136 {
137 string token = System.Guid.NewGuid().ToString();
138 string resetLink = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(GetPageIdByNavigationTag("SignInPage")) + "?Username=" + user.UserName + "&RecoveryToken=" + token;
139
140 // Set the token on the user
141 user.PasswordRecoveryTokenExpirationTime = System.DateTime.UtcNow.AddHours(Dynamicweb.Configuration.SystemConfiguration.Instance.GetInt32("/Globalsettings/Modules/UserManagement/ExtranetPasswordSecurity/RecoveryTokenTimeout"));
142 user.PasswordRecoveryToken = token;
143 user.Save();
144
145
146 link = new Dynamicweb.Frontend.LinkViewModel()
147 {
148 Url = resetLink
149 };
150 }
151 }
152 }
153
154 <table id="@blockId" class="@blockType" align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;mso-line-height-rule:exactly;@GetTableReset()color:inherit;width:100%;@GetFontStack()">
155 <tbody>
156 <tr style="@GetTableReset()">
157 <td style="mso-line-height-rule:exactly;mso-text-raise:0px;mso-table-lspace:0pt;mso-table-rspace:0pt;@GetFontStack()font-weight:400;text-align:@align;@(backgroundColor)@(foregroundColor)@GetTableReset()padding:@(padding)px;@(borderClass)" width="100%">
158 @if (link is object)
159 {
160 @RenderButton(link, blockTheme, align, title)
161 }
162 <!--[if mso]><br/><![endif]-->
163 </td>
164 </tr>
165 </tbody>
166 </table>
167
168 @helper RenderButton(Dynamicweb.Frontend.LinkViewModel link, Dynamicweb.Frontend.ItemViewModel theme, string align, string title)
169 {
170 var backgroundColor = theme?.GetColor("ButtonPrimaryBackgroundColor");
171 var foregroundColor = theme?.GetColor("ButtonPrimaryForegroundColor");
172 var borderColor = theme?.GetColor("ButtonPrimaryBorderColor");
173
174 var parms = new Dictionary<string, object>();
175 parms.Add("backgroundColor", backgroundColor);
176 parms.Add("foregroundColor", foregroundColor);
177 parms.Add("borderColor", borderColor);
178 parms.Add("align", align);
179 parms.Add("title", title);
180
181 @RenderPartial("Swift_Email/Components/Button.cshtml", link ?? new Dynamicweb.Frontend.LinkViewModel(), parms)
182 }
|