-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPromoXmlConnector.ashx.cs
268 lines (214 loc) · 9.68 KB
/
PromoXmlConnector.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
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Web;
using System.Xml;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using NBrightCore;
using NBrightCore.common;
using NBrightCore.images;
using NBrightCore.render;
using NBrightDNN;
using DataProvider = DotNetNuke.Data.DataProvider;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Exceptions;
using Nevoweb.DNN.NBrightBuy.Components;
namespace Nevoweb.DNN.NBrightBuy.Providers.QtyPromo
{
/// <summary>
/// Summary description for XMLconnector
/// </summary>
public class PromoXmlConnector : IHttpHandler
{
private String _lang = "";
private String _itemid = "";
public void ProcessRequest(HttpContext context)
{
#region "Initialize"
var strOut = "";
try
{
var moduleid = Utils.RequestQueryStringParam(context, "mid");
var paramCmd = Utils.RequestQueryStringParam(context, "cmd");
var lang = Utils.RequestQueryStringParam(context, "lang");
var language = Utils.RequestQueryStringParam(context, "language");
_itemid = Utils.RequestQueryStringParam(context, "itemid");
#region "setup language"
// because we are using a webservice the system current thread culture might not be set correctly,
// so use the lang/lanaguge param to set it.
if (lang == "") lang = language;
if (!string.IsNullOrEmpty(lang)) _lang = lang;
// default to current thread if we have no language.
if (_lang == "") _lang = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(_lang);
#endregion
#endregion
#region "Do processing of command"
strOut = "ERROR!! - No Security rights for current user!";
if (CheckRights())
{
switch (paramCmd)
{
case "test":
strOut = "<root>" + UserController.Instance.GetCurrentUserInfo().Username + "</root>";
break;
case "getdata":
strOut = GetData(context);
break;
case "addnew":
strOut = GetData(context, true);
break;
case "deleterecord":
strOut = DeleteData(context);
break;
case "savedata":
strOut = SaveData(context);
break;
case "selectlang":
strOut = SaveData(context);
break;
}
}
#endregion
}
catch (Exception ex)
{
strOut = ex.ToString();
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 "Methods"
private String GetData(HttpContext context,bool clearCache = false)
{
var objCtrl = new NBrightBuyController();
var strOut = "";
//get uploaded params
var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
var typeCode = ajaxInfo.GetXmlProperty("genxml/hidden/typecode");
var newitem = ajaxInfo.GetXmlProperty("genxml/hidden/newitem");
var selecteditemid = ajaxInfo.GetXmlProperty("genxml/hidden/selecteditemid");
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");
if (editlang == "") editlang = _lang;
if (!Utils.IsNumeric(moduleid)) moduleid = "-2"; // use moduleid -2 for razor
if (clearCache) NBrightBuyUtils.RemoveModCache(Convert.ToInt32(moduleid));
if (newitem == "new") selecteditemid = AddNew(moduleid, typeCode);
var templateControl = "/DesktopModules/NBright/NBrightQtyPromo";
if (Utils.IsNumeric(selecteditemid))
{
// do edit field data if a itemid has been selected
var obj = objCtrl.Get(Convert.ToInt32(selecteditemid), "",editlang);
strOut = NBrightBuyUtils.RazorTemplRender(typeCode.ToLower() + "fields.cshtml", Convert.ToInt32(moduleid), _lang + itemid + editlang + selecteditemid, obj, templateControl, "config", _lang, StoreSettings.Current.Settings());
}
else
{
// Return list of items
var l = objCtrl.GetList(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), typeCode, "", " order by [XMLData].value('(genxml/textbox/validuntil)[1]','nvarchar(50)'), ModifiedDate desc", 0, 0, 0, 0, editlang);
strOut = NBrightBuyUtils.RazorTemplRenderList(typeCode.ToLower() + "list.cshtml", Convert.ToInt32(moduleid), _lang + editlang, l, templateControl, "config",_lang,StoreSettings.Current.Settings());
}
return strOut;
}
private String AddNew(String moduleid,String typeCode)
{
if (!Utils.IsNumeric(moduleid)) moduleid = "-2"; // -2 for razor
var objCtrl = new NBrightBuyController();
var nbi = new NBrightInfo(true);
nbi.PortalId = PortalSettings.Current.PortalId;
nbi.TypeCode = typeCode;
nbi.ModuleId = Convert.ToInt32(moduleid);
nbi.ItemID = -1;
var itemId = objCtrl.Update(nbi);
nbi.ItemID = itemId;
foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
{
var nbi2 = new NBrightInfo(true);
nbi2.PortalId = PortalSettings.Current.PortalId;
nbi2.TypeCode = typeCode + "LANG";
nbi2.ModuleId = Convert.ToInt32(moduleid);
nbi2.ItemID = -1;
nbi2.Lang = lang;
nbi2.ParentItemId = itemId;
nbi2.GUIDKey = "";
nbi2.ItemID = objCtrl.Update(nbi2);
}
NBrightBuyUtils.RemoveModCache(nbi.ModuleId);
return nbi.ItemID.ToString("");
}
private String SaveData(HttpContext context)
{
var objCtrl = new NBrightBuyController();
//get uploaded params
var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
var lang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");
if (lang == "") lang = ajaxInfo.GetXmlProperty("genxml/hidden/lang");
if (lang == "") lang = _lang;
if (Utils.IsNumeric(itemid))
{
// get DB record
var nbi = objCtrl.Get(Convert.ToInt32(itemid));
if (nbi != null)
{
var typecode = nbi.TypeCode;
// get data passed back by ajax
var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
// update record with ajax data
nbi.UpdateAjax(strIn);
if (nbi.GUIDKey == "") nbi.GUIDKey = Utils.GetUniqueKey();
objCtrl.Update(nbi);
// do langauge record
var nbi2 = objCtrl.GetDataLang(Convert.ToInt32(itemid), lang);
nbi2.UpdateAjax(strIn);
objCtrl.Update(nbi2);
DataCache.ClearCache(); // clear ALL cache.
}
}
return "";
}
private String DeleteData(HttpContext context)
{
var objCtrl = new NBrightBuyController();
//get uploaded params
var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
if (Utils.IsNumeric(itemid))
{
// delete DB record
objCtrl.Delete(Convert.ToInt32(itemid));
NBrightBuyUtils.RemoveModCache(-2);
}
return "";
}
#endregion
private Boolean CheckRights()
{
if (UserController.Instance.GetCurrentUserInfo().IsInRole(StoreSettings.ManagerRole) || UserController.Instance.GetCurrentUserInfo().IsInRole(StoreSettings.EditorRole) || UserController.Instance.GetCurrentUserInfo().IsInRole("Administrators"))
{
return true;
}
return false;
}
}
}