Error executing template "Designs/FifthField/ItemCreator/Create/review.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_f0707b9c0c6245e0b285e18a438a3a50.Execute() in f:\Domains\Sites\www.fifthfield.com\Files\Templates\Designs\FifthField\ItemCreator\Create\review.cshtml:line 19
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.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
2 @using System
3 @using System.Web;
4 @using System.IO;
5
6 @{
7 var areaItem = Pageview.Area.Item;
8 var str_error = "";
9 var thisDay = DateTime.Today;
10
11 var bol_loggedIn = Dynamicweb.Security.UserManagement.User.IsExtranetUserLoggedIn();
12
13 var request = System.Web.HttpContext.Current.Request.Params;
14
15 var str_productID = request["productId"];
16 var str_prodHref = areaItem["ProductsPage"].ToString() + "&ProductID=" + str_productID;
17
18 var dw_product = Dynamicweb.Ecommerce.Services.Products.GetProductById(str_productID,string.Empty,true);
19 var str_productName = dw_product.Name;
20
21 var str_imagesFolder = "/Files/Files/FifthField/Products/";
22 var str_dominantColor = dw_product.GetProductFieldValue("DominantColor") != null ? dw_product.GetProductFieldValue("DominantColor").ToString() : "";
23 var str_imagePattern = str_imagesFolder + dw_product.Number + ".jpg";
24
25 str_imagePattern = File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(str_imagePattern)) ? str_imagePattern : areaItem["NoImage"].ToString();
26 var str_image = dw_product.ImageLarge != "" ? dw_product.ImageLarge : dw_product.ImageMedium != "" ? dw_product.ImageMedium : dw_product.ImageSmall != "" ? dw_product.ImageSmall : str_imagePattern;
27 var str_email = GetString("ItemCreator:Edit.Item.Email.Value") != "" ? GetString("ItemCreator:Edit.Item.Email.Value") : Pageview.User?.Email != null ? Pageview.User?.Email.ToString() : "";
28
29 string siteKey = Dynamicweb.Core.Converter.ToString(Dynamicweb.Data.Database.ExecuteScalar("SELECT TOP 1 SiteKey FROM _GoogleReCaptcha"));
30
31 var rqst = HttpContext.Current.Request;
32 var referer = rqst.UrlReferrer != null ? rqst.UrlReferrer.Host : "";
33 if (rqst.Url.Host != referer)
34 {
35 HttpContext.Current.Response.Redirect("/", true);
36 }
37 }
38
39 @if(request["success"] != null){
40 using (var obj_command = Dynamicweb.Data.Database.CreateConnection().CreateCommand())
41 {
42 obj_command.CommandText = "SELECT ROUND(AVG(CAST(Rate as float)), 2) FROM ItemType_Reviews WHERE Product=@productID";
43 obj_command.Parameters.Add(new System.Data.SqlClient.SqlParameter()
44 {
45 ParameterName = "productID",
46 SqlDbType = System.Data.SqlDbType.NVarChar,
47 Value = str_productID ?? ""
48 });
49
50 if(obj_command.ExecuteScalar() != null)
51 {
52 dw_product.Rating = Convert.ToDouble(obj_command.ExecuteScalar().ToString());
53 dw_product.Save();
54 }
55 }
56
57 <h2>@Translate("Thank you for helping us to help others.")</h2>
58 <a class="btnBlueYellow goToReview" href="@(str_prodHref)&goToReview=@GetString("ItemCreator:Item.Id")">@Translate("See this review")</a>
59
60 }else{
61 <div id="reviewProductHolder" class="row">
62 <div class="col-xs-12 col-md-4">
63 <p class="h3">@Translate("Our View on Reviews") <a href="#" id="hideShowReviewDisclaimer"><i class="fa"></i></a></p>
64 <p id="reviewDisclaimer">@Translate("ReviewDisclaimer", "With this review you are helping others to get the right product. We will never send unwanted promotional emails nor will we ever rent, sell, forward or display any email address. Thank you for your help.")</p>
65 <hr class="hidden-md hidden-lg col-xs-8 col-sm-10 col-xs-offset-1"/>
66 </div>
67 <div class="col-xs-12 col-md-8">
68 <figure>
69 <a href="@str_prodHref"><img src='/admin/public/getimage.ashx?Image=@str_image&Format=jpg&AlternativeImage=files/templates/designs/FifthField/images/alternativeImage.jpg&Width=350&Height=200&Compression=80&Crop=5' alt="@str_productName" title="@str_productName" /></a>
70 </figure>
71 <div class="averageRating">
72 <span class="productProperties">@Translate("Name"): <a href="@str_prodHref"><span class="blue2dColor">@str_productName</span></a></span><br/>
73 <span class="productProperties">@Translate("Price"): <span class="blue2dColor">@dw_product.Price</span></span><br/>
74 <span class="productProperties">@Translate("Average Rating"): </span>
75
76 @if(dw_product.Rating == 0){
77 <span id="notRatedYet">@Translate("No reviews yet.")</span>
78 }else{
79 @getProductStars(dw_product.Rating)
80 }
81 </div>
82 <p class="newsletterEmail">@Translate("HelpUsReview", "Help us help others. No fields are required, you may review anonymously by simply scrolling to the bottom and rating the product.")</p>
83 @if(!bol_loggedIn){
84 <p class="newsletterEmail">@Translate("If you sign in we will keep track of your reviews in your account center.")</p>
85 }
86 </div>
87 </div>
88 @GetString("ItemCreator:Edit.Form.Begin").Replace("<form ", "<form class=\"DMForms col-xs-12\" data-action=\"/Default.aspx?ID="+areaItem["ReCaptcha"]+"\" ")
89 <input type="hidden" name="success" value="true" />
90 <input type="hidden" id="Product" name="Product" value="@str_productID" />
91 <input type="hidden" id="Yes" name="Yes" value="0" />
92 <input type="hidden" id="No" name="No" value="0" />
93 <input type="hidden" id="Date" name="Date" value="@thisDay.ToString("MMMM") @thisDay.Day, @thisDay.Year" />
94 if(bol_loggedIn){
95 @GetString("ItemCreator:Edit.Item.UserID.Control")
96 }
97
98 <fieldset>
99 <label for="@GetValue("ItemCreator:Edit.Item.YourName.Name")">@Translate("Your Name")</label>
100 <input type="text" name="@GetValue("ItemCreator:Edit.Item.YourName.SystemName")" value="@GetValue("ItemCreator:Edit.Item.YourName.Value")" />
101 </fieldset>
102 <fieldset class="Select">
103 <label for="@GetValue("ItemCreator:Edit.Item.GraduationDate.Name")">@Translate("Graduating Year")</label>
104 <select id='@GetValue("ItemCreator:Edit.Item.GraduationDate.SystemName")' name='@GetValue("ItemCreator:Edit.Item.GraduationDate.SystemName")' value='@GetValue("ItemCreator:Edit.Item.GraduationDate.Value")'>
105 @for(var i=(DateTime.Now.Year + 8); i>1949;i--){
106 if(i != DateTime.Now.Year){
107 <option value="@i">@i</option>
108 }else{
109 <option value="@i" selected="selected">@i</option>
110 }
111 }
112 <option value='@Translate("Prior1950")'>@Translate("Prior to 1950")</option>
113 <option value='@Translate("Non-graduate")'>@Translate("Non-graduate")</option>
114 </select>
115 </fieldset>
116 <fieldset>
117 <label for="@GetValue("ItemCreator:Edit.Item.Discipline.Name")">@Translate("Discipline")</label>
118 <input type="text" name="@GetValue("ItemCreator:Edit.Item.Discipline.SystemName")" value="@GetValue("ItemCreator:Edit.Item.Discipline.Value")" />
119 </fieldset>
120 <fieldset>
121 <label for="@GetValue("ItemCreator:Edit.Item.Email.Name")">@Translate("E-mail")</label>
122 <input type="text" name="@GetValue("ItemCreator:Edit.Item.Email.SystemName")" value="@str_email" />
123 <p class="newsletterEmail">@Translate("We will never send unwanted promotional emails nor will we ever rent, sell, display or forward any email address.")</p>
124 </fieldset>
125 <fieldset>
126 <label for="@GetValue("ItemCreator:Edit.Item.Comment.Name")">@Translate("Comment")</label>
127 <textarea name="@GetValue("ItemCreator:Edit.Item.Comment.SystemName")" value="@GetValue("ItemCreator:Edit.Item.Comment.Value")"></textarea>
128 </fieldset>
129 <fieldset class="fitContainer">
130 <span>@Translate("Fit")</span>
131 <ul>
132 <li><label for="Fit_0"><input type="radio" id="Fit_0" name="Fit" value="1"></label></li>
133 <li><label for="Fit_1"><input type="radio" id="Fit_1" name="Fit" value="2"></label></li>
134 <li class="active"><label for="Fit_2"><input checked type="radio" id="Fit_2" name="Fit" value="3"></label></li>
135 <li><label for="Fit_3"><input type="radio" id="Fit_3" name="Fit" value="4"></label></li>
136 <li><label for="Fit_4"><input type="radio" id="Fit_4" name="Fit" value="5"></label></li>
137 </ul>
138 <span class="fitText">*@Translate("Select if Applicable")</span>
139 <div class="fitLegends">
140 <span>@Translate("Fits small")</span>
141 <span>@Translate("Fits big")</span>
142 </div>
143 </fieldset>
144 <fieldset class="rate">
145 <span>@Translate("Rate")</span>
146 <ul>
147 <li class="active">
148 <label for="Rate_4">
149 <input type="radio" id="Rate_4" name="Rate" value="5">
150 </label>
151 </li>
152 <li>
153 <label for="Rate_3">
154 <input type="radio" id="Rate_3" name="Rate" value="4">
155 </label>
156 </li>
157 <li>
158 <label for="Rate_2">
159 <input type="radio" id="Rate_2" name="Rate" value="3">
160 </label>
161 </li>
162 <li>
163 <label for="Rate_1">
164 <input type="radio" id="Rate_1" name="Rate" value="2">
165 </label>
166 </li>
167 <li>
168 <label for="Rate_0">
169 <input checked type="radio" id="Rate_0" name="Rate" value="1">
170 </label>
171 </li>
172 </ul>
173 </fieldset>
174
175 <div class="g-recaptcha" data-error="@Translate("recaptchaError","Please let us know you are not a robot")" data-sitekey="@siteKey"></div>
176
177 <input class="btnBlueYellow" value='@Translate("Send")' />
178
179 foreach (var error in GetLoop("ValidationErrors")){
180 str_error += "---"+error.GetValue("ItemCreator:Edit.Validation.FieldName")+": "+error.GetValue("ItemCreator:Edit.Validation.Error");
181 }
182
183 @GetString("ItemCreator:Edit.Form.End")
184
185 @SnippetStart("jsOnLoad")
186 <text>
187 var str_error = "@str_error";
188 onLoadReviewForm(str_error,$('#ItemCreator_EditForm_54'));
189 </text>
190 @SnippetEnd("jsOnLoad")
191 }
192
193 @helper getProductStars(double num_productRating){
194 var str_starClass = "";
195 var str_halfStar = "";
196
197 <ul class="rating noClick">
198 @for(var s=5;s>0;s--){
199 if(s == Math.Ceiling(num_productRating)){
200 str_starClass = "class='star'";
201 str_halfStar = !(num_productRating - Math.Round(num_productRating) == 0) ? "fa-star-half-o" : "fa-star" ;
202 }else{
203 str_starClass = "";
204 str_halfStar = "fa-star";
205 }
206
207 <li data-star="@s" @str_starClass><i class="fa @str_halfStar"></i></li>
208 }
209 </ul>
210 }