AdminController.cs 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766
  1. using ClosedXML.Excel;
  2. using DocumentFormat.OpenXml.Drawing;
  3. using DocumentFormat.OpenXml.Wordprocessing;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.AspNetCore.Server.IISIntegration;
  8. using Microsoft.Extensions.Configuration;
  9. using Nancy;
  10. using OfficeOpenXml;
  11. using SuperAdmin.Models.Http;
  12. using SuperAdmin.Models.Object;
  13. using SuperAdmin.Source;
  14. using SuperCms.Extensions;
  15. using Newtonsoft.Json;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Threading.Tasks;
  21. using Timor_BPSuperAdmin.Models.Http;
  22. using static SuperAdmin.Source.CommonUtils;
  23. namespace SuperAdmin.Controllers
  24. {
  25. public class AdminController : BaseController
  26. {
  27. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  28. public AdminController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
  29. {
  30. }
  31. public IActionResult ReportUssdDetail()
  32. {
  33. if (!CheckAuthToken())
  34. {
  35. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  36. }
  37. return View();
  38. }
  39. [HttpPost]
  40. public IActionResult ReportUssdDetailSearch(PushUssdDetailReq req)
  41. {
  42. if (!CheckAuthToken())
  43. {
  44. return Json(new
  45. {
  46. error = "-1",
  47. content = "Login first"
  48. });
  49. }
  50. req.rowsOnPage = req.rowsOnPage ?? "100";
  51. req.seqPage = req.seqPage ?? "1";
  52. req.order = req.order ?? "desc";
  53. req.msisdn = ValidateMsisdn(req.msisdn);
  54. String url = GetParameter(CommonUtils.WsType.PushUssdDetailGetList);
  55. PushUssdDetailRes res = PushUssdDetailRes.Parse(SendPost(req, url));
  56. var fdsds = "dsds";
  57. return PartialView("../Partial/_ReportUssdDetail", res.list);
  58. }
  59. [HttpPost]
  60. public IActionResult ReportUssdDetailExport(PushUssdDetailReq req)
  61. {
  62. if (!CheckAuthToken())
  63. {
  64. return null;
  65. }
  66. // Áp dụng cùng logic phân trang/thứ tự như ReportUssdDetailSearch để dữ liệu export khớp với search
  67. req.rowsOnPage = req.rowsOnPage ?? "100";
  68. req.seqPage = req.seqPage ?? "1";
  69. req.order = req.order ?? "desc";
  70. String url = GetParameter(CommonUtils.WsType.PushUssdDetailGetList);
  71. PushUssdDetailRes res = PushUssdDetailRes.Parse(SendPost(req, url));
  72. var list = res.list ?? new List<PushUssdDetail>();
  73. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  74. string fileName = "campaign_detail.xlsx";
  75. try
  76. {
  77. using (var workbook = new XLWorkbook())
  78. {
  79. int i = 1;
  80. IXLWorksheet worksheet = workbook.Worksheets.Add("Campaign Detail");
  81. worksheet.Column(i).Width = 15; worksheet.Cell(1, i++).Value = "No.";
  82. worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "Request ID";
  83. worksheet.Column(i).Width = 30; worksheet.Cell(1, i++).Value = "Campaign";
  84. worksheet.Column(i).Width = 18; worksheet.Cell(1, i++).Value = "Msisdn";
  85. worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Send Time";
  86. worksheet.Column(i).Width = 12; worksheet.Cell(1, i++).Value = "Send Status";
  87. worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "Total Step";
  88. worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "Is Step 1";
  89. worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Step 1 Time";
  90. worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "Is Step 2";
  91. worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Step 2 Time";
  92. worksheet.Column(i).Width = 18; worksheet.Cell(1, i++).Value = "Error Code";
  93. worksheet.Column(i).Width = 12; worksheet.Cell(1, i++).Value = "Is Success";
  94. worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Insert Time";
  95. worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Last Update";
  96. worksheet.Column(i).Width = 50; worksheet.Cell(1, i++).Value = "Msg Content";
  97. worksheet.Row(1).Style.Font.Bold = true;
  98. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  99. if (list.Count > 0)
  100. {
  101. for (int index = 1; index <= list.Count; index++)
  102. {
  103. i = 1;
  104. var obj = list[index - 1];
  105. worksheet.Cell(index + 1, i++).Value = index;
  106. worksheet.Cell(index + 1, i++).Value = obj.requestId ?? "";
  107. // Campaign: ID + Name (giống view)
  108. string campaignDisplay = obj.campaignId ?? "";
  109. if (!string.IsNullOrEmpty(obj.campaignName))
  110. {
  111. campaignDisplay += " - " + obj.campaignName;
  112. }
  113. worksheet.Cell(index + 1, i++).Value = campaignDisplay;
  114. worksheet.Cell(index + 1, i++).Value = obj.msisdn ?? "";
  115. worksheet.Cell(index + 1, i++).Value = obj.sendTime ?? "";
  116. worksheet.Cell(index + 1, i++).Value = obj.sendStatus ?? "";
  117. worksheet.Cell(index + 1, i++).Value = obj.totalStep ?? "";
  118. worksheet.Cell(index + 1, i++).Value = obj.isStep1 ?? "";
  119. worksheet.Cell(index + 1, i++).Value = obj.step1Time ?? "";
  120. worksheet.Cell(index + 1, i++).Value = obj.isStep2 ?? "";
  121. worksheet.Cell(index + 1, i++).Value = obj.step2Time ?? "";
  122. worksheet.Cell(index + 1, i++).Value = obj.errorCode ?? "";
  123. worksheet.Cell(index + 1, i++).Value = obj.isSuccess ?? "";
  124. worksheet.Cell(index + 1, i++).Value = obj.insertTime ?? "";
  125. worksheet.Cell(index + 1, i++).Value = obj.lastUpdate ?? "";
  126. worksheet.Cell(index + 1, i++).Value = obj.msgContent ?? "";
  127. }
  128. }
  129. using (var stream = new MemoryStream())
  130. {
  131. workbook.SaveAs(stream);
  132. var content = stream.ToArray();
  133. return File(content, contentType, fileName);
  134. }
  135. }
  136. }
  137. catch (Exception)
  138. {
  139. return null;
  140. }
  141. }
  142. public IActionResult Index(String fromDate, String toDate)
  143. {
  144. try
  145. {
  146. if (!CheckAuthToken())
  147. {
  148. //return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  149. UserRoles vsa = HttpContext.Session.GetComplexData<UserRoles>("userInfo");
  150. //var listMenu = new List<String>();
  151. if (vsa != null && vsa.function != null)
  152. {
  153. var listObj = vsa.function;
  154. foreach (Function obj in listObj)
  155. {
  156. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + obj.link);
  157. }
  158. }
  159. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  160. }
  161. fromDate = fromDate ?? DateTime.Now.ToString("dd/MM/yyyy 00:00:00");
  162. toDate = toDate ?? DateTime.Now.ToString("dd/MM/yyyy 23:59:59");
  163. //DashboardModel model = LoadDashboard(fromDate, toDate);
  164. // init
  165. try
  166. {
  167. var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
  168. if (listService == null)
  169. {
  170. PreLoadService();
  171. }
  172. }
  173. catch (Exception ex)
  174. {
  175. PreLoadService();
  176. }
  177. return View();
  178. }
  179. catch (Exception ex)
  180. {
  181. log.Error("Error admin index: " + ex.Message, ex);
  182. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  183. }
  184. }
  185. public IActionResult Dashboard(String fromDate, String toDate)
  186. {
  187. DashboardModel model = LoadDashboard(fromDate, toDate);
  188. var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
  189. if (listService == null)
  190. {
  191. PreLoadService();
  192. }
  193. //
  194. return PartialView("../Partial/_Dashboard", model);
  195. }
  196. private DashboardModel LoadDashboard(String fromDate, String toDate)
  197. {
  198. string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
  199. string subDomain = GetParameter(UtilsController.Constant.SUB_DOMAIN);
  200. HttpContext.Session.SetComplexData("serviceName", serviceName);
  201. HttpContext.Session.SetComplexData("subDomain", subDomain);
  202. //String fromDate = DateTime.Now.AddDays(-30).ToString("dd/MM/yyyy");
  203. //String toDate = DateTime.Now.ToString("dd/MM/yyyy");
  204. //
  205. DashboardModel model = new DashboardModel();
  206. string url = GetParameter(CommonUtils.WsType.CamGetList);
  207. CampaignGetListReq req = new CampaignGetListReq();
  208. req.fromDate = fromDate;
  209. req.toDate = toDate;
  210. req.rowsOnPage = "1000000";
  211. req.seqPage = "1";
  212. // running
  213. req.status = CampaignStatus.Running;
  214. CampaignGetListRes running = CampaignGetListRes.Parse(SendPost(req, url));
  215. model.listRunning = running.list;
  216. // pending
  217. req.status = CampaignStatus.Pending + "," + CampaignStatus.Paused;
  218. CampaignGetListRes pending = CampaignGetListRes.Parse(SendPost(req, url));
  219. model.listPending = pending.list;
  220. return model;
  221. }
  222. // CAMPAIGN
  223. [HttpPost]
  224. public JsonResult UpdateCampaignStatus(String id, String status)
  225. {
  226. if (!CheckAuthToken())
  227. {
  228. return Json(new
  229. {
  230. error = "-1",
  231. content = "Login first"
  232. });
  233. }
  234. string account = HttpContext.Session.GetString("account");
  235. // get campaign by id
  236. string url = GetParameter(CommonUtils.WsType.CamGetList);
  237. CampaignGetListReq req = new CampaignGetListReq();
  238. req.id = id;
  239. CampaignGetListRes cpRes = CampaignGetListRes.Parse(SendPost(req, url));
  240. var cmp = cpRes.list[0];
  241. // update status
  242. ChangeStatusReq updateReq = new ChangeStatusReq();
  243. updateReq.id = id;
  244. updateReq.status = status;
  245. updateReq.users = account;
  246. string result = SendPost(updateReq, GetParameter(CommonUtils.WsType.changeStatus));
  247. CommonRes res = CommonRes.Parse(result);
  248. return Json(new
  249. {
  250. error = res.responseCode,
  251. content = res.responseMessage
  252. });
  253. }
  254. public IActionResult CampaignManagement()
  255. {
  256. if (!CheckAuthToken())
  257. {
  258. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  259. }
  260. CriteriaSearchReq req = new CriteriaSearchReq();
  261. req.rowsOnPage = "1000000";
  262. req.seqPage = "1";
  263. req.order = "asc";
  264. req.isActive = "1";
  265. // load criteria
  266. CriteriaGetListRes res1 = CriteriaGetListRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.balanceGetList)));
  267. HttpContext.Session.SetComplexData("listBalance", res1.list);
  268. CriteriaGetListRes res2 = CriteriaGetListRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.expGetList)));
  269. HttpContext.Session.SetComplexData("listExpire", res2.list);
  270. CriteriaGetListRes res3 = CriteriaGetListRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.shortCodeGetList)));
  271. HttpContext.Session.SetComplexData("listShortCode", res3.list);
  272. // load whitelist sub active
  273. GetListSubReq req2 = new GetListSubReq();
  274. req2.rowsOnPage = "1000000";
  275. req2.seqPage = "1";
  276. req2.order = "asc";
  277. req2.subType = CommonUtils.ListSubType.Whitelist;
  278. GetListSubRes res4 = GetListSubRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.listSubGetList)));
  279. HttpContext.Session.SetComplexData("listSubFile", res4.list);
  280. PreLoadService();
  281. return View();
  282. }
  283. public IActionResult CampaignSearch(CampaignGetListReq req)
  284. {
  285. if (!CheckAuthToken())
  286. {
  287. return Json(new
  288. {
  289. error = "-1",
  290. content = "Login first"
  291. });
  292. }
  293. //string account = HttpContext.Session.GetString("account");
  294. //req.usersName = account;
  295. req.rowsOnPage = "1000000";
  296. req.seqPage = "1";
  297. req.order = "desc";
  298. //req.type = "1"; // already result
  299. String url = GetParameter(CommonUtils.WsType.CamGetList);
  300. CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
  301. //HttpContext.Session.SetComplexData("ExportGetListRes", res);
  302. //return Json(new
  303. //{
  304. // error = res.responseCode,
  305. // content = res.responseMessage,
  306. // data = res.list
  307. //});
  308. return PartialView("../Partial/_ListCampaign", res.list);
  309. }
  310. [HttpPost]
  311. public IActionResult CampaignExport(CampaignGetListReq req)
  312. {
  313. if (!CheckAuthToken())
  314. {
  315. return null;
  316. }
  317. String url = GetParameter(CommonUtils.WsType.CamGetList);
  318. CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
  319. var list = res.list;
  320. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  321. string fileName = "campaigns.xlsx";
  322. try
  323. {
  324. using (var workbook = new XLWorkbook())
  325. {
  326. int i = 1;
  327. IXLWorksheet worksheet = workbook.Worksheets.Add("Campaigns");
  328. worksheet.Column(i).Width = 15;
  329. worksheet.Cell(1, i++).Value = "No.";
  330. worksheet.Column(i).Width = 30;
  331. worksheet.Cell(1, i++).Value = "Name";
  332. worksheet.Column(i).Width = 20;
  333. worksheet.Cell(1, i++).Value = "From date";
  334. worksheet.Column(i).Width = 20;
  335. worksheet.Cell(1, i++).Value = "To Date";
  336. worksheet.Column(i).Width = 15;
  337. worksheet.Cell(1, i++).Value = "Type";
  338. worksheet.Column(i).Width = 15;
  339. worksheet.Cell(1, i++).Value = "Service Type";
  340. worksheet.Column(i).Width = 20;
  341. worksheet.Cell(1, i++).Value = "Services in Campaign";
  342. worksheet.Column(i).Width = 10;
  343. worksheet.Cell(1, i++).Value = "Priority";
  344. worksheet.Column(i).Width = 20;
  345. worksheet.Cell(1, i++).Value = "Modify Date";
  346. worksheet.Column(i).Width = 10;
  347. worksheet.Cell(1, i++).Value = "Status";
  348. // make color
  349. worksheet.Row(1).Style.Font.Bold = true;
  350. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  351. //worksheet.Cell(1, i++).Value = "BetId";
  352. if (list != null && list.Count > 0)
  353. {
  354. for (int index = 1; index <= list.Count; index++)
  355. {
  356. i = 1;
  357. var obj = list[index - 1];
  358. worksheet.Cell(index + 1, i++).Value = index;
  359. worksheet.Cell(index + 1, i++).Value = obj.name;
  360. worksheet.Cell(index + 1, i++).SetValue(obj.fromDate);
  361. worksheet.Cell(index + 1, i++).SetValue(obj.toDate);
  362. worksheet.Cell(index + 1, i++).Value = obj.isDefault == "1" ? "Default" : "Normal";
  363. worksheet.Cell(index + 1, i++).Value = (int.Parse(obj.addType) - 1) + "-Verification";
  364. string services = "";
  365. if (obj.listServiceMapCam != null)
  366. {
  367. foreach (var sv in obj.listServiceMapCam)
  368. {
  369. services += @sv.serviceObj.name + "; ";
  370. }
  371. if (services.Length > 2)
  372. {
  373. services = services.Substring(0, services.Length - 2);
  374. }
  375. }
  376. worksheet.Cell(index + 1, i++).Value = services;
  377. worksheet.Cell(index + 1, i++).Value = obj.priority;
  378. worksheet.Cell(index + 1, i++).SetValue(obj.dateUpdate);
  379. worksheet.Cell(index + 1, i++).Value = CommonUtils.StatusToStr(obj.status);
  380. }
  381. }
  382. using (var stream = new MemoryStream())
  383. {
  384. workbook.SaveAs(stream);
  385. var content = stream.ToArray();
  386. return File(content, contentType, fileName);
  387. }
  388. }
  389. }
  390. catch (Exception ex)
  391. {
  392. return null;
  393. }
  394. }
  395. [HttpPost]
  396. public JsonResult CampaignClone(CampaignCopyReq request)
  397. {
  398. if (!CheckAuthToken())
  399. {
  400. return Json(new
  401. {
  402. error = "-1",
  403. content = "Login first"
  404. });
  405. }
  406. string account = HttpContext.Session.GetString("account");
  407. request.users = account;
  408. // send change status
  409. string url = GetParameter(CommonUtils.WsType.camCopy);
  410. var res = CommonRes.Parse(SendPost(request, url));
  411. return Json(new
  412. {
  413. error = res.responseCode,
  414. content = res.responseMessage
  415. });
  416. }
  417. [HttpPost]
  418. public IActionResult CampaignLoadInfo(CampaignGetListReq request)
  419. {
  420. if (!CheckAuthToken())
  421. {
  422. return Json(new
  423. {
  424. error = "-1",
  425. content = "Login first"
  426. });
  427. }
  428. string account = HttpContext.Session.GetString("account");
  429. // check update or add
  430. string url = GetParameter(CommonUtils.WsType.CamGetList);
  431. var res = CampaignGetListRes.Parse(SendPost(request, url));
  432. if (res.responseCode == "0")
  433. {
  434. return PartialView("../Partial/_Campaign", res.list[0]);
  435. }
  436. else
  437. {
  438. return Json(new
  439. {
  440. error = res.responseCode,
  441. content = res.responseMessage
  442. });
  443. }
  444. }
  445. [HttpPost]
  446. public JsonResult CampaignAddUpdate(CampaignAddUpdateObj campAddUpdateObj)
  447. {
  448. if (!CheckAuthToken())
  449. {
  450. return Json(new
  451. {
  452. error = "-1",
  453. content = "Login first"
  454. });
  455. }
  456. string account = HttpContext.Session.GetString("account");
  457. string errorContent = "";
  458. // check update or add
  459. string url = "";
  460. if (campAddUpdateObj.campReq.id == null || campAddUpdateObj.campReq.id == "")
  461. {
  462. url = GetParameter(CommonUtils.WsType.CamInsert);
  463. }
  464. else
  465. {
  466. url = GetParameter(CommonUtils.WsType.CamUpdate);
  467. }
  468. campAddUpdateObj.campReq.users = account;
  469. campAddUpdateObj.campReq.type = "0";
  470. //campAddUpdateObj.campReq.status = CampaignStatus.draft;
  471. var res = CampaignInsertRes.Parse(SendPost(campAddUpdateObj.campReq, url));
  472. if (res.responseCode == "0")
  473. {
  474. // create campaign success -> add service to campaign
  475. string campId = campAddUpdateObj.campReq.id;
  476. if (campId == null || campId == "")
  477. {
  478. campId = res.id;
  479. }
  480. // get info to remove
  481. if (campAddUpdateObj.campReq.id != null && campAddUpdateObj.campReq.id != "")
  482. {
  483. // remove service
  484. url = GetParameter(CommonUtils.WsType.CamGetList);
  485. CampaignGetListReq getCamReq = new CampaignGetListReq();
  486. getCamReq.id = campAddUpdateObj.campReq.id;
  487. var camInfo = CampaignGetListRes.Parse(SendPost(getCamReq, url)).list[0];
  488. if (camInfo.listServiceMapCam != null)
  489. {
  490. url = GetParameter(CommonUtils.WsType.CamSvRemove);
  491. CamServiceAddReq svRemoveReq = new CamServiceAddReq();
  492. svRemoveReq.type = "1";
  493. foreach (var oldSv in camInfo.listServiceMapCam)
  494. {
  495. svRemoveReq.id = oldSv.id;
  496. SendPost(svRemoveReq, url);
  497. }
  498. }
  499. // remove criteria
  500. CriteriaMapCamReq criRemoveReq = new CriteriaMapCamReq();
  501. criRemoveReq.type = "1";
  502. url = GetParameter(CommonUtils.WsType.camBalanceUpdate);
  503. foreach (var oldSv in camInfo.listBalanceMapCam)
  504. {
  505. criRemoveReq.id = oldSv.id;
  506. SendPost(criRemoveReq, url);
  507. }
  508. url = GetParameter(CommonUtils.WsType.camSubUpdate);
  509. foreach (var oldSv in camInfo.listSubMapCam)
  510. {
  511. criRemoveReq.id = oldSv.id;
  512. SendPost(criRemoveReq, url);
  513. }
  514. url = GetParameter(CommonUtils.WsType.camExpireUpdate);
  515. foreach (var oldSv in camInfo.listExpireMapCam)
  516. {
  517. criRemoveReq.id = oldSv.id;
  518. SendPost(criRemoveReq, url);
  519. }
  520. url = GetParameter(CommonUtils.WsType.camShortCodeUpdate);
  521. foreach (var oldSv in camInfo.listShortCodeMapCam)
  522. {
  523. criRemoveReq.id = oldSv.id;
  524. SendPost(criRemoveReq, url);
  525. }
  526. }
  527. // remove old services
  528. //CampaignServiceListReq listSvReq = new CampaignServiceListReq();
  529. //listSvReq.campaignId = campId;
  530. //listSvReq.rowsOnPage = "1000000";
  531. //listSvReq.seqPage = "1";
  532. //url = GetParameter(CommonUtils.WsType.CamSvGetList);
  533. //var listSvRes = CampaignServiceListRes.Parse(SendPost(listSvReq, url));
  534. //if (listSvRes.list != null)
  535. //{
  536. // url = GetParameter(CommonUtils.WsType.CamSvRemove);
  537. // CamServiceAddReq svRemoveReq = new CamServiceAddReq();
  538. // svRemoveReq.type = "1";
  539. // foreach (var oldSv in listSvRes.list)
  540. // {
  541. // svRemoveReq.id = oldSv.id;
  542. // SendPost(svRemoveReq, url);
  543. // }
  544. //}
  545. // add new services
  546. if (campAddUpdateObj.listCampSv != null)
  547. {
  548. url = GetParameter(CommonUtils.WsType.CamAddInsert);
  549. foreach (var campSv in campAddUpdateObj.listCampSv)
  550. {
  551. campSv.users = account;
  552. campSv.campaignId = campId;
  553. var resAdd = CommonRes.Parse(SendPost(campSv, url));
  554. if (resAdd.responseCode != "0")
  555. {
  556. errorContent += "<br />" + "Error add service " + campSv.note + ": " + resAdd.responseMessage;
  557. }
  558. }
  559. }
  560. // add balances
  561. if (campAddUpdateObj.balances != null)
  562. {
  563. url = GetParameter(CommonUtils.WsType.camBalanceInsert);
  564. foreach (var campCri in campAddUpdateObj.balances)
  565. {
  566. campCri.users = account;
  567. campCri.campaignId = campId;
  568. var resAdd = CommonRes.Parse(SendPost(campCri, url));
  569. if (resAdd.responseCode != "0")
  570. {
  571. errorContent += "<br />" + "Error add criteria " + campCri.note + ": " + resAdd.responseMessage;
  572. }
  573. }
  574. }
  575. // add expires
  576. if (campAddUpdateObj.expires != null)
  577. {
  578. url = GetParameter(CommonUtils.WsType.camExpireInsert);
  579. foreach (var campCri in campAddUpdateObj.expires)
  580. {
  581. campCri.users = account;
  582. campCri.campaignId = campId;
  583. var resAdd = CommonRes.Parse(SendPost(campCri, url));
  584. if (resAdd.responseCode != "0")
  585. {
  586. errorContent += "<br />" + "Error add criteria " + campCri.note + ": " + resAdd.responseMessage;
  587. }
  588. }
  589. }
  590. // add shortcode
  591. url = GetParameter(CommonUtils.WsType.camShortCodeInsert);
  592. CriteriaMapCamReq camShortCode = new CriteriaMapCamReq();
  593. camShortCode.users = account;
  594. camShortCode.campaignId = campId;
  595. camShortCode.shortCodeId = campAddUpdateObj.shortCodeId;
  596. var resAdd2 = CommonRes.Parse(SendPost(camShortCode, url));
  597. if (resAdd2.responseCode != "0")
  598. {
  599. errorContent += "<br />" + "Error add shortcode " + camShortCode.note + ": " + resAdd2.responseMessage;
  600. }
  601. // add list sub
  602. if (campAddUpdateObj.listSubs != null)
  603. {
  604. url = GetParameter(CommonUtils.WsType.camSubInsert);
  605. foreach (var campCri in campAddUpdateObj.listSubs)
  606. {
  607. campCri.users = account;
  608. campCri.campaignId = campId;
  609. var resAdd = CommonRes.Parse(SendPost(campCri, url));
  610. if (resAdd.responseCode != "0")
  611. {
  612. errorContent += "<br />" + "Error add sub " + campCri.note + ": " + resAdd.responseMessage;
  613. }
  614. }
  615. }
  616. // check result
  617. if (errorContent != "")
  618. {
  619. return Json(new
  620. {
  621. error = res.responseCode,
  622. warning = "1",
  623. campId = campId,
  624. content = "Create campaign success with warning:" + errorContent
  625. });
  626. }
  627. else
  628. {
  629. return Json(new
  630. {
  631. error = res.responseCode,
  632. content = res.responseMessage
  633. });
  634. }
  635. }
  636. else
  637. {
  638. return Json(new
  639. {
  640. error = res.responseCode,
  641. content = res.responseMessage
  642. });
  643. }
  644. }
  645. // ApiWebserviceManagement
  646. public IActionResult ApiWebserviceManagement()
  647. {
  648. if (!CheckAuthToken())
  649. {
  650. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  651. }
  652. return View();
  653. }
  654. [HttpPost]
  655. public IActionResult GetApiServices()
  656. {
  657. if (!CheckAuthToken())
  658. {
  659. return Json(new
  660. {
  661. error = "-1",
  662. content = "Login first"
  663. });
  664. }
  665. var req = new ApiServiceReq
  666. {
  667. rowsOnPage = "1000000",
  668. seqPage = "1",
  669. order = "desc"
  670. };
  671. string url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
  672. ApiServiceRes res = ApiServiceRes.Parse(SendPost(req, url));
  673. if (res == null || res.list == null)
  674. {
  675. return Json(new
  676. {
  677. error = "1",
  678. content = "No data found"
  679. });
  680. }
  681. return Json(new
  682. {
  683. error = 0,
  684. data = res.list
  685. });
  686. }
  687. public IActionResult ApiServiceSearch(ApiServiceReq req)
  688. {
  689. if (!CheckAuthToken())
  690. {
  691. return Json(new
  692. {
  693. error = "-1",
  694. content = "Login first"
  695. });
  696. }
  697. req.rowsOnPage = "1000000";
  698. req.seqPage = "1";
  699. req.order = "desc";
  700. String url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
  701. ApiServiceRes res = ApiServiceRes.Parse(SendPost(req, url));
  702. HttpContext.Session.SetComplexData("apiServiceData", res.list);
  703. return PartialView("../Partial/_ApiWebserviceManagement", res.list);
  704. }
  705. [HttpPost]
  706. public IActionResult ApiServiceExport(ApiServiceReq req)
  707. {
  708. if (!CheckAuthToken())
  709. {
  710. return null;
  711. }
  712. // Ensure same paging/order behavior as search
  713. req.rowsOnPage = "1000000";
  714. req.seqPage = "1";
  715. req.order = "desc";
  716. string url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
  717. ApiServiceRes res = ApiServiceRes.Parse(SendPost(req, url));
  718. var list = res.list ?? new List<ApiService>();
  719. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  720. string fileName = "api_services.xlsx";
  721. try
  722. {
  723. using (var workbook = new XLWorkbook())
  724. {
  725. int i = 1;
  726. IXLWorksheet worksheet = workbook.Worksheets.Add("API Services");
  727. worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "No.";
  728. worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "ID";
  729. worksheet.Column(i).Width = 30; worksheet.Cell(1, i++).Value = "ws_name";
  730. worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "ws_code";
  731. worksheet.Column(i).Width = 50; worksheet.Cell(1, i++).Value = "wsdl";
  732. worksheet.Column(i).Width = 40; worksheet.Cell(1, i++).Value = "msg_template";
  733. worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "error_tag";
  734. worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "success_code";
  735. worksheet.Column(i).Width = 12; worksheet.Cell(1, i++).Value = "Status";
  736. worksheet.Row(1).Style.Font.Bold = true;
  737. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  738. if (list.Count > 0)
  739. {
  740. for (int index = 1; index <= list.Count; index++)
  741. {
  742. i = 1;
  743. var obj = list[index - 1];
  744. worksheet.Cell(index + 1, i++).Value = index;
  745. worksheet.Cell(index + 1, i++).Value = obj.ws_id;
  746. worksheet.Cell(index + 1, i++).Value = obj.ws_name;
  747. worksheet.Cell(index + 1, i++).Value = obj.ws_code;
  748. worksheet.Cell(index + 1, i++).Value = obj.wsdl;
  749. worksheet.Cell(index + 1, i++).Value = obj.msg_template;
  750. worksheet.Cell(index + 1, i++).Value = obj.error_tag;
  751. worksheet.Cell(index + 1, i++).Value = obj.success_code;
  752. worksheet.Cell(index + 1, i++).Value = obj.isActive == "1" ? "Active" : "Inactive";
  753. }
  754. }
  755. using (var stream = new MemoryStream())
  756. {
  757. workbook.SaveAs(stream);
  758. var content = stream.ToArray();
  759. return File(content, contentType, fileName);
  760. }
  761. }
  762. }
  763. catch (Exception)
  764. {
  765. return null;
  766. }
  767. }
  768. [HttpPost]
  769. public JsonResult ApiServiceLoadInfo(ApiServiceReq request)
  770. {
  771. if (!CheckAuthToken())
  772. {
  773. return Json(new
  774. {
  775. error = "-1",
  776. content = "Login first"
  777. });
  778. }
  779. string account = HttpContext.Session.GetString("account");
  780. // check update or add
  781. string url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
  782. var res = ApiServiceRes.Parse(SendPost(request, url));
  783. return Json(new
  784. {
  785. error = res.responseCode,
  786. content = res.responseMessage,
  787. data = res.list[0]
  788. });
  789. }
  790. [HttpPost]
  791. public JsonResult ApiServiceAddUpdate(ApiServiceUpdateReq request)
  792. {
  793. if (!CheckAuthToken())
  794. {
  795. return Json(new
  796. {
  797. error = "-1",
  798. content = "Login first"
  799. });
  800. }
  801. string account = HttpContext.Session.GetString("account");
  802. // check update or add
  803. string url = "";
  804. if (request.id != null)
  805. {
  806. url = GetParameter(CommonUtils.WsType.ApiServiceUpdate);
  807. }
  808. else
  809. {
  810. // add
  811. url = GetParameter(CommonUtils.WsType.ApiServiceInsert);
  812. }
  813. request.users = account;
  814. var res = ApiServiceUpdateRes.Parse(SendPost(request, url));
  815. // reload
  816. PreLoadService();
  817. return Json(new
  818. {
  819. error = res.responseCode,
  820. content = res.responseMessage
  821. });
  822. }
  823. // SERVICE
  824. public IActionResult ServiceManagement()
  825. {
  826. if (!CheckAuthToken())
  827. {
  828. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  829. }
  830. return View();
  831. }
  832. public IActionResult ServiceSearch(ServiceGetListReq req)
  833. {
  834. if (!CheckAuthToken())
  835. {
  836. return Json(new
  837. {
  838. error = "-1",
  839. content = "Login first"
  840. });
  841. }
  842. req.rowsOnPage = "1000000";
  843. req.seqPage = "1";
  844. req.order = "desc";
  845. String url = GetParameter(CommonUtils.WsType.SvGetList);
  846. ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
  847. HttpContext.Session.SetComplexData("listService", res.list);
  848. return PartialView("../Partial/_Services", res.list);
  849. }
  850. [HttpPost]
  851. public JsonResult ServiceLoadInfo(ServiceGetListReq request)
  852. {
  853. if (!CheckAuthToken())
  854. {
  855. return Json(new
  856. {
  857. error = "-1",
  858. content = "Login first"
  859. });
  860. }
  861. string account = HttpContext.Session.GetString("account");
  862. // check update or add
  863. string url = GetParameter(CommonUtils.WsType.SvGetList);
  864. var res = ServiceGetListRes.Parse(SendPost(request, url));
  865. return Json(new
  866. {
  867. error = res.responseCode,
  868. content = res.responseMessage,
  869. data = res.list[0]
  870. });
  871. }
  872. [HttpPost]
  873. public JsonResult ServiceAddUpdate(ServiceUpdateReq request)
  874. {
  875. if (!CheckAuthToken())
  876. {
  877. return Json(new
  878. {
  879. error = "-1",
  880. content = "Login first"
  881. });
  882. }
  883. string account = HttpContext.Session.GetString("account");
  884. // check update or add
  885. string url = "";
  886. if (request.id != null)
  887. {
  888. url = GetParameter(CommonUtils.WsType.SvUpdate);
  889. }
  890. else
  891. {
  892. // add
  893. url = GetParameter(CommonUtils.WsType.SvInsert);
  894. }
  895. request.users = account;
  896. var res = ServiceUpdateRes.Parse(SendPost(request, url));
  897. // reload
  898. PreLoadService();
  899. return Json(new
  900. {
  901. error = res.responseCode,
  902. content = res.responseMessage
  903. });
  904. }
  905. // SERVICE
  906. public IActionResult CampaignScheduler()
  907. {
  908. if (!CheckAuthToken())
  909. {
  910. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  911. }
  912. return View();
  913. }
  914. public IActionResult SchedulerSearch(CalendarGetListReq req, string viewType = "calendar")
  915. {
  916. if (!CheckAuthToken())
  917. {
  918. return Json(new
  919. {
  920. error = "-1",
  921. content = "Login first"
  922. });
  923. }
  924. String url = GetParameter(CommonUtils.WsType.CalendarGetList);
  925. CalendarGetListRes res = CalendarGetListRes.Parse(SendPost(req, url));
  926. string viewName = viewType == "table" ? "../Partial/_CampaignSchedulerTable" : "../Partial/_CampaignSchedulerCalendar";
  927. return PartialView(viewName, res.list);
  928. }
  929. [HttpPost]
  930. public IActionResult SchedulerExport(CalendarGetListReq req)
  931. {
  932. if (!CheckAuthToken())
  933. {
  934. return null;
  935. }
  936. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  937. String url = GetParameter(CommonUtils.WsType.CalendarGetList);
  938. CalendarGetListRes res = CalendarGetListRes.Parse(SendPost(req, url));
  939. var list = res.list;
  940. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  941. string fileName = "calendar.xlsx";
  942. try
  943. {
  944. using (var workbook = new XLWorkbook())
  945. {
  946. int i = 1;
  947. IXLWorksheet worksheet = workbook.Worksheets.Add("Scheduler");
  948. worksheet.Column(i).Width = 15;
  949. worksheet.Cell(1, i++).Value = "No.";
  950. worksheet.Column(i).Width = 20;
  951. worksheet.Cell(1, i++).Value = "Date";
  952. worksheet.Column(i).Width = 15;
  953. worksheet.Cell(1, i++).Value = "ID";
  954. worksheet.Column(i).Width = 30;
  955. worksheet.Cell(1, i++).Value = "Campaign Name";
  956. worksheet.Column(i).Width = 15;
  957. worksheet.Cell(1, i++).Value = "Campaign Type";
  958. worksheet.Column(i).Width = 20;
  959. worksheet.Cell(1, i++).Value = "Start Date";
  960. worksheet.Column(i).Width = 20;
  961. worksheet.Cell(1, i++).Value = "End Date";
  962. worksheet.Column(i).Width = 20;
  963. worksheet.Cell(1, i++).Value = "Services";
  964. worksheet.Column(i).Width = 15;
  965. worksheet.Cell(1, i++).Value = "Status";
  966. // make color
  967. worksheet.Row(1).Style.Font.Bold = true;
  968. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  969. //worksheet.Cell(1, i++).Value = "BetId";
  970. if (list != null && list.Count > 0)
  971. {
  972. int rownum = 1;
  973. for (int index = 1; index <= list.Count; index++)
  974. {
  975. var calendar = list[index - 1];
  976. if (calendar.list == null || calendar.list.Count == 0)
  977. {
  978. i = 1;
  979. rownum++;
  980. worksheet.Cell(rownum, i++).Value = rownum-1;
  981. worksheet.Cell(rownum, i++).SetValue(calendar.date);
  982. }
  983. else
  984. {
  985. for (int j = 0; j < calendar.list.Count; j++)
  986. {
  987. i = 1;
  988. rownum++;
  989. var obj = calendar.list[j];
  990. worksheet.Cell(rownum, i++).Value = rownum-1;
  991. if (j == 0)
  992. {
  993. // merge cell
  994. worksheet.Range($"B{rownum}:B{rownum + calendar.list.Count - 1}").Merge();
  995. worksheet.Cell(rownum, i).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
  996. worksheet.Cell(rownum, i++).SetValue(calendar.date);
  997. } else
  998. {
  999. i++;
  1000. }
  1001. worksheet.Cell(rownum, i++).Value = obj.id;
  1002. worksheet.Cell(rownum, i++).Value = obj.name;
  1003. worksheet.Cell(rownum, i++).Value = obj.isDefault == "1" ? "Default" : "Normal";
  1004. worksheet.Cell(rownum, i++).SetValue(obj.fromDate);
  1005. worksheet.Cell(rownum, i++).SetValue(obj.toDate);
  1006. string services = "";
  1007. if (obj.listServiceMapCam != null)
  1008. {
  1009. foreach (var sv in obj.listServiceMapCam)
  1010. {
  1011. services += @sv.serviceObj.name + "; ";
  1012. }
  1013. if (services.Length > 2)
  1014. {
  1015. services = services.Substring(0, services.Length - 2);
  1016. }
  1017. }
  1018. worksheet.Cell(rownum, i++).Value = services;
  1019. worksheet.Cell(rownum, i++).Value = CommonUtils.StatusToStr(obj.status);
  1020. }
  1021. }
  1022. }
  1023. }
  1024. using (var stream = new MemoryStream())
  1025. {
  1026. workbook.SaveAs(stream);
  1027. var content = stream.ToArray();
  1028. return File(content, contentType, fileName);
  1029. }
  1030. }
  1031. }
  1032. catch (Exception ex)
  1033. {
  1034. return null;
  1035. }
  1036. }
  1037. // COMMON
  1038. [HttpPost]
  1039. public JsonResult ChangeStatus(ChangeStatusReq request)
  1040. {
  1041. if (!CheckAuthToken())
  1042. {
  1043. return Json(new
  1044. {
  1045. error = "-1",
  1046. content = "Login first"
  1047. });
  1048. }
  1049. string account = HttpContext.Session.GetString("account");
  1050. request.users = account;
  1051. // send change status
  1052. string url = GetParameter(CommonUtils.WsType.changeStatus);
  1053. var res = CommonRes.Parse(SendPost(request, url));
  1054. // reload
  1055. if (request.type == CommonUtils.ActionType.Service)
  1056. {
  1057. PreLoadService();
  1058. }
  1059. return Json(new
  1060. {
  1061. error = res.responseCode,
  1062. content = res.responseMessage
  1063. });
  1064. }
  1065. [HttpPost]
  1066. public IActionResult ServiceExport(ServiceGetListReq req)
  1067. {
  1068. if (!CheckAuthToken())
  1069. {
  1070. return null;
  1071. }
  1072. try
  1073. {
  1074. // Initialize req if null
  1075. if (req == null)
  1076. {
  1077. req = new ServiceGetListReq();
  1078. }
  1079. // Set pagination to get all records, same as ServiceSearch
  1080. req.rowsOnPage = "1000000";
  1081. req.seqPage = "1";
  1082. req.order = "desc";
  1083. String url = GetParameter(CommonUtils.WsType.SvGetList);
  1084. ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
  1085. var list = res.list ?? new List<Service>();
  1086. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  1087. string fileName = "services.xlsx";
  1088. using (var workbook = new XLWorkbook())
  1089. {
  1090. int i = 1;
  1091. IXLWorksheet worksheet = workbook.Worksheets.Add("Services");
  1092. worksheet.Column(i).Width = 15;
  1093. worksheet.Cell(1, i++).Value = "No.";
  1094. worksheet.Column(i).Width = 20;
  1095. worksheet.Cell(1, i++).Value = "Name";
  1096. worksheet.Column(i).Width = 15;
  1097. worksheet.Cell(1, i++).Value = "Short code";
  1098. worksheet.Column(i).Width = 20;
  1099. worksheet.Cell(1, i++).Value = "Command";
  1100. worksheet.Column(i).Width = 20;
  1101. worksheet.Cell(1, i++).Value = "Description";
  1102. worksheet.Column(i).Width = 20;
  1103. worksheet.Cell(1, i++).Value = "Created date";
  1104. worksheet.Column(i).Width = 50;
  1105. worksheet.Cell(1, i++).Value = "Message USSD return success";
  1106. worksheet.Column(i).Width = 50;
  1107. worksheet.Cell(1, i++).Value = "Message USSD return failed";
  1108. // make color
  1109. worksheet.Row(1).Style.Font.Bold = true;
  1110. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  1111. //worksheet.Cell(1, i++).Value = "BetId";
  1112. if (list != null && list.Count > 0)
  1113. {
  1114. for (int index = 1; index <= list.Count; index++)
  1115. {
  1116. i = 1;
  1117. var obj = list[index - 1];
  1118. worksheet.Cell(index + 1, i++).Value = index;
  1119. worksheet.Cell(index + 1, i++).Value = obj.name ?? "";
  1120. worksheet.Cell(index + 1, i++).Value = obj.shortCode ?? "";
  1121. worksheet.Cell(index + 1, i++).Value = obj.command ?? "";
  1122. worksheet.Cell(index + 1, i++).Value = obj.description ?? "";
  1123. worksheet.Cell(index + 1, i++).Value = obj.dateCreated ?? "";
  1124. worksheet.Cell(index + 1, i++).Value = obj.msgRegisterSuccess ?? "";
  1125. worksheet.Cell(index + 1, i++).Value = obj.msgRegisterFlase ?? "";
  1126. }
  1127. }
  1128. using (var stream = new MemoryStream())
  1129. {
  1130. workbook.SaveAs(stream);
  1131. var content = stream.ToArray();
  1132. return File(content, contentType, fileName);
  1133. }
  1134. }
  1135. }
  1136. catch (Exception ex)
  1137. {
  1138. log.Error("Error in ServiceExport: " + ex.Message, ex);
  1139. return null;
  1140. }
  1141. }
  1142. [HttpPost]
  1143. public IActionResult CampaignService(CampaignServiceListReq req)
  1144. {
  1145. if (!CheckAuthToken())
  1146. {
  1147. return PartialView("../Partial/_CampaignService", null);
  1148. }
  1149. if (req.rowsOnPage == null)
  1150. {
  1151. req.rowsOnPage = "1000000";
  1152. req.seqPage = "1";
  1153. req.order = "asc";
  1154. String url = GetParameter(CommonUtils.WsType.CamSvGetList);
  1155. CampaignServiceListRes res = CampaignServiceListRes.Parse(SendPost(req, url));
  1156. return PartialView("../Partial/_CampaignService", res.list);
  1157. }
  1158. else
  1159. {
  1160. ViewBag.nextIndex = req.rowsOnPage;
  1161. return PartialView("../Partial/_CampaignService", null);
  1162. }
  1163. }
  1164. [HttpPost]
  1165. public IActionResult SvGroup(ServiceGroupReq req)
  1166. {
  1167. if (!CheckAuthToken())
  1168. {
  1169. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  1170. }
  1171. string url = GetParameter(CommonUtils.WsType.SvGroupGetList);
  1172. ServiceGroupRes res = ServiceGroupRes.Parse(SendPost(req, url));
  1173. HttpContext.Session.SetComplexData("serviceGroupData", res.list);
  1174. return Json(new { success = true });
  1175. }
  1176. [HttpPost]
  1177. public IActionResult SvGroupLoad(ServiceGroupReq req)
  1178. {
  1179. if (!CheckAuthToken())
  1180. {
  1181. return Json(new
  1182. {
  1183. error = "-1",
  1184. content = "Login first"
  1185. });
  1186. }
  1187. string url = GetParameter(CommonUtils.WsType.SvGroupGetList);
  1188. ServiceGroupRes res = ServiceGroupRes.Parse(SendPost(req, url));
  1189. if (res == null || res.list == null)
  1190. {
  1191. return Json(new
  1192. {
  1193. error = "1",
  1194. content = "No data found"
  1195. });
  1196. }
  1197. return Json(new
  1198. {
  1199. error = 0,
  1200. data = res.list
  1201. });
  1202. }
  1203. // ReportCampaign
  1204. public IActionResult ReportCampaign()
  1205. {
  1206. if (!CheckAuthToken())
  1207. {
  1208. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  1209. }
  1210. return View();
  1211. }
  1212. [HttpPost]
  1213. public IActionResult ReportCampaignSearch(RpByCampaignReq req)
  1214. {
  1215. if (!CheckAuthToken())
  1216. {
  1217. return Json(new
  1218. {
  1219. error = "-1",
  1220. content = "Login first"
  1221. });
  1222. }
  1223. string url = GetParameter(CommonUtils.WsType.ReportByCampaign);
  1224. string result = SendPost(req, url);
  1225. RpByCampaignRes res = RpByCampaignRes.Parse(result);
  1226. return PartialView("../Partial/_ReportCampaign", res.list);
  1227. }
  1228. [HttpPost]
  1229. public IActionResult ReportCampaignExport(RpByCampaignReq req)
  1230. {
  1231. if (!CheckAuthToken())
  1232. {
  1233. return null;
  1234. }
  1235. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  1236. string url = GetParameter(CommonUtils.WsType.ReportByCampaign);
  1237. string result = SendPost(req, url);
  1238. RpByCampaignRes res = RpByCampaignRes.Parse(result);
  1239. List<RpByCampaign> list = res.list;
  1240. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  1241. string fileName = "report_campaign.xlsx";
  1242. try
  1243. {
  1244. using (var workbook = new XLWorkbook())
  1245. {
  1246. int i = 1;
  1247. IXLWorksheet worksheet = workbook.Worksheets.Add("Report Campaign");
  1248. worksheet.Column(i).Width = 15;
  1249. worksheet.Cell(1, i++).Value = "No.";
  1250. worksheet.Column(i).Width = 15;
  1251. worksheet.Cell(1, i++).Value = "ID";
  1252. worksheet.Column(i).Width = 30;
  1253. worksheet.Cell(1, i++).Value = "Name";
  1254. worksheet.Column(i).Width = 15;
  1255. worksheet.Cell(1, i++).Value = "Priority";
  1256. worksheet.Column(i).Width = 15;
  1257. worksheet.Cell(1, i++).Value = "Campaign Type";
  1258. worksheet.Column(i).Width = 15;
  1259. worksheet.Cell(1, i++).Value = "Service Type";
  1260. worksheet.Column(i).Width = 20;
  1261. worksheet.Cell(1, i++).Value = "Service Name";
  1262. worksheet.Column(i).Width = 15;
  1263. worksheet.Cell(1, i++).Value = "Total Send 1";
  1264. worksheet.Column(i).Width = 15;
  1265. worksheet.Cell(1, i++).Value = "Total press 1 of send 1";
  1266. worksheet.Column(i).Width = 15;
  1267. worksheet.Cell(1, i++).Value = "Total Send 2";
  1268. worksheet.Column(i).Width = 15;
  1269. worksheet.Cell(1, i++).Value = "Total press 1 of send 2";
  1270. worksheet.Column(i).Width = 15;
  1271. worksheet.Cell(1, i++).Value = "Total Success";
  1272. worksheet.Column(i).Width = 15;
  1273. worksheet.Cell(1, i++).Value = "Total Failed";
  1274. // make color
  1275. worksheet.Row(1).Style.Font.Bold = true;
  1276. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  1277. //worksheet.Cell(1, i++).Value = "BetId";
  1278. if (list != null && list.Count > 0)
  1279. {
  1280. for (int index = 1; index <= list.Count; index++)
  1281. {
  1282. i = 1;
  1283. var obj = list[index - 1];
  1284. worksheet.Cell(index + 1, i++).Value = index;
  1285. worksheet.Cell(index + 1, i++).Value = obj.campaignId;
  1286. worksheet.Cell(index + 1, i++).Value = obj.campaignName;
  1287. worksheet.Cell(index + 1, i++).Value = obj.priority;
  1288. worksheet.Cell(index + 1, i++).Value = obj.campaignType == "1" ? "Default" : "Normal";
  1289. worksheet.Cell(index + 1, i++).Value = (int.Parse(obj.serviceType) - 1) + "-Verification";
  1290. worksheet.Cell(index + 1, i++).Value = obj.serviceName;
  1291. worksheet.Cell(index + 1, i++).Value = obj.totalView1;
  1292. worksheet.Cell(index + 1, i++).Value = obj.activation1;
  1293. worksheet.Cell(index + 1, i++).Value = obj.totalView2;
  1294. worksheet.Cell(index + 1, i++).Value = obj.activation2;
  1295. worksheet.Cell(index + 1, i++).Value = obj.success;
  1296. worksheet.Cell(index + 1, i++).Value = obj.fail;
  1297. }
  1298. }
  1299. using (var stream = new MemoryStream())
  1300. {
  1301. workbook.SaveAs(stream);
  1302. var content = stream.ToArray();
  1303. return File(content, contentType, fileName);
  1304. }
  1305. }
  1306. }
  1307. catch (Exception ex)
  1308. {
  1309. return null;
  1310. }
  1311. }
  1312. private String formatStatus(String status)
  1313. {
  1314. if (status == "0")
  1315. {
  1316. return "Processing";
  1317. }
  1318. else if (status == "1")
  1319. {
  1320. return "Success";
  1321. }
  1322. else if (status == "2")
  1323. {
  1324. return "Pending";
  1325. }
  1326. else if (status == "3")
  1327. {
  1328. return "Revert";
  1329. }
  1330. return status;
  1331. }
  1332. private void PreLoadService()
  1333. {
  1334. try
  1335. {
  1336. ServiceGetListReq req = new ServiceGetListReq();
  1337. req.isActive = "1";
  1338. req.rowsOnPage = "20000";
  1339. req.seqPage = "1";
  1340. String url = GetParameter(CommonUtils.WsType.SvGetList);
  1341. ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
  1342. HttpContext.Session.SetComplexData("listService", res.list);
  1343. }
  1344. catch (Exception ex)
  1345. {
  1346. log.Error("Error load service: ", ex);
  1347. }
  1348. }
  1349. // List import
  1350. public IActionResult ListMsisdn()
  1351. {
  1352. if (!CheckAuthToken())
  1353. {
  1354. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  1355. }
  1356. CampaignGetListReq req = new CampaignGetListReq();
  1357. req.rowsOnPage = "1000000";
  1358. req.seqPage = "1";
  1359. req.order = "desc";
  1360. String url = GetParameter(CommonUtils.WsType.CamGetList);
  1361. CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
  1362. HttpContext.Session.SetComplexData("listCampaign", res.list);
  1363. return View();
  1364. }
  1365. public IActionResult ListMsisdnSearch(ListMsisdnGetReq req)
  1366. {
  1367. if (!CheckAuthToken())
  1368. {
  1369. return Json(new
  1370. {
  1371. error = "-1",
  1372. content = "Login first"
  1373. });
  1374. }
  1375. //string account = HttpContext.Session.GetString("account");
  1376. //req.users = account;
  1377. req.msisdn = BaseController.ValidateMsisdn(req.msisdn);
  1378. string url = GetParameter(CommonUtils.WsType.MsisdnSearch);
  1379. string result = SendPost(req, url);
  1380. ListMsisdnGetRes res = ListMsisdnGetRes.Parse(result);
  1381. return PartialView("../Partial/_ListMsisdn", res);
  1382. //return Json(new
  1383. //{
  1384. // error = res.responseCode,
  1385. // content = res.responseMessage,
  1386. // data = res.list
  1387. //});
  1388. }
  1389. [HttpPost]
  1390. public IActionResult ListMsisdnExport(ListMsisdnGetReq req)
  1391. {
  1392. if (!CheckAuthToken())
  1393. {
  1394. return null;
  1395. }
  1396. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  1397. string url = GetParameter(CommonUtils.WsType.MsisdnSearch);
  1398. string result = SendPost(req, url);
  1399. ListMsisdnGetRes res = ListMsisdnGetRes.Parse(result);
  1400. List<MsisdnList> list = res.list;
  1401. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  1402. string fileName = "player_list.xlsx";
  1403. try
  1404. {
  1405. using (var workbook = new XLWorkbook())
  1406. {
  1407. int i = 1;
  1408. IXLWorksheet worksheet = workbook.Worksheets.Add("Player List");
  1409. worksheet.Column(i).Width = 15;
  1410. worksheet.Cell(1, i++).Value = "No.";
  1411. worksheet.Column(i).Width = 20;
  1412. worksheet.Cell(1, i++).Value = "Phone number";
  1413. worksheet.Column(i).Width = 15;
  1414. worksheet.Cell(1, i++).Value = "Type";
  1415. worksheet.Column(i).Width = 25;
  1416. worksheet.Cell(1, i++).Value = "Campaign";
  1417. worksheet.Column(i).Width = 20;
  1418. worksheet.Cell(1, i++).Value = "Import date";
  1419. // make color
  1420. worksheet.Row(1).Style.Font.Bold = true;
  1421. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  1422. //worksheet.Cell(1, i++).Value = "BetId";
  1423. if (list != null && list.Count > 0)
  1424. {
  1425. for (int index = 1; index <= list.Count; index++)
  1426. {
  1427. i = 1;
  1428. var obj = list[index - 1];
  1429. worksheet.Cell(index + 1, i++).Value = index;
  1430. worksheet.Cell(index + 1, i++).Value = obj.msisdn;
  1431. worksheet.Cell(index + 1, i++).Value = obj.type == "2" ? "Blacklist" : "Whitelist";
  1432. worksheet.Cell(index + 1, i++).Value = obj.campaignId == "-1" ? "All" : (obj.campaignId + " - " + obj.campaignName);
  1433. worksheet.Cell(index + 1, i++).Value = obj.sysdate;
  1434. }
  1435. }
  1436. using (var stream = new MemoryStream())
  1437. {
  1438. workbook.SaveAs(stream);
  1439. var content = stream.ToArray();
  1440. return File(content, contentType, fileName);
  1441. }
  1442. }
  1443. }
  1444. catch (Exception ex)
  1445. {
  1446. return null;
  1447. }
  1448. }
  1449. [HttpPost]
  1450. public JsonResult ListMsisdnRemove(ImportMsisdn request)
  1451. {
  1452. if (!CheckAuthToken())
  1453. {
  1454. return Json(new
  1455. {
  1456. error = "-1",
  1457. content = "Login first"
  1458. });
  1459. }
  1460. string account = HttpContext.Session.GetString("account");
  1461. // check update or add
  1462. string url = GetParameter(CommonUtils.WsType.MsisdnAddUpdate);
  1463. request.users = account;
  1464. var res = ServiceUpdateRes.Parse(SendPost(request, url));
  1465. return Json(new
  1466. {
  1467. error = res.responseCode,
  1468. content = res.responseMessage
  1469. });
  1470. }
  1471. [HttpPost]
  1472. public IActionResult ListMsisdnImport(ImportMsisdn req, IFormFile file_upload)
  1473. {
  1474. if (!CheckAuthToken())
  1475. {
  1476. return null;
  1477. }
  1478. //ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  1479. try
  1480. {
  1481. if (file_upload != null && (file_upload.FileName.EndsWith(".txt") || file_upload.FileName.EndsWith(".csv")))
  1482. {
  1483. String fileUpload = UploadedFile(file_upload, "import_msisdn");
  1484. if (fileUpload != "")
  1485. {
  1486. // import data
  1487. return importMsisdn(req, fileUpload);
  1488. }
  1489. else
  1490. {
  1491. return Json(new
  1492. {
  1493. error_code = UtilsController.Constant.FAILURE,
  1494. error_content = "Invalid file",
  1495. });
  1496. }
  1497. }
  1498. else
  1499. {
  1500. return Json(new
  1501. {
  1502. error_code = UtilsController.Constant.FAILURE,
  1503. error_content = "Import file invalid",
  1504. });
  1505. }
  1506. }
  1507. catch (Exception ex)
  1508. {
  1509. return Json(new
  1510. {
  1511. error_code = UtilsController.Constant.FAILURE,
  1512. error_content = "System failed!",
  1513. });
  1514. }
  1515. }
  1516. private JsonResult importMsisdn(ImportMsisdn req, String importFile)
  1517. {
  1518. using (StreamReader f = new StreamReader(importFile))
  1519. {
  1520. string account = HttpContext.Session.GetString("account");
  1521. req.users = account;
  1522. //
  1523. List<Datum> listMsisdn = new List<Datum>();
  1524. int ct = 0;
  1525. string ln;
  1526. while ((ln = f.ReadLine()) != null)
  1527. {
  1528. ct++;
  1529. listMsisdn.Add(new Datum(ValidateMsisdn(ln.Trim()), "1"));
  1530. }
  1531. f.Close();
  1532. req.data = listMsisdn;
  1533. // send request
  1534. string url = GetParameter(CommonUtils.WsType.MsisdnAddUpdate);
  1535. string result = SendPost(req, url);
  1536. CommonRes res = CommonRes.Parse(result);
  1537. //
  1538. listMsisdn.Clear();
  1539. return Json(new
  1540. {
  1541. error = res.responseCode,
  1542. content = res.responseMessage
  1543. });
  1544. }
  1545. }
  1546. // PARAM
  1547. public IActionResult ParamManagement()
  1548. {
  1549. return View();
  1550. }
  1551. public IActionResult ParamSearch(ParamGetListReq req)
  1552. {
  1553. if (!CheckAuthToken())
  1554. {
  1555. return Json(new
  1556. {
  1557. error = "-1",
  1558. content = "Login first"
  1559. });
  1560. }
  1561. String url = GetParameter(CommonUtils.WsType.ParamGetList);
  1562. ParamGetListRes res = ParamGetListRes.Parse(SendPost(req, url));
  1563. return PartialView("../Partial/_Params", res.list);
  1564. }
  1565. [HttpPost]
  1566. public JsonResult ParamLoadInfo(ParamGetListReq request)
  1567. {
  1568. if (!CheckAuthToken())
  1569. {
  1570. return Json(new
  1571. {
  1572. error = "-1",
  1573. content = "Login first"
  1574. });
  1575. }
  1576. string account = HttpContext.Session.GetString("account");
  1577. // check update or add
  1578. string url = GetParameter(CommonUtils.WsType.ParamGetList);
  1579. var res = ParamGetListRes.Parse(SendPost(request, url));
  1580. return Json(new
  1581. {
  1582. error = res.responseCode,
  1583. content = res.responseMessage,
  1584. data = res.list[0]
  1585. });
  1586. }
  1587. [HttpPost]
  1588. public JsonResult ParamAddUpdate(String id, String value, String note)
  1589. {
  1590. if (!CheckAuthToken())
  1591. {
  1592. return Json(new
  1593. {
  1594. error = "-1",
  1595. content = "Login first"
  1596. });
  1597. }
  1598. string account = HttpContext.Session.GetString("account");
  1599. // get param by id
  1600. string url = GetParameter(CommonUtils.WsType.ParamGetList);
  1601. ParamGetListReq req = new ParamGetListReq();
  1602. req.id = id;
  1603. ParamGetListRes cpRes = ParamGetListRes.Parse(SendPost(req, url));
  1604. var cmp = cpRes.list[0];
  1605. // update status
  1606. ParamUpdateReq updateReq = new ParamUpdateReq(cmp);
  1607. updateReq.values = value;
  1608. updateReq.note = note;
  1609. updateReq.users = account;
  1610. string result = SendPost(updateReq, GetParameter(CommonUtils.WsType.ParamUpdate));
  1611. CommonRes res = CommonRes.Parse(result);
  1612. return Json(new
  1613. {
  1614. error = res.responseCode,
  1615. content = res.responseMessage
  1616. });
  1617. }
  1618. public IActionResult Reload()
  1619. {
  1620. return View();
  1621. }
  1622. [HttpPost]
  1623. public JsonResult ReloadConfig(ReloadReq request)
  1624. {
  1625. if (!CheckAuthToken())
  1626. {
  1627. return Json(new
  1628. {
  1629. error = "-1",
  1630. content = "Login first"
  1631. });
  1632. }
  1633. string account = HttpContext.Session.GetString("account");
  1634. request.users = account;
  1635. // check update or add
  1636. string url = GetParameter(CommonUtils.WsType.ParamReload);
  1637. var res = ParamUpdateRes.Parse(SendPost(request, url));
  1638. return Json(new
  1639. {
  1640. error = res.responseCode,
  1641. content = res.responseMessage
  1642. });
  1643. }
  1644. // SERVICE UNDER
  1645. public IActionResult ServiceUnder()
  1646. {
  1647. // init
  1648. try
  1649. {
  1650. var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
  1651. if (listService == null)
  1652. {
  1653. PreLoadService();
  1654. }
  1655. }
  1656. catch (Exception ex)
  1657. {
  1658. PreLoadService();
  1659. }
  1660. return View();
  1661. }
  1662. public IActionResult ServiceUnderSearch(ServiceUnderGetListReq req)
  1663. {
  1664. if (!CheckAuthToken())
  1665. {
  1666. return Json(new
  1667. {
  1668. error = "-1",
  1669. content = "Login first"
  1670. });
  1671. }
  1672. String url = GetParameter(CommonUtils.WsType.SvGetList);
  1673. ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
  1674. return PartialView("../Partial/_ServicesUnder", res.list);
  1675. }
  1676. [HttpPost]
  1677. public JsonResult ServiceUnderLoadInfo(ServiceUnderGetListReq request)
  1678. {
  1679. if (!CheckAuthToken())
  1680. {
  1681. return Json(new
  1682. {
  1683. error = "-1",
  1684. content = "Login first"
  1685. });
  1686. }
  1687. string account = HttpContext.Session.GetString("account");
  1688. // check update or add
  1689. string url = GetParameter(CommonUtils.WsType.SvUnderGetList);
  1690. var res = ServiceUnderGetListRes.Parse(SendPost(request, url));
  1691. return Json(new
  1692. {
  1693. error = res.responseCode,
  1694. content = res.responseMessage,
  1695. data = res.list[0]
  1696. });
  1697. }
  1698. [HttpPost]
  1699. public JsonResult ServiceUnderAddUpdate(ServiceUnderUpdateReq request)
  1700. {
  1701. if (!CheckAuthToken())
  1702. {
  1703. return Json(new
  1704. {
  1705. error = "-1",
  1706. content = "Login first"
  1707. });
  1708. }
  1709. string account = HttpContext.Session.GetString("account");
  1710. // check update or add
  1711. string url = "";
  1712. if (request.id != null)
  1713. {
  1714. url = GetParameter(CommonUtils.WsType.SvUnderUpdate);
  1715. }
  1716. else
  1717. {
  1718. // add
  1719. url = GetParameter(CommonUtils.WsType.SvUnderInsert);
  1720. }
  1721. request.users = account;
  1722. var res = ServiceUnderUpdateRes.Parse(SendPost(request, url));
  1723. return Json(new
  1724. {
  1725. error = res.responseCode,
  1726. content = res.responseMessage
  1727. });
  1728. }
  1729. [HttpPost]
  1730. public JsonResult ServiceUnderDelete(ServiceUnderUpdateReq request)
  1731. {
  1732. if (!CheckAuthToken())
  1733. {
  1734. return Json(new
  1735. {
  1736. error = "-1",
  1737. content = "Login first"
  1738. });
  1739. }
  1740. string account = HttpContext.Session.GetString("account");
  1741. // check update or add
  1742. string url = GetParameter(CommonUtils.WsType.SvUnderUpdate);
  1743. request.users = account;
  1744. request.type = "1";// delete
  1745. var res = ServiceUnderUpdateRes.Parse(SendPost(request, url));
  1746. return Json(new
  1747. {
  1748. error = res.responseCode,
  1749. content = res.responseMessage
  1750. });
  1751. }
  1752. [HttpPost]
  1753. public IActionResult ServiceUnderExport(ServiceUnderGetListReq req)
  1754. {
  1755. if (!CheckAuthToken())
  1756. {
  1757. return null;
  1758. }
  1759. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  1760. string url = GetParameter(CommonUtils.WsType.SvGetList);
  1761. string result = SendPost(req, url);
  1762. ServiceUnderGetListRes res = ServiceUnderGetListRes.Parse(result);
  1763. var list = res.list;
  1764. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  1765. string fileName = "service_ngam.xlsx";
  1766. try
  1767. {
  1768. using (var workbook = new XLWorkbook())
  1769. {
  1770. //<th scope="col" class="text-center" style="vertical-align:middle">ID</th>
  1771. //<th scope = "col" class="text-center" style="vertical-align:middle">Service Name</th>
  1772. //<th scope = "col" class="text-center" style="vertical-align:middle">From Date</th>
  1773. //<th scope = "col" class="text-center" style="vertical-align:middle">To Date</th>
  1774. //<th scope = "col" class="text-center" style="vertical-align:middle">Percent</th>
  1775. //<th scope = "col" class="text-center" style="vertical-align:middle">Message</th>
  1776. //<th scope = "col" class="text-center" style="vertical-align:middle">Type</th>
  1777. //<th scope = "col" class="text-center" style="vertical-align:middle">Action</th>
  1778. int i = 1;
  1779. IXLWorksheet worksheet = workbook.Worksheets.Add("Service Under");
  1780. worksheet.Column(i).Width = 15;
  1781. worksheet.Cell(1, i++).Value = "No.";
  1782. worksheet.Column(i).Width = 20;
  1783. worksheet.Cell(1, i++).Value = "Name";
  1784. worksheet.Column(i).Width = 15;
  1785. worksheet.Cell(1, i++).Value = "From Date";
  1786. worksheet.Column(i).Width = 20;
  1787. worksheet.Cell(1, i++).Value = "To Date";
  1788. worksheet.Column(i).Width = 20;
  1789. worksheet.Cell(1, i++).Value = "Percent";
  1790. worksheet.Column(i).Width = 20;
  1791. worksheet.Cell(1, i++).Value = "Content Type";
  1792. worksheet.Column(i).Width = 20;
  1793. worksheet.Cell(1, i++).Value = "Message";
  1794. // make color
  1795. worksheet.Row(1).Style.Font.Bold = true;
  1796. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  1797. //worksheet.Cell(1, i++).Value = "BetId";
  1798. if (list != null && list.Count > 0)
  1799. {
  1800. for (int index = 1; index <= list.Count; index++)
  1801. {
  1802. i = 1;
  1803. var obj = list[index - 1];
  1804. worksheet.Cell(index + 1, i++).Value = index;
  1805. worksheet.Cell(index + 1, i++).Value = obj.name;
  1806. worksheet.Cell(index + 1, i++).Value = obj.fromDate;
  1807. worksheet.Cell(index + 1, i++).Value = obj.toDate;
  1808. worksheet.Cell(index + 1, i++).Value = obj.percent;
  1809. worksheet.Cell(index + 1, i++).Value = obj.addType == "1" ? "Text" : "Register";
  1810. worksheet.Cell(index + 1, i++).Value = obj.message;
  1811. }
  1812. }
  1813. using (var stream = new MemoryStream())
  1814. {
  1815. workbook.SaveAs(stream);
  1816. var content = stream.ToArray();
  1817. return File(content, contentType, fileName);
  1818. }
  1819. }
  1820. }
  1821. catch (Exception ex)
  1822. {
  1823. return null;
  1824. }
  1825. }
  1826. // USER MANAGEMENT
  1827. public IActionResult UserManagement()
  1828. {
  1829. if (!CheckAuthToken())
  1830. {
  1831. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  1832. }
  1833. return View();
  1834. }
  1835. [HttpPost]
  1836. public IActionResult UserSearch(UserWebCmsGetListReq req)
  1837. {
  1838. if (!CheckAuthToken())
  1839. {
  1840. return Json(new
  1841. {
  1842. error = "-1",
  1843. content = "Login first"
  1844. });
  1845. }
  1846. if (req.rowsOnPage == null)
  1847. {
  1848. req.rowsOnPage = "1000000";
  1849. req.seqPage = "1";
  1850. req.order = "desc";
  1851. }
  1852. String url = GetParameter(CommonUtils.WsType.UserWebCmsGetList);
  1853. UserWebCmsGetListRes res = UserWebCmsGetListRes.Parse(SendPost(req, url));
  1854. return PartialView("../Partial/_Users", res.list);
  1855. }
  1856. [HttpPost]
  1857. public JsonResult UserLoadInfo(UserWebCmsGetListReq request)
  1858. {
  1859. if (!CheckAuthToken())
  1860. {
  1861. return Json(new
  1862. {
  1863. error = "-1",
  1864. content = "Login first"
  1865. });
  1866. }
  1867. string account = HttpContext.Session.GetString("account");
  1868. String url = GetParameter(CommonUtils.WsType.UserWebCmsGetList);
  1869. var res = UserWebCmsGetListRes.Parse(SendPost(request, url));
  1870. if (res.list != null && res.list.Count > 0)
  1871. {
  1872. return Json(new
  1873. {
  1874. error = res.responseCode,
  1875. content = res.responseMessage,
  1876. data = res.list[0]
  1877. });
  1878. }
  1879. return Json(new
  1880. {
  1881. error = "-1",
  1882. content = "Not found"
  1883. });
  1884. }
  1885. [HttpPost]
  1886. public JsonResult UserAddUpdate(UserWebCmsUpdateReq request)
  1887. {
  1888. if (!CheckAuthToken())
  1889. {
  1890. return Json(new
  1891. {
  1892. error = "-1",
  1893. content = "Login first"
  1894. });
  1895. }
  1896. string account = HttpContext.Session.GetString("account");
  1897. string url = "";
  1898. if (request.id != null && request.id != "")
  1899. {
  1900. url = GetParameter(CommonUtils.WsType.UserWebCmsUpdate);
  1901. }
  1902. else
  1903. {
  1904. url = GetParameter(CommonUtils.WsType.UserWebCmsInsert);
  1905. }
  1906. request.users = account;
  1907. var res = UserWebCmsUpdateRes.Parse(SendPost(request, url));
  1908. return Json(new
  1909. {
  1910. error = res.responseCode,
  1911. content = res.responseMessage
  1912. });
  1913. }
  1914. // REPORT COUNT DAILY
  1915. public IActionResult ReportCountDaily()
  1916. {
  1917. if (!CheckAuthToken())
  1918. {
  1919. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  1920. }
  1921. // Load campaign list if not in session
  1922. try
  1923. {
  1924. var listCampaign = HttpContext.Session.GetComplexData<List<Campaign>>("listCampaign");
  1925. if (listCampaign == null)
  1926. {
  1927. CampaignGetListReq req = new CampaignGetListReq();
  1928. req.rowsOnPage = "1000000";
  1929. req.seqPage = "1";
  1930. req.order = "desc";
  1931. String url = GetParameter(CommonUtils.WsType.CamGetList);
  1932. CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
  1933. HttpContext.Session.SetComplexData("listCampaign", res.list);
  1934. }
  1935. }
  1936. catch (Exception ex)
  1937. {
  1938. log.Error("Error load campaign: ", ex);
  1939. }
  1940. return View();
  1941. }
  1942. [HttpPost]
  1943. public IActionResult ReportCountDailySearch(ReportCountDailyReq req)
  1944. {
  1945. if (!CheckAuthToken())
  1946. {
  1947. return Json(new
  1948. {
  1949. error = "-1",
  1950. content = "Login first"
  1951. });
  1952. }
  1953. req.rowsOnPage = "1000000";
  1954. req.seqPage = "1";
  1955. req.order = "desc";
  1956. String url = GetParameter(CommonUtils.WsType.ReportCountDailyGetList);
  1957. ReportCountDailyRes res = ReportCountDailyRes.Parse(SendPost(req, url));
  1958. return PartialView("../Partial/_ReportCountDaily", res.list);
  1959. }
  1960. [HttpPost]
  1961. public IActionResult ReportCountDailyExport(ReportCountDailyReq req)
  1962. {
  1963. if (!CheckAuthToken())
  1964. {
  1965. return null;
  1966. }
  1967. req.rowsOnPage = "1000000";
  1968. req.seqPage = "1";
  1969. req.order = "desc";
  1970. String url = GetParameter(CommonUtils.WsType.ReportCountDailyGetList);
  1971. ReportCountDailyRes res = ReportCountDailyRes.Parse(SendPost(req, url));
  1972. var list = res.list;
  1973. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  1974. string fileName = "report_count_daily.xlsx";
  1975. try
  1976. {
  1977. using (var workbook = new XLWorkbook())
  1978. {
  1979. int i = 1;
  1980. IXLWorksheet worksheet = workbook.Worksheets.Add("Report Count Daily");
  1981. worksheet.Column(i).Width = 15;
  1982. worksheet.Cell(1, i++).Value = "#";
  1983. worksheet.Column(i).Width = 20;
  1984. worksheet.Cell(1, i++).Value = "Report Date";
  1985. worksheet.Column(i).Width = 15;
  1986. worksheet.Cell(1, i++).Value = "Campaign ID";
  1987. worksheet.Column(i).Width = 30;
  1988. worksheet.Cell(1, i++).Value = "Campaign Name";
  1989. worksheet.Column(i).Width = 15;
  1990. worksheet.Cell(1, i++).Value = "Priority";
  1991. worksheet.Column(i).Width = 15;
  1992. worksheet.Cell(1, i++).Value = "Campaign Type";
  1993. worksheet.Column(i).Width = 15;
  1994. worksheet.Cell(1, i++).Value = "Service Type";
  1995. worksheet.Column(i).Width = 15;
  1996. worksheet.Cell(1, i++).Value = "Partner";
  1997. worksheet.Column(i).Width = 30;
  1998. worksheet.Cell(1, i++).Value = "Service Name";
  1999. worksheet.Column(i).Width = 15;
  2000. worksheet.Cell(1, i++).Value = "USSD out success";
  2001. // make color
  2002. worksheet.Row(1).Style.Font.Bold = true;
  2003. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  2004. if (list != null && list.Count > 0)
  2005. {
  2006. for (int index = 1; index <= list.Count; index++)
  2007. {
  2008. i = 1;
  2009. var obj = list[index - 1];
  2010. worksheet.Cell(index + 1, i++).Value = index;
  2011. worksheet.Cell(index + 1, i++).SetValue(obj.reportDate);
  2012. worksheet.Cell(index + 1, i++).Value = obj.campaignId;
  2013. worksheet.Cell(index + 1, i++).Value = obj.campaignName;
  2014. worksheet.Cell(index + 1, i++).Value = obj.priority;
  2015. worksheet.Cell(index + 1, i++).Value = obj.isDefault == "0" ? "Normal" : obj.isDefault == "1" ? "Default" : obj.isDefault;
  2016. worksheet.Cell(index + 1, i++).Value = obj.addType == "1" ? "Text" : obj.addType == "2" ? "1-Verification" : obj.addType == "3" ? "2-Verification" : obj.addType;
  2017. worksheet.Cell(index + 1, i++).Value = obj.isMyService == "0" ? "Metfone" : obj.isMyService == "1" ? "Khmernet" : obj.isMyService;
  2018. worksheet.Cell(index + 1, i++).Value = obj.serviceName;
  2019. worksheet.Cell(index + 1, i++).Value = obj.countSend1;
  2020. }
  2021. }
  2022. using (var stream = new MemoryStream())
  2023. {
  2024. workbook.SaveAs(stream);
  2025. var content = stream.ToArray();
  2026. return File(content, contentType, fileName);
  2027. }
  2028. }
  2029. }
  2030. catch (Exception ex)
  2031. {
  2032. log.Error("Error exporting report count daily: ", ex);
  2033. return StatusCode(StatusCodes.Status500InternalServerError, "Unable to export report count daily.");
  2034. }
  2035. }
  2036. // FUNCTION MANAGEMENT
  2037. public IActionResult FunctionManagement()
  2038. {
  2039. if (!CheckAuthToken())
  2040. {
  2041. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  2042. }
  2043. return View();
  2044. }
  2045. [HttpPost]
  2046. public IActionResult FunctionSearch(FunctionWebCmsGetListReq req)
  2047. {
  2048. if (!CheckAuthToken())
  2049. {
  2050. return Json(new
  2051. {
  2052. error = "-1",
  2053. content = "Login first"
  2054. });
  2055. }
  2056. if (req.rowsOnPage == null)
  2057. {
  2058. req.rowsOnPage = "1000000";
  2059. req.seqPage = "1";
  2060. req.order = "desc";
  2061. }
  2062. String url = GetParameter(CommonUtils.WsType.FunctionWebCmsGetList);
  2063. FunctionWebCmsGetListRes res = FunctionWebCmsGetListRes.Parse(SendPost(req, url));
  2064. return PartialView("../Partial/_Functions", res.list);
  2065. }
  2066. [HttpPost]
  2067. public JsonResult FunctionLoadInfo(FunctionWebCmsGetListReq request)
  2068. {
  2069. if (!CheckAuthToken())
  2070. {
  2071. return Json(new
  2072. {
  2073. error = "-1",
  2074. content = "Login first"
  2075. });
  2076. }
  2077. string account = HttpContext.Session.GetString("account");
  2078. String url = GetParameter(CommonUtils.WsType.FunctionWebCmsGetList);
  2079. var res = FunctionWebCmsGetListRes.Parse(SendPost(request, url));
  2080. if (res.list != null && res.list.Count > 0)
  2081. {
  2082. return Json(new
  2083. {
  2084. error = res.responseCode,
  2085. content = res.responseMessage,
  2086. data = res.list[0]
  2087. });
  2088. }
  2089. return Json(new
  2090. {
  2091. error = "-1",
  2092. content = "Not found"
  2093. });
  2094. }
  2095. [HttpPost]
  2096. public JsonResult FunctionAddUpdate(FunctionWebCmsUpdateReq request)
  2097. {
  2098. if (!CheckAuthToken())
  2099. {
  2100. return Json(new
  2101. {
  2102. error = "-1",
  2103. content = "Login first"
  2104. });
  2105. }
  2106. string account = HttpContext.Session.GetString("account");
  2107. string url = "";
  2108. if (request.id != null && request.id != "")
  2109. {
  2110. url = GetParameter(CommonUtils.WsType.FunctionWebCmsUpdate);
  2111. }
  2112. else
  2113. {
  2114. url = GetParameter(CommonUtils.WsType.FunctionWebCmsInsert);
  2115. }
  2116. request.users = account;
  2117. var res = FunctionWebCmsUpdateRes.Parse(SendPost(request, url));
  2118. return Json(new
  2119. {
  2120. error = res.responseCode,
  2121. content = res.responseMessage
  2122. });
  2123. }
  2124. [HttpPost]
  2125. public JsonResult FunctionDelete(FunctionWebCmsUpdateReq request)
  2126. {
  2127. if (!CheckAuthToken())
  2128. {
  2129. return Json(new
  2130. {
  2131. error = "-1",
  2132. content = "Login first"
  2133. });
  2134. }
  2135. string account = HttpContext.Session.GetString("account");
  2136. string url = GetParameter(CommonUtils.WsType.FunctionWebCmsDelete);
  2137. request.users = account;
  2138. var res = FunctionWebCmsUpdateRes.Parse(SendPost(request, url));
  2139. return Json(new
  2140. {
  2141. error = res.responseCode,
  2142. content = res.responseMessage
  2143. });
  2144. }
  2145. [HttpPost]
  2146. public IActionResult ReportErrorDailyDetail(ReportErrorDailyReq req)
  2147. {
  2148. if (!CheckAuthToken())
  2149. {
  2150. return Json(new
  2151. {
  2152. error = "-1",
  2153. content = "Login first"
  2154. });
  2155. }
  2156. string account = HttpContext.Session.GetString("account");
  2157. if (string.IsNullOrEmpty(account))
  2158. {
  2159. account = "-1";
  2160. }
  2161. req.users = account;
  2162. String url = GetParameter(CommonUtils.WsType.ReportErrorDailyGetList);
  2163. if (string.IsNullOrEmpty(url))
  2164. {
  2165. return Json(new
  2166. {
  2167. error = "-1",
  2168. content = "API URL not configured"
  2169. });
  2170. }
  2171. try
  2172. {
  2173. ReportErrorDailyRes res = ReportErrorDailyRes.Parse(SendPost(req, url));
  2174. if (res == null || res.responseCode != "0")
  2175. {
  2176. return Json(new
  2177. {
  2178. error = res?.responseCode ?? "-1",
  2179. content = res?.responseMessage ?? "Error occurred"
  2180. });
  2181. }
  2182. return PartialView("../Partial/_ReportErrorDaily", res.list ?? new List<ReportErrorDaily>());
  2183. }
  2184. catch (Exception ex)
  2185. {
  2186. log.Error("Error in ReportErrorDailyDetail: ", ex);
  2187. return Json(new
  2188. {
  2189. error = "-1",
  2190. content = "Error occurred: " + ex.Message
  2191. });
  2192. }
  2193. }
  2194. public IActionResult DashboardReport()
  2195. {
  2196. if (!CheckAuthToken())
  2197. {
  2198. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  2199. }
  2200. // Load campaign list if not in session
  2201. try
  2202. {
  2203. var listCampaign = HttpContext.Session.GetComplexData<List<Campaign>>("listCampaign");
  2204. if (listCampaign == null)
  2205. {
  2206. CampaignGetListReq req = new CampaignGetListReq();
  2207. req.rowsOnPage = "1000000";
  2208. req.seqPage = "1";
  2209. req.order = "desc";
  2210. String url = GetParameter(CommonUtils.WsType.CamGetList);
  2211. CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
  2212. HttpContext.Session.SetComplexData("listCampaign", res.list);
  2213. }
  2214. var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
  2215. if (listService == null)
  2216. {
  2217. PreLoadService();
  2218. }
  2219. }
  2220. catch (Exception ex)
  2221. {
  2222. log.Error("Error load campaign/service: ", ex);
  2223. }
  2224. return View();
  2225. }
  2226. [HttpPost]
  2227. public JsonResult DashboardReportGetData(string campaignId, string serviceId, string hours, string quickJump)
  2228. {
  2229. if (!CheckAuthToken())
  2230. {
  2231. return Json(new
  2232. {
  2233. error = "-1",
  2234. content = "Login first"
  2235. });
  2236. }
  2237. string account = HttpContext.Session.GetString("account");
  2238. if (string.IsNullOrEmpty(account))
  2239. {
  2240. account = "-1";
  2241. }
  2242. try
  2243. {
  2244. HourlyImpressionsGetListReq req = new HourlyImpressionsGetListReq();
  2245. req.users = account;
  2246. req.campaignId = campaignId ?? "-1";
  2247. req.serviceId = serviceId ?? "-1";
  2248. req.hours = hours ?? "72h";
  2249. req.quickJump = quickJump ?? "-1";
  2250. req.language = "vi";
  2251. String url = GetParameter(CommonUtils.WsType.HourlyImpressionsGetList);
  2252. if (string.IsNullOrEmpty(url))
  2253. {
  2254. return Json(new
  2255. {
  2256. error = "-1",
  2257. content = "API URL not configured"
  2258. });
  2259. }
  2260. HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(req, url));
  2261. if (res == null || res.responseCode != "0")
  2262. {
  2263. return Json(new
  2264. {
  2265. error = res?.responseCode ?? "-1",
  2266. content = res?.responseMessage ?? "Error occurred"
  2267. });
  2268. }
  2269. return Json(new
  2270. {
  2271. error = "0",
  2272. data = JsonConvert.SerializeObject(res)
  2273. });
  2274. }
  2275. catch (Exception ex)
  2276. {
  2277. log.Error("Error in DashboardReportGetData: ", ex);
  2278. return Json(new
  2279. {
  2280. error = "-1",
  2281. content = "Error occurred: " + ex.Message
  2282. });
  2283. }
  2284. }
  2285. [HttpPost]
  2286. public JsonResult DashboardReportGetDailyData(string campaignId, string fromDate, string toDate)
  2287. {
  2288. if (!CheckAuthToken())
  2289. {
  2290. return Json(new
  2291. {
  2292. error = "-1",
  2293. content = "Login first"
  2294. });
  2295. }
  2296. string account = HttpContext.Session.GetString("account");
  2297. if (string.IsNullOrEmpty(account))
  2298. {
  2299. account = "-1";
  2300. }
  2301. try
  2302. {
  2303. HourlyImpressionsGetListReq req = new HourlyImpressionsGetListReq();
  2304. req.users = account;
  2305. req.campaignId = campaignId ?? "-1";
  2306. req.hours = "-1"; // Not used for daily
  2307. req.quickJump = "-1"; // Not used for daily
  2308. req.language = "vi";
  2309. String url = GetParameter(CommonUtils.WsType.DailyImpressionsGetList);
  2310. if (string.IsNullOrEmpty(url))
  2311. {
  2312. return Json(new
  2313. {
  2314. error = "-1",
  2315. content = "API URL not configured"
  2316. });
  2317. }
  2318. // Create custom request object for daily (with fromDate and toDate)
  2319. DailyImpressionsGetListReq dailyReq = new DailyImpressionsGetListReq();
  2320. dailyReq.users = account;
  2321. dailyReq.campaignId = campaignId ?? "-1";
  2322. dailyReq.fromDate = fromDate ?? "-1";
  2323. dailyReq.toDate = toDate ?? "-1";
  2324. dailyReq.language = "vi";
  2325. dailyReq.channel = "WEB";
  2326. dailyReq.token = HttpContext.Session.GetString("token") ?? "";
  2327. HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(dailyReq, url));
  2328. if (res == null || res.responseCode != "0")
  2329. {
  2330. return Json(new
  2331. {
  2332. error = res?.responseCode ?? "-1",
  2333. content = res?.responseMessage ?? "Error occurred"
  2334. });
  2335. }
  2336. return Json(new
  2337. {
  2338. error = "0",
  2339. data = JsonConvert.SerializeObject(res)
  2340. });
  2341. }
  2342. catch (Exception ex)
  2343. {
  2344. log.Error("Error in DashboardReportGetDailyData: ", ex);
  2345. return Json(new
  2346. {
  2347. error = "-1",
  2348. content = "Error occurred: " + ex.Message
  2349. });
  2350. }
  2351. }
  2352. [HttpPost]
  2353. public JsonResult DashboardReportGetDailyUniqueData(string campaignId, string serviceId, string fromDate, string toDate)
  2354. {
  2355. if (!CheckAuthToken())
  2356. {
  2357. return Json(new
  2358. {
  2359. error = "-1",
  2360. content = "Login first"
  2361. });
  2362. }
  2363. string account = HttpContext.Session.GetString("account");
  2364. if (string.IsNullOrEmpty(account))
  2365. {
  2366. account = "-1";
  2367. }
  2368. try
  2369. {
  2370. DailyImpressionsGetListReq req = new DailyImpressionsGetListReq();
  2371. req.users = account;
  2372. req.campaignId = campaignId ?? "-1";
  2373. req.serviceId = serviceId ?? "-1";
  2374. req.fromDate = fromDate ?? "-1";
  2375. req.toDate = toDate ?? "-1";
  2376. req.language = "vi";
  2377. req.channel = "WEB";
  2378. req.token = HttpContext.Session.GetString("token") ?? "";
  2379. String url = GetParameter(CommonUtils.WsType.DailyUniqueImpressionsGetList);
  2380. if (string.IsNullOrEmpty(url))
  2381. {
  2382. return Json(new
  2383. {
  2384. error = "-1",
  2385. content = "API URL not configured"
  2386. });
  2387. }
  2388. HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(req, url));
  2389. if (res == null || res.responseCode != "0")
  2390. {
  2391. return Json(new
  2392. {
  2393. error = res?.responseCode ?? "-1",
  2394. content = res?.responseMessage ?? "Error occurred"
  2395. });
  2396. }
  2397. return Json(new
  2398. {
  2399. error = "0",
  2400. data = JsonConvert.SerializeObject(res)
  2401. });
  2402. }
  2403. catch (Exception ex)
  2404. {
  2405. log.Error("Error in DashboardReportGetDailyUniqueData: ", ex);
  2406. return Json(new
  2407. {
  2408. error = "-1",
  2409. content = "Error occurred: " + ex.Message
  2410. });
  2411. }
  2412. }
  2413. [HttpPost]
  2414. public JsonResult DashboardReportGetDailyEngagedData(string campaignId, string fromDate, string toDate)
  2415. {
  2416. if (!CheckAuthToken())
  2417. {
  2418. return Json(new
  2419. {
  2420. error = "-1",
  2421. content = "Login first"
  2422. });
  2423. }
  2424. string account = HttpContext.Session.GetString("account");
  2425. if (string.IsNullOrEmpty(account))
  2426. {
  2427. account = "-1";
  2428. }
  2429. try
  2430. {
  2431. DailyImpressionsGetListReq req = new DailyImpressionsGetListReq();
  2432. req.users = account;
  2433. req.campaignId = campaignId ?? "-1";
  2434. req.serviceId = "-1";
  2435. req.fromDate = fromDate ?? "-1";
  2436. req.toDate = toDate ?? "-1";
  2437. req.language = "vi";
  2438. req.channel = "WEB";
  2439. req.token = HttpContext.Session.GetString("token") ?? "";
  2440. String url = GetParameter(CommonUtils.WsType.DailyEngagedGetList);
  2441. if (string.IsNullOrEmpty(url))
  2442. {
  2443. return Json(new
  2444. {
  2445. error = "-1",
  2446. content = "API URL not configured"
  2447. });
  2448. }
  2449. HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(req, url));
  2450. if (res == null || res.responseCode != "0")
  2451. {
  2452. return Json(new
  2453. {
  2454. error = res?.responseCode ?? "-1",
  2455. content = res?.responseMessage ?? "Error occurred"
  2456. });
  2457. }
  2458. return Json(new
  2459. {
  2460. error = "0",
  2461. data = JsonConvert.SerializeObject(res)
  2462. });
  2463. }
  2464. catch (Exception ex)
  2465. {
  2466. log.Error("Error in DashboardReportGetDailyEngagedData: ", ex);
  2467. return Json(new
  2468. {
  2469. error = "-1",
  2470. content = "Error occurred: " + ex.Message
  2471. });
  2472. }
  2473. }
  2474. }
  2475. }