forked from openstore-ecommerce/OpenStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmlConnector.ashx.cs
723 lines (624 loc) · 30 KB
/
XmlConnector.ashx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Xml;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using Microsoft.ApplicationBlocks.Data;
using Microsoft.SqlServer.Server;
using NBrightCore.common;
using NBrightCore.render;
using NBrightDNN;
using Nevoweb.DNN.NBrightBuy.Components;
using DataProvider = DotNetNuke.Data.DataProvider;
using System.Web.Script.Serialization;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Exceptions;
using NBrightBuy.render;
using NBrightCore.images;
using Nevoweb.DNN.NBrightBuy.Components.Address;
using Nevoweb.DNN.NBrightBuy.Components.Cart;
using Nevoweb.DNN.NBrightBuy.Components.Clients;
using Nevoweb.DNN.NBrightBuy.Components.Interfaces;
using Nevoweb.DNN.NBrightBuy.Components.Orders;
using Nevoweb.DNN.NBrightBuy.Components.Payments;
using Nevoweb.DNN.NBrightBuy.Components.Products;
using Nevoweb.DNN.NBrightBuy.Components.Category;
using Nevoweb.DNN.NBrightBuy.Components.ItemLists;
using Nevoweb.DNN.NBrightBuy.Components.Plugins;
using RazorEngine.Compilation.ImpromptuInterface;
namespace Nevoweb.DNN.NBrightBuy
{
/// <summary>
/// Summary description for XMLconnector
/// </summary>
public class XmlConnector : IHttpHandler
{
private readonly JavaScriptSerializer _js = new JavaScriptSerializer();
private String _editlang = "";
public void ProcessRequest(HttpContext context)
{
#region "Initialize"
var strOut = "** No Action **";
var paramCmd = Utils.RequestQueryStringParam(context, "cmd");
var itemId = Utils.RequestQueryStringParam(context, "itemid");
var ctlType = Utils.RequestQueryStringParam(context, "ctltype");
var idXref = Utils.RequestQueryStringParam(context, "idxref");
var xpathpdf = Utils.RequestQueryStringParam(context, "pdf");
var xpathref = Utils.RequestQueryStringParam(context, "pdfref");
var lang = Utils.RequestQueryStringParam(context, "lang");
var language = Utils.RequestQueryStringParam(context, "language");
var moduleId = Utils.RequestQueryStringParam(context, "mid");
var moduleKey = Utils.RequestQueryStringParam(context, "mkey");
var parentid = Utils.RequestQueryStringParam(context, "parentid");
var entryid = Utils.RequestQueryStringParam(context, "entryid");
var entryxid = Utils.RequestQueryStringParam(context, "entryxid");
var catid = Utils.RequestQueryStringParam(context, "catid");
var catxid = Utils.RequestQueryStringParam(context, "catxid");
var templatePrefix = Utils.RequestQueryStringParam(context, "tprefix");
var value = Utils.RequestQueryStringParam(context, "value");
var itemListName = Utils.RequestQueryStringParam(context, "listname");
if (itemListName == "") itemListName = "ItemList";
if (itemListName == "*") itemListName = "ItemList";
#region "setup language"
// because we are using a webservice the system current thread culture might not be set correctly,
NBrightBuyUtils.SetContextLangauge(context);
var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
_editlang = NBrightBuyUtils.GetEditLang(ajaxInfo, Utils.GetCurrentCulture());
#endregion
Logging.Debug($"XmlConnector called with: paramCmd='{paramCmd}', itemId='{itemId}', itemListName='{itemListName}'");
#endregion
try
{
#region "Do processing of command"
if (paramCmd.StartsWith("client."))
{
strOut = ClientFunctions.ProcessCommand(paramCmd, context);
}
else if (paramCmd.StartsWith("orderadmin_"))
{
strOut = OrderFunctions.ProcessCommand(paramCmd, context);
}
else if (paramCmd.StartsWith("payment_"))
{
strOut = PaymentFunctions.ProcessCommand(paramCmd, context);
}
else if (paramCmd.StartsWith("product_"))
{
ProductFunctions.EntityTypeCode = "PRD";
strOut = ProductFunctions.ProcessCommand(paramCmd, context, _editlang);
}
else if (paramCmd.StartsWith("category_"))
{
CategoryFunctions.EntityTypeCode = "CATEGORY";
strOut = CategoryFunctions.ProcessCommand(paramCmd, context, _editlang);
}
else if (paramCmd.StartsWith("property_"))
{
PropertyFunctions.EntityTypeCode = "CATEGORY";
strOut = PropertyFunctions.ProcessCommand(paramCmd, context, _editlang);
}
else if (paramCmd.StartsWith("itemlist_"))
{
strOut = ItemListsFunctions.ProcessCommand(paramCmd, context);
}
else if (paramCmd.StartsWith("addressadmin_"))
{
strOut = AddressAdminFunctions.ProcessCommand(paramCmd, context);
}
else if (paramCmd.StartsWith("plugins_"))
{
strOut = PluginFunctions.ProcessCommand(paramCmd, context);
}
else if (paramCmd.StartsWith("cart_"))
{
strOut = CartFunctions.ProcessCommand(paramCmd, context);
}
else
{
switch (paramCmd)
{
case "test":
strOut = "<root>" + UserController.Instance.GetCurrentUserInfo().Username + "</root>";
break;
case "setdata":
break;
case "deldata":
break;
case "getdata":
strOut = GetReturnData(context);
break;
case "fileupload":
if (NBrightBuyUtils.CheckRights())
{
strOut = FileUpload(context);
}
break;
case "fileclientupload":
if (StoreSettings.Current.GetBool("allowupload"))
{
strOut = FileUpload(context, itemId);
}
break;
case "docdownload":
var fname = Utils.RequestQueryStringParam(context, "filename");
var filekey = Utils.RequestQueryStringParam(context, "key");
if (filekey != "")
{
var uData = new UserData();
if (uData.HasPurchasedDocByKey(filekey)) fname = uData.GetPurchasedFileName(filekey);
fname = StoreSettings.Current.FolderDocuments + "/" + fname;
}
if (fname != "")
{
strOut = fname; // return this is error.
var downloadname = Utils.RequestQueryStringParam(context, "downloadname");
var fpath = HttpContext.Current.Server.MapPath(fname);
if (downloadname == "") downloadname = Path.GetFileName(fname);
try
{
Utils.ForceDocDownload(fpath, downloadname, context.Response);
}
catch (Exception ex)
{
// ignore, robots can cause error on thread abort.
//Exceptions.LogException(ex);
Logging.Debug($"XmlConnector.ProcessRequest exception for {paramCmd} which is ignored because bots tend to cause these on thread abort: {ex.Message}.");
}
}
break;
case "printproduct":
break;
case "renderpostdata":
strOut = RenderPostData(context);
break;
case "getsettings":
strOut = GetSettings(context);
break;
case "savesettings":
if (NBrightBuyUtils.CheckRights()) strOut = SaveSettings(context);
break;
case "updateprofile":
strOut = UpdateProfile(context);
break;
case "dosearch":
strOut = DoSearch(context);
break;
case "resetsearch":
strOut = ResetSearch(context);
break;
case "orderby":
strOut = DoOrderBy(context);
break;
case "renderthemefolders":
strOut = RenderThemeFolders(context);
break;
}
}
if (strOut == "** No Action **")
{
var pluginData = new PluginData(PortalSettings.Current.PortalId);
var provList = pluginData.GetAjaxProviders();
foreach (var d in provList)
{
if (paramCmd.ToLower().StartsWith(d.Key.ToLower() + "_") || paramCmd.ToLower().StartsWith("cmd" + d.Key.ToLower() + "_"))
{
var ajaxprov = AjaxInterface.Instance(d.Key);
if (ajaxprov != null)
{
strOut = ajaxprov.ProcessCommand(paramCmd, context, _editlang);
}
}
}
}
#endregion
}
catch (Exception ex)
{
strOut = ex.ToString();
Logging.LogException(ex);
//Exceptions.LogException(ex);
}
#region "return results"
//send back xml as plain text
context.Response.Clear();
context.Response.ContentType = "text/plain";
context.Response.Write(strOut);
context.Response.End();
#endregion
}
public bool IsReusable
{
get
{
return false;
}
}
#region "fileupload"
private void UpdateProductImages(HttpContext context)
{
//get uploaded params
var settings = NBrightBuyUtils.GetAjaxDictionary(context);
if (!settings.ContainsKey("itemid")) settings.Add("itemid", "");
var productitemid = settings["itemid"];
var imguploadlist = settings["imguploadlist"];
if (Utils.IsNumeric(productitemid))
{
var imgs = imguploadlist.Split(',');
foreach (var img in imgs)
{
if (ImgUtils.IsImageFile(Path.GetExtension(img)) && img != "")
{
string fullName = StoreSettings.Current.FolderTempMapPath + "\\" + img;
if (File.Exists(fullName))
{
var imgResize = StoreSettings.Current.GetInt(StoreSettingKeys.productimageresize);
if (imgResize == 0) imgResize = 800;
var imagepath = ResizeImage(fullName, imgResize);
var imageurl = StoreSettings.Current.FolderImages.TrimEnd('/') + "/" + Path.GetFileName(imagepath);
AddNewImage(Convert.ToInt32(productitemid), imageurl, imagepath);
}
}
}
// clear any cache for the product.
ProductUtils.RemoveProductDataCache(PortalSettings.Current.PortalId, Convert.ToInt32(productitemid));
var cachekey = "AjaxProductImgs*" + productitemid;
Utils.RemoveCache(cachekey);
}
}
private String ResizeImage(String fullName, int imgSize = 640)
{
if (ImgUtils.IsImageFile(Path.GetExtension(fullName)))
{
var extension = Path.GetExtension(fullName);
var newImageFileName = StoreSettings.Current.FolderImagesMapPath.TrimEnd(Convert.ToChar("\\")) + "\\" + Utils.GetUniqueKey() + extension;
if (extension != null && extension.ToLower() == ".png")
{
newImageFileName = ImgUtils.ResizeImageToPng(fullName, newImageFileName, imgSize);
}
else
{
newImageFileName = ImgUtils.ResizeImageToJpg(fullName, newImageFileName, imgSize);
}
Utils.DeleteSysFile(fullName);
return newImageFileName;
}
return "";
}
private void AddNewImage(int itemId,String imageurl, String imagepath)
{
var objCtrl = new NBrightBuyController();
var dataRecord = objCtrl.Get(itemId);
if (dataRecord != null)
{
var strXml = "<genxml><imgs><genxml><hidden><imagepath>" + imagepath + "</imagepath><imageurl>" + imageurl + "</imageurl></hidden></genxml></imgs></genxml>";
if (dataRecord.XMLDoc.SelectSingleNode("genxml/imgs") == null)
{
dataRecord.AddXmlNode(strXml, "genxml/imgs", "genxml");
}
else
{
dataRecord.AddXmlNode(strXml, "genxml/imgs/genxml", "genxml/imgs");
}
objCtrl.Update(dataRecord);
}
}
private string FileUpload(HttpContext context, string itemid = "")
{
try
{
var strOut = "";
switch (context.Request.HttpMethod)
{
case "HEAD":
case "GET":
break;
case "POST":
case "PUT":
strOut = UploadFile(context, itemid);
break;
case "DELETE":
break;
case "OPTIONS":
break;
default:
context.Response.ClearHeaders();
context.Response.StatusCode = 405;
break;
}
return strOut;
}
catch (Exception ex)
{
return ex.ToString();
}
}
// Upload file to the server
private String UploadFile(HttpContext context, string itemid = "")
{
var statuses = new List<FilesStatus>();
var headers = context.Request.Headers;
if (string.IsNullOrEmpty(headers["X-File-Name"]))
{
return UploadWholeFile(context, statuses, itemid);
}
else
{
return UploadPartialFile(headers["X-File-Name"], context, statuses, itemid);
}
}
// Upload partial file
private String UploadPartialFile(string fileName, HttpContext context, List<FilesStatus> statuses, string itemid = "")
{
Regex fexpr = new Regex(StoreSettings.Current.Get("fileregexpr"));
if (fexpr.Match(fileName.ToLower()).Success)
{
if (itemid != "") itemid += "_";
if (context.Request.Files.Count != 1) throw new HttpRequestValidationException("Attempt to upload chunked file containing more than one fragment per request");
var inputStream = context.Request.Files[0].InputStream;
var fullName = StoreSettings.Current.FolderTempMapPath + "\\" + itemid + fileName;
using (var fs = new FileStream(fullName, FileMode.Append, FileAccess.Write))
{
var buffer = new byte[1024];
var l = inputStream.Read(buffer, 0, 1024);
while (l > 0)
{
fs.Write(buffer, 0, l);
l = inputStream.Read(buffer, 0, 1024);
}
fs.Flush();
fs.Close();
}
statuses.Add(new FilesStatus(new FileInfo(fullName)));
}
return "";
}
// Upload entire file
private String UploadWholeFile(HttpContext context, List<FilesStatus> statuses, string itemid = "")
{
if (itemid != "") itemid += "_";
for (int i = 0; i < context.Request.Files.Count; i++)
{
var file = context.Request.Files[i];
Regex fexpr = new Regex(StoreSettings.Current.Get("fileregexpr"));
if (fexpr.Match(file.FileName.ToLower()).Success)
{
file.SaveAs(StoreSettings.Current.FolderTempMapPath + "\\" + itemid + file.FileName);
statuses.Add(new FilesStatus(Path.GetFileName(itemid + file.FileName), file.ContentLength));
}
}
return "";
}
private void WriteJsonIframeSafe(HttpContext context, List<FilesStatus> statuses)
{
context.Response.AddHeader("Vary", "Accept");
try
{
if (context.Request["HTTP_ACCEPT"].Contains("application/json"))
context.Response.ContentType = "application/json";
else
context.Response.ContentType = "text/plain";
}
catch
{
context.Response.ContentType = "text/plain";
}
var jsonObj = _js.Serialize(statuses.ToArray());
context.Response.Write(jsonObj);
}
#endregion
#region "SQL Data return"
private string GetReturnData(HttpContext context)
{
try
{
var strOut = "";
var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
var xmlData = GenXmlFunctions.GetGenXmlByAjax(strIn, "");
var objInfo = new NBrightInfo();
objInfo.ItemID = -1;
objInfo.TypeCode = "AJAXDATA";
objInfo.XMLData = xmlData;
var settings = objInfo.ToDictionary();
var themeFolder = StoreSettings.Current.ThemeFolder;
if (settings.ContainsKey("themefolder")) themeFolder = settings["themefolder"];
var templCtrl = NBrightBuyUtils.GetTemplateGetter(themeFolder);
if (!settings.ContainsKey("portalid")) settings.Add("portalid", PortalSettings.Current.PortalId.ToString("")); // aways make sure we have portalid in settings
var objCtrl = new NBrightBuyController();
// run SQL and template to return html
if (settings.ContainsKey("sqltpl") && settings.ContainsKey("xsltpl"))
{
var strSql = templCtrl.GetTemplateData(settings["sqltpl"], Utils.GetCurrentCulture(), true, true, true, StoreSettings.Current.Settings());
var xslTemp = templCtrl.GetTemplateData(settings["xsltpl"], Utils.GetCurrentCulture(), true, true, true, StoreSettings.Current.Settings());
// replace any settings tokens (This is used to place the form data into the SQL)
strSql = Utils.ReplaceSettingTokens(strSql, settings);
strSql = Utils.ReplaceUrlTokens(strSql);
strSql = GenXmlFunctions.StripSqlCommands(strSql); // don't allow anything to update through here.
strOut = objCtrl.GetSqlxml(strSql);
if (!strOut.StartsWith("<root>")) strOut = "<root>" + strOut + "</root>"; // always wrap with root node.
strOut = XslUtils.XslTransInMemory(strOut, xslTemp);
}
return strOut;
}
catch (Exception ex)
{
return ex.ToString();
}
}
#endregion
#region "Front Office Actions"
/// <summary>
/// This token used the ajax posted context data to render the razor template specified in "carttemplate"
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private String RenderPostData(HttpContext context)
{
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);
var carttemplate = ajaxInfo.GetXmlProperty("genxml/hidden/carttemplate");
var theme = ajaxInfo.GetXmlProperty("genxml/hidden/carttheme");
var lang = ajaxInfo.GetXmlProperty("genxml/hidden/lang");
var controlpath = ajaxInfo.GetXmlProperty("genxml/hidden/controlpath");
if (controlpath == "") controlpath = "/DesktopModules/NBright/NBrightBuy";
var razorTempl = "";
if (carttemplate != "")
{
if (lang == "") lang = Utils.GetCurrentCulture();
razorTempl = NBrightBuyUtils.RazorTemplRender(carttemplate, 0, "", ajaxInfo, controlpath, theme, lang, StoreSettings.Current.Settings());
}
return razorTempl;
}
/// <summary>
/// This is used to render a new theme dropdownlist when a change to the control path has been made.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private String RenderThemeFolders(HttpContext context)
{
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);
var uilang = ajaxInfo.GetXmlProperty("genxml/hidden/uilang");
var razorTempl = "";
if (uilang == "") uilang = Utils.GetCurrentCulture();
razorTempl = NBrightBuyUtils.RazorTemplRender("ThemeFolderSelect.cshtml", 0, "", ajaxInfo, "/DesktopModules/NBright/NBrightBuy", "config", uilang, StoreSettings.Current.Settings());
return razorTempl;
}
private string UpdateProfile(HttpContext context)
{
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context, true);
var profileData = new ProfileData();
profileData.UpdateProfileAjax(ajaxInfo.XMLData, StoreSettings.Current.DebugMode);
return "OK";
}
private string ResetSearch(HttpContext context)
{
// take all input and created a SQL select with data and save for processing on search list.
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context, true);
var navData = new NavigationData(ajaxInfo.PortalId, ajaxInfo.GetXmlProperty("genxml/hidden/modulekey"));
navData.Delete();
return "RESET";
}
private string DoSearch(HttpContext context)
{
// take all input and created a SQL select with data and save for processing on search list.
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context, true);
var tagList = new List<string>();
var nodList = ajaxInfo.XMLDoc.SelectNodes("genxml/hidden/*");
foreach (XmlNode nod in nodList)
{
tagList.Add(nod.InnerText);
}
var navData = new NavigationData(ajaxInfo.PortalId, ajaxInfo.GetXmlProperty("genxml/hidden/modulekey"));
navData.Build(ajaxInfo.XMLData,tagList);
navData.Mode = ajaxInfo.GetXmlProperty("genxml/hidden/navigationmode").ToLower();
navData.CategoryId = ajaxInfo.GetXmlPropertyInt("genxml/hidden/categoryid");
if (ajaxInfo.GetXmlProperty("genxml/hidden/pagenumber") != "") navData.PageNumber = ajaxInfo.GetXmlProperty("genxml/hidden/pagenumber");
if (ajaxInfo.GetXmlProperty("genxml/hidden/pagesize") != "") navData.PageSize = ajaxInfo.GetXmlProperty("genxml/hidden/pagesize");
if (ajaxInfo.GetXmlProperty("genxml/hidden/pagename") != "") navData.PageName = ajaxInfo.GetXmlProperty("genxml/hidden/pagename");
if (ajaxInfo.GetXmlProperty("genxml/hidden/pagemoduleid") != "") navData.PageModuleId = ajaxInfo.GetXmlProperty("genxml/hidden/pagemoduleid");
navData.SearchFormData = ajaxInfo.XMLData;
navData.Save();
return "OK";
}
private string DoOrderBy(HttpContext context)
{
// take all input and created a SQL select with data and save for processing on search list.
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context, true);
var navData = new NavigationData(ajaxInfo.PortalId, ajaxInfo.GetXmlProperty("genxml/hidden/modulekey"));
navData.OrderByIdx = ajaxInfo.GetXmlProperty("genxml/hidden/orderbyidx");
navData.OrderBy = " order by " + ajaxInfo.GetXmlProperty("genxml/hidden/orderby" + navData.OrderByIdx);
navData.Save();
return "OK";
}
#endregion
#region "Settings"
private String GetSettings(HttpContext context, bool clearCache = false)
{
try
{
var strOut = "";
//get uploaded params
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
var razortemplate = ajaxInfo.GetXmlProperty("genxml/hidden/razortemplate");
var themefolder = ajaxInfo.GetXmlProperty("genxml/dropdownlist/themefolder");
var controlpath = ajaxInfo.GetXmlProperty("genxml/hidden/controlpath");
if (controlpath == "") controlpath = "/DesktopModules/NBright/NBrightBuy";
if (razortemplate == "") return ""; // assume no settings requirted
if (moduleid == "") moduleid = "-1";
// do edit field data if a itemid has been selected
var obj = NBrightBuyUtils.GetSettings(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid));
obj.ModuleId = Convert.ToInt32(moduleid); // assign for new records
strOut = NBrightBuyUtils.RazorTemplRender(razortemplate, obj.ModuleId, "settings", obj, controlpath, themefolder, Utils.GetCurrentCulture(), null);
return strOut;
}
catch (Exception ex)
{
Logging.LogException(ex);
return ex.ToString();
}
}
private String SaveSettings(HttpContext context)
{
try
{
var objCtrl = new NBrightBuyController();
//get uploaded params
var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
if (Utils.IsNumeric(moduleid))
{
// get DB record
var nbi = NBrightBuyUtils.GetSettings(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid));
if (nbi.ModuleId == 0) // new setting record
{
nbi = CreateSettingsInfo(moduleid, nbi);
}
// get data passed back by ajax
var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
// update record with ajax data
nbi.UpdateAjax(strIn);
if (nbi.GetXmlProperty("genxml/hidden/modref") == "") nbi.SetXmlProperty("genxml/hidden/modref", Utils.GetUniqueKey(10));
if (nbi.TextData == "") nbi.TextData = "NBrightBuy";
objCtrl.Update(nbi);
NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId); // make sure all new settings are used.
}
return "";
}
catch (Exception ex)
{
Logging.LogException(ex);
return ex.ToString();
}
}
private NBrightInfo CreateSettingsInfo(String moduleid, NBrightInfo nbi)
{
var objCtrl = new NBrightBuyController();
nbi = objCtrl.GetByType(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), "SETTINGS");
if (nbi == null)
{
nbi = new NBrightInfo(true); // populate empty XML so we can update nodes.
nbi.GUIDKey = "";
nbi.PortalId = PortalSettings.Current.PortalId;
nbi.ModuleId = Convert.ToInt32(moduleid);
nbi.TypeCode = "SETTINGS";
nbi.Lang = "";
}
//rebuild xml
nbi.ModuleId = Convert.ToInt32(moduleid);
nbi.GUIDKey = Utils.GetUniqueKey(10);
nbi.SetXmlProperty("genxml/hidden/modref", nbi.GUIDKey);
return nbi;
}
#endregion
}
}