AdminController.cs 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Configuration;
  6. using SuperCms.Extensions;
  7. using SuperAdmin.Source;
  8. using Microsoft.AspNetCore.Http;
  9. using System.IO;
  10. using ReportWeb.Models;
  11. using ReportWeb;
  12. using System.Data;
  13. using Newtonsoft.Json;
  14. using ReportWeb.Source;
  15. using OfficeOpenXml;
  16. using ClosedXML.Excel;
  17. namespace SuperAdmin.Controllers
  18. {
  19. public class AdminController : BaseController
  20. {
  21. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  22. DbConnector db = new DbConnector();
  23. List<Services> listService;
  24. String sdf = "dd/MM/yyyy HH:mm";
  25. String df = "dd/MM/yyyy";
  26. public static int counter = 0;
  27. public static bool counterStart = false;
  28. public AdminController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
  29. {
  30. // init
  31. subDomain = _configuration["subDomain"];
  32. }
  33. public ActionResult Index(String nameSearch)
  34. {
  35. // get list service
  36. if (HttpContext.Session.GetComplexData<List<Services>>("listService") == null)
  37. {
  38. listService = db.LoadListServices();
  39. HttpContext.Session.SetComplexData("listService", listService);
  40. }
  41. Users user = HttpContext.Session.GetComplexData<Users>("user");
  42. if (user == null || (user.role <= 0))
  43. {
  44. return Redirect(subDomain + "/Home/Login");
  45. }
  46. if (user.role == Common.UserRole.Agent)
  47. {
  48. return View("SearchHistory");
  49. }
  50. ReportWeb.Models.DashboardModel model = new ReportWeb.Models.DashboardModel();
  51. model.listDailyReport = db.GetCommonReport(DateTime.Now.AddDays(-11), DateTime.Now.AddDays(-1));
  52. model.listDailyReportTotal = db.GetTotalReport(DateTime.Now.AddDays(-11), DateTime.Now.AddDays(-1));
  53. model.listHourlyReportTotal = db.GetTotalHourlyReport(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
  54. //model.todayReport = db.GetCommonReport(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
  55. //model.yesterdayReport = db.GetCommonReport(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-2));
  56. model.todayReport = new List<DailyReport>();
  57. model.yesterdayReport = new List<DailyReport>();
  58. String today = DateTime.Now.AddDays(-1).ToString(df);
  59. String yesterday = DateTime.Now.AddDays(-2).ToString(df);
  60. if (model.listDailyReport != null)
  61. {
  62. foreach (DailyReport dailyReport in model.listDailyReport)
  63. {
  64. if (dailyReport.report_date == today)
  65. {
  66. model.todayReport.Add(dailyReport);
  67. }
  68. if (dailyReport.report_date == yesterday)
  69. {
  70. model.yesterdayReport.Add(dailyReport);
  71. }
  72. model.avg7NewSubs += dailyReport.count_reg;
  73. model.avg7TotalSubs += dailyReport.count_active;
  74. model.avg7TotalRevenue += dailyReport.revenue;
  75. }
  76. }
  77. model.avg7NewSubs = model.avg7NewSubs / 10;
  78. model.avg7TotalSubs = model.avg7TotalSubs / 10;
  79. model.avg7TotalRevenue = model.avg7TotalRevenue / 10;
  80. // total
  81. foreach (DailyReport dailyReport in model.todayReport)
  82. {
  83. model.totalSubs += dailyReport.count_active;
  84. model.newSubs += dailyReport.count_reg;
  85. model.totalRevenue += dailyReport.revenue;
  86. }
  87. model.totalSubs = model.totalSubs;
  88. model.newSubs = model.newSubs;
  89. model.totalRevenue = model.totalRevenue;
  90. return View(model);
  91. }
  92. public ActionResult SearchHistory()
  93. {
  94. Users user = HttpContext.Session.GetComplexData<Users>("user");
  95. if (user == null || (user.role <= 0))
  96. {
  97. return Redirect(subDomain + "/Home/Login");
  98. }
  99. else
  100. {
  101. return View();
  102. }
  103. }
  104. [HttpPost]
  105. public JsonResult SearchHistoryAction(String msisdn, String service_id, String fromDate, String toDate)
  106. {
  107. Users user = HttpContext.Session.GetComplexData<Users>("user");
  108. if (user == null || user.role <= 0)
  109. {
  110. ViewBag.username = "Welcome!";
  111. return Json(new
  112. {
  113. error = "10",
  114. content = "Timeout"
  115. });
  116. }
  117. msisdn = validateMsisdn(msisdn);
  118. if (msisdn == null || msisdn == "")
  119. {
  120. return Json(new
  121. {
  122. error = "1",
  123. content = "Enter msisdn"
  124. });
  125. }
  126. Services sv = GetServiceById(int.Parse(service_id));
  127. if (sv == null)
  128. {
  129. return Json(new
  130. {
  131. error = "2",
  132. content = "Not found service"
  133. });
  134. }
  135. DateTime startTime = DateTime.ParseExact(fromDate, df, null);
  136. DateTime endTime = DateTime.ParseExact(toDate, df, null);
  137. sv = db.GetServiceRpBySvCode(sv.sv_code);
  138. List<RegInfo> listRegInfo = db.GetRegisterInfo(sv, msisdn, startTime, endTime);
  139. List<ChargeLog> listChargeLog = db.GetChargeLog(sv, msisdn, startTime, endTime);
  140. return Json(new
  141. {
  142. error = "0",
  143. listRegInfo = listRegInfo,
  144. listChargeLog = listChargeLog
  145. });
  146. }
  147. // SPIN
  148. public ActionResult SearchSpin()
  149. {
  150. Users user = HttpContext.Session.GetComplexData<Users>("user");
  151. if (user == null || (user.role <= 0))
  152. {
  153. return Redirect(subDomain + "/Home/Login");
  154. }
  155. else
  156. {
  157. return View();
  158. }
  159. }
  160. [HttpPost]
  161. public JsonResult SearchSpinAction(String msisdn, String fromDate, String toDate)
  162. {
  163. Users user = HttpContext.Session.GetComplexData<Users>("user");
  164. if (user == null || user.role <= 0)
  165. {
  166. ViewBag.username = "Welcome!";
  167. return Json(new
  168. {
  169. error = "10",
  170. content = "Timeout"
  171. });
  172. }
  173. msisdn = validateMsisdn(msisdn);
  174. if (msisdn == null || msisdn == "")
  175. {
  176. return Json(new
  177. {
  178. error = "1",
  179. content = "Enter msisdn"
  180. });
  181. }
  182. DateTime startTime = DateTime.ParseExact(fromDate, df, null);
  183. DateTime endTime = DateTime.ParseExact(toDate, df, null);
  184. List<SpinLog> listSpin = db.GetLuckySpin(msisdn, startTime, endTime);
  185. SearchModel model = new SearchModel();
  186. model.listSpin = listSpin;
  187. model.remainSpin = db.CountLuckySpin(msisdn);
  188. return Json(new
  189. {
  190. error = "0",
  191. model = model
  192. });
  193. }
  194. [HttpPost]
  195. public IActionResult HistorySpinExport(String msisdn, String fromDate, String toDate)
  196. {
  197. if (!CheckAuthToken())
  198. {
  199. return Json(new
  200. {
  201. error = "-1",
  202. content = "Not allow"
  203. });
  204. }
  205. return ExportSpin(msisdn, fromDate, toDate);
  206. }
  207. private FileContentResult ExportSpin(String msisdn, String fromDate, String toDate)
  208. {
  209. try
  210. {
  211. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  212. msisdn = validateMsisdn(msisdn);
  213. DateTime startTime = DateTime.ParseExact(fromDate, df, null);
  214. DateTime endTime = DateTime.ParseExact(toDate, df, null);
  215. List<SpinLog> list = db.GetLuckySpin(msisdn, startTime, endTime);
  216. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  217. string fileName = "report_spin.xlsx";
  218. using (var workbook = new XLWorkbook())
  219. {
  220. int i = 1;
  221. IXLWorksheet worksheet = workbook.Worksheets.Add("Report Spin");
  222. worksheet.Column(i).Width = 15;
  223. worksheet.Cell(1, i++).Value = "No.";
  224. worksheet.Column(i).Width = 20;
  225. worksheet.Cell(1, i++).Value = "Phone number";
  226. worksheet.Column(i).Width = 25;
  227. worksheet.Cell(1, i++).Value = "Receive Time";
  228. worksheet.Column(i).Width = 15;
  229. worksheet.Cell(1, i++).Value = "Quantity";
  230. worksheet.Column(i).Width = 15;
  231. worksheet.Cell(1, i++).Value = "Used";
  232. worksheet.Column(i).Width = 25;
  233. worksheet.Cell(1, i++).Value = "Expire Time";
  234. worksheet.Column(i).Width = 15;
  235. worksheet.Cell(1, i++).Value = "Status";
  236. worksheet.Column(i).Width = 15;
  237. worksheet.Cell(1, i++).Value = "Note";
  238. // make color
  239. worksheet.Row(1).Style.Font.Bold = true;
  240. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  241. //worksheet.Cell(1, i++).Value = "BetId";
  242. if (list != null && list.Count > 0)
  243. {
  244. for (int index = 1; index <= list.Count; index++)
  245. {
  246. i = 1;
  247. var news = list[index - 1];
  248. worksheet.Cell(index + 1, i++).Value = index;
  249. worksheet.Cell(index + 1, i++).SetValue(news.msisdn);
  250. worksheet.Cell(index + 1, i++).SetValue(news.insert_time.Value.ToString("dd/MM/yyyy HH:mm:ss"));
  251. worksheet.Cell(index + 1, i++).SetValue(news.added);
  252. worksheet.Cell(index + 1, i++).SetValue(news.used);
  253. worksheet.Cell(index + 1, i++).SetValue(news.expire_time.Value.ToString("dd/MM/yyyy HH:mm:ss"));
  254. worksheet.Cell(index + 1, i++).SetValue(news.expire_time.Value > DateTime.Now ? "Valid" : "Expired");
  255. worksheet.Cell(index + 1, i++).SetValue(news.channel_add);
  256. }
  257. }
  258. using (var stream = new MemoryStream())
  259. {
  260. workbook.SaveAs(stream);
  261. var content = stream.ToArray();
  262. return File(content, contentType, fileName);
  263. }
  264. }
  265. }
  266. catch (Exception ex)
  267. {
  268. return null;
  269. }
  270. }
  271. // REPORT
  272. public ActionResult Report(String serviceId)
  273. {
  274. Users user = HttpContext.Session.GetComplexData<Users>("user");
  275. if (user == null || (user.role <= 0))
  276. {
  277. return Redirect(subDomain + "/Home/Login");
  278. }
  279. else
  280. {
  281. ViewBag.ServiceId = serviceId;
  282. return View();
  283. }
  284. }
  285. public ActionResult ReportHourly()
  286. {
  287. Users user = HttpContext.Session.GetComplexData<Users>("user");
  288. if (user == null || (user.role <= 0))
  289. {
  290. return Redirect(subDomain + "/Home/Login");
  291. }
  292. else
  293. {
  294. return View();
  295. }
  296. }
  297. public ActionResult ReportRevenue()
  298. {
  299. Users user = HttpContext.Session.GetComplexData<Users>("user");
  300. if (user == null || (user.role <= 0))
  301. {
  302. return Redirect(subDomain + "/Home/Login");
  303. }
  304. else
  305. {
  306. return View();
  307. }
  308. }
  309. public List<DailyReport> GetReportData(String fromDate, String toDate, String service_id)
  310. {
  311. DateTime startTime = DateTime.ParseExact(fromDate, df, null);
  312. DateTime endTime = DateTime.ParseExact(toDate, df, null);
  313. Services sv = GetServiceById(int.Parse(service_id));
  314. List<DailyReport> res = db.GetDailyReport(sv.sv_code, startTime, endTime);
  315. return res;
  316. }
  317. [HttpPost]
  318. public JsonResult GetReport(String fromDate, String toDate, String service_id)
  319. {
  320. Users user = HttpContext.Session.GetComplexData<Users>("user");
  321. if (user == null || user.role <= 0)
  322. {
  323. ViewBag.username = "Welcome!";
  324. return Json(new
  325. {
  326. error = "10",
  327. content = "Timeout"
  328. });
  329. }
  330. Services sv = GetServiceById(int.Parse(service_id));
  331. if (sv == null)
  332. {
  333. return Json(new
  334. {
  335. error = "2",
  336. content = "Not found service"
  337. });
  338. }
  339. List<DailyReport> res = GetReportData(fromDate, toDate, service_id);
  340. return Json(new
  341. {
  342. error = "0",
  343. dailyReport = res
  344. });
  345. }
  346. [HttpPost]
  347. public IActionResult ReportExport(String fromDate, String toDate, String service_id)
  348. {
  349. Users user = HttpContext.Session.GetComplexData<Users>("user");
  350. if (user == null || user.role <= 0)
  351. {
  352. ViewBag.username = "Welcome!";
  353. return Json(new
  354. {
  355. error = "10",
  356. content = "Timeout"
  357. });
  358. }
  359. Services sv = GetServiceById(int.Parse(service_id));
  360. if (sv == null)
  361. {
  362. return Json(new
  363. {
  364. error = "2",
  365. content = "Not found service"
  366. });
  367. }
  368. return ExportReport(fromDate, toDate, service_id);
  369. }
  370. private FileContentResult ExportReport(String fromDate, String toDate, String service_id)
  371. {
  372. try
  373. {
  374. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  375. List<DailyReport> list = GetReportData(fromDate, toDate, service_id);
  376. string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  377. string fileName = "report_total.xlsx";
  378. using (var workbook = new XLWorkbook())
  379. {
  380. int i = 1;
  381. IXLWorksheet worksheet = workbook.Worksheets.Add("Report Spin");
  382. worksheet.Column(i).Width = 15;
  383. worksheet.Cell(1, i++).Value = "No.";
  384. worksheet.Column(i).Width = 20;
  385. worksheet.Cell(1, i++).Value = "Report date";
  386. worksheet.Column(i).Width = 20;
  387. worksheet.Cell(1, i++).Value = "Revenue";
  388. worksheet.Column(i).Width = 20;
  389. worksheet.Cell(1, i++).Value = "Revenue Buy";
  390. worksheet.Column(i).Width = 20;
  391. worksheet.Cell(1, i++).Value = "Paid money";
  392. worksheet.Column(i).Width = 20;
  393. worksheet.Cell(1, i++).Value = "Count sub";
  394. worksheet.Column(i).Width = 20;
  395. worksheet.Cell(1, i++).Value = "Register new";
  396. worksheet.Column(i).Width = 20;
  397. worksheet.Cell(1, i++).Value = "Deactive";
  398. // make color
  399. worksheet.Row(1).Style.Font.Bold = true;
  400. worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
  401. //worksheet.Cell(1, i++).Value = "BetId";
  402. if (list != null && list.Count > 0)
  403. {
  404. for (int index = 1; index <= list.Count; index++)
  405. {
  406. i = 1;
  407. var news = list[index - 1];
  408. worksheet.Cell(index + 1, i++).Value = index;
  409. worksheet.Cell(index + 1, i++).SetValue(news.report_date);
  410. worksheet.Cell(index + 1, i++).SetValue(news.revenue);
  411. worksheet.Cell(index + 1, i++).SetValue(news.revenue_buy);
  412. worksheet.Cell(index + 1, i++).SetValue(news.paid_money);
  413. worksheet.Cell(index + 1, i++).SetValue(news.count_active);
  414. worksheet.Cell(index + 1, i++).SetValue(news.count_reg);
  415. worksheet.Cell(index + 1, i++).SetValue(news.count_deactive);
  416. }
  417. }
  418. using (var stream = new MemoryStream())
  419. {
  420. workbook.SaveAs(stream);
  421. var content = stream.ToArray();
  422. return File(content, contentType, fileName);
  423. }
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. return null;
  429. }
  430. }
  431. [HttpPost]
  432. public JsonResult GetReportHourly(String fromDate, String toDate, String service_id)
  433. {
  434. Users user = HttpContext.Session.GetComplexData<Users>("user");
  435. if (user == null || user.role <= 0)
  436. {
  437. ViewBag.username = "Welcome!";
  438. return Json(new
  439. {
  440. error = "10",
  441. content = "Timeout"
  442. });
  443. }
  444. DateTime startTime = DateTime.ParseExact(fromDate, df, null);
  445. DateTime endTime = DateTime.ParseExact(toDate, df, null);
  446. Services sv = GetServiceById(int.Parse(service_id));
  447. if (sv == null)
  448. {
  449. return Json(new
  450. {
  451. error = "2",
  452. content = "Not found service"
  453. });
  454. }
  455. List<DailyReport> res = db.GetHourlyReport(sv.sv_code, startTime, endTime);
  456. return Json(new
  457. {
  458. error = "0",
  459. dailyReport = res
  460. });
  461. }
  462. [HttpPost]
  463. public JsonResult GetRevenueHourly(String fromDate, String toDate, String service_id)
  464. {
  465. Users user = HttpContext.Session.GetComplexData<Users>("user");
  466. if (user == null || user.role <= 0)
  467. {
  468. ViewBag.username = "Welcome!";
  469. return Json(new
  470. {
  471. error = "10",
  472. content = "Timeout"
  473. });
  474. }
  475. DateTime startTime = DateTime.ParseExact(fromDate, df, null);
  476. DateTime endTime = DateTime.ParseExact(toDate, df, null);
  477. Services sv = GetServiceById(int.Parse(service_id));
  478. if (sv == null)
  479. {
  480. return Json(new
  481. {
  482. error = "2",
  483. content = "Not found service"
  484. });
  485. }
  486. DataTable dt = db.GetRevenueHourly(sv.sv_code, startTime, endTime);
  487. return Json(new
  488. {
  489. data = JsonConvert.SerializeObject(dt),
  490. error = "0"
  491. });
  492. }
  493. public ActionResult ServiceManagement()
  494. {
  495. Users user = HttpContext.Session.GetComplexData<Users>("user");
  496. if (user == null)
  497. {
  498. ViewBag.username = "Welcome!";
  499. return Redirect(subDomain + "/Home/Login");
  500. }
  501. if (user.role != Common.UserRole.Admin)
  502. {
  503. HttpContext.Session.Clear();
  504. ViewBag.username = "Welcome!";
  505. return Redirect(subDomain + "/Home/Login");
  506. }
  507. List<Services> listService = db.LoadListServices();
  508. return View(listService);
  509. }
  510. public ActionResult ServiceRpManagement()
  511. {
  512. Users user = HttpContext.Session.GetComplexData<Users>("user");
  513. if (user == null)
  514. {
  515. ViewBag.username = "Welcome!";
  516. return Redirect(subDomain + "/Home/Login");
  517. }
  518. if (user.role != Common.UserRole.Admin)
  519. {
  520. HttpContext.Session.Clear();
  521. ViewBag.username = "Welcome!";
  522. return Redirect(subDomain + "/Home/Login");
  523. }
  524. List<Services> listService = db.LoadListServicesReport();
  525. return View(listService);
  526. }
  527. public ActionResult ServiceAdvManagement()
  528. {
  529. Users user = HttpContext.Session.GetComplexData<Users>("user");
  530. if (user == null)
  531. {
  532. ViewBag.username = "Welcome!";
  533. return Redirect(subDomain + "/Home/Login");
  534. }
  535. if (user.role != Common.UserRole.Admin)
  536. {
  537. HttpContext.Session.Clear();
  538. ViewBag.username = "Welcome!";
  539. return Redirect(subDomain + "/Home/Login");
  540. }
  541. List<Services> listService = db.LoadListServicesAdv(-1);
  542. return View(listService);
  543. }
  544. [HttpPost]
  545. public JsonResult SearchService()
  546. {
  547. Users user = HttpContext.Session.GetComplexData<Users>("user");
  548. if (user == null)
  549. {
  550. return Json(new
  551. {
  552. error = "10",
  553. content = "Timeout"
  554. });
  555. }
  556. if (user.role != Common.UserRole.Admin)
  557. {
  558. return Json(new
  559. {
  560. error = "10",
  561. content = "Timeout"
  562. });
  563. }
  564. List<Services> listService = db.LoadListServices();
  565. return Json(new
  566. {
  567. error = "0",
  568. content = "Success",
  569. listService = listService
  570. });
  571. }
  572. [HttpPost]
  573. public JsonResult SearchServiceRp()
  574. {
  575. Users user = HttpContext.Session.GetComplexData<Users>("user");
  576. if (user == null)
  577. {
  578. return Json(new
  579. {
  580. error = "10",
  581. content = "Timeout"
  582. });
  583. }
  584. if (user.role != Common.UserRole.Admin)
  585. {
  586. return Json(new
  587. {
  588. error = "10",
  589. content = "Timeout"
  590. });
  591. }
  592. List<Services> listService = db.LoadListServicesReport();
  593. return Json(new
  594. {
  595. error = "0",
  596. content = "Success",
  597. listService = listService
  598. });
  599. }
  600. [HttpPost]
  601. public JsonResult SearchServiceAdv(string status)
  602. {
  603. Users user = HttpContext.Session.GetComplexData<Users>("user");
  604. if (user == null)
  605. {
  606. return Json(new
  607. {
  608. error = "10",
  609. content = "Timeout"
  610. });
  611. }
  612. if (user.role != Common.UserRole.Admin)
  613. {
  614. return Json(new
  615. {
  616. error = "10",
  617. content = "Timeout"
  618. });
  619. }
  620. int st = status == null ? -1 : int.Parse(status);
  621. List<Services> listService = db.LoadListServicesAdv(st);
  622. return Json(new
  623. {
  624. error = "0",
  625. content = "Success",
  626. listService = listService
  627. });
  628. }
  629. [HttpPost]
  630. public JsonResult GetServiceRpBySvCode(String svCode)
  631. {
  632. Users user = HttpContext.Session.GetComplexData<Users>("user");
  633. if (user == null)
  634. {
  635. return Json(new
  636. {
  637. error = "10",
  638. content = "Timeout"
  639. });
  640. }
  641. if (user.role != Common.UserRole.Admin)
  642. {
  643. return Json(new
  644. {
  645. error = "10",
  646. content = "Timeout"
  647. });
  648. }
  649. Services service = db.GetServiceRpBySvCode(svCode);
  650. return Json(new
  651. {
  652. error = "0",
  653. content = "Success",
  654. service = service
  655. });
  656. }
  657. [HttpPost]
  658. public JsonResult GetServiceAdvById(String advId)
  659. {
  660. Users user = HttpContext.Session.GetComplexData<Users>("user");
  661. if (user == null)
  662. {
  663. return Json(new
  664. {
  665. error = "10",
  666. content = "Timeout"
  667. });
  668. }
  669. if (user.role != Common.UserRole.Admin)
  670. {
  671. return Json(new
  672. {
  673. error = "10",
  674. content = "Timeout"
  675. });
  676. }
  677. Services service = db.GetServiceAdvById(advId);
  678. return Json(new
  679. {
  680. error = "0",
  681. content = "Success",
  682. service = service
  683. });
  684. }
  685. [HttpPost]
  686. public JsonResult GetServiceById(String serviceId)
  687. {
  688. Users user = HttpContext.Session.GetComplexData<Users>("user");
  689. if (user == null)
  690. {
  691. return Json(new
  692. {
  693. error = "10",
  694. content = "Timeout"
  695. });
  696. }
  697. if (user.role != Common.UserRole.Admin)
  698. {
  699. return Json(new
  700. {
  701. error = "10",
  702. content = "Timeout"
  703. });
  704. }
  705. Services service = db.GetServiceById(serviceId);
  706. return Json(new
  707. {
  708. error = "0",
  709. content = "Success",
  710. service = service
  711. });
  712. }
  713. [HttpPost]
  714. public ActionResult AddService()
  715. {
  716. Users user = HttpContext.Session.GetComplexData<Users>("user");
  717. if (user == null)
  718. {
  719. return Json(new
  720. {
  721. error = "10",
  722. content = "Timeout"
  723. });
  724. }
  725. if (user.role != Common.UserRole.Admin)
  726. {
  727. return Json(new
  728. {
  729. error = "10",
  730. content = "Timeout"
  731. });
  732. }
  733. try
  734. {
  735. String serviceName = Request.Form["serviceName"];
  736. String serviceCode = Request.Form["serviceCode"];
  737. // call ws
  738. db.InsertService(serviceCode, serviceName);
  739. // Returns message that successfully uploaded
  740. return Json(new
  741. {
  742. error_code = "0"
  743. });
  744. }
  745. catch (Exception ex)
  746. {
  747. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  748. }
  749. }
  750. [HttpPost]
  751. public ActionResult AddServiceRp()
  752. {
  753. Users user = HttpContext.Session.GetComplexData<Users>("user");
  754. if (user == null)
  755. {
  756. return Json(new
  757. {
  758. error = "10",
  759. content = "Timeout"
  760. });
  761. }
  762. if (user.role != Common.UserRole.Admin)
  763. {
  764. return Json(new
  765. {
  766. error = "10",
  767. content = "Timeout"
  768. });
  769. }
  770. try
  771. {
  772. //formData.append('dbName', $("#dbName").val());
  773. //formData.append('svCode', $("#serviceCode").val());
  774. //formData.append('connectionString', $("#connectionString").val());
  775. //formData.append('dbUserName', $("#dbUserName").val());
  776. //formData.append('dbPassword', $("#dbPassword").val());
  777. //formData.append('sqlReportDaily', $("#sqlReportDaily").val());
  778. //formData.append('sqlReportWeekly', $("#sqlReportWeekly").val());
  779. String svCode = Request.Form["svCode"];
  780. String dbName = Request.Form["dbName"];
  781. String connectionString = Request.Form["connectionString"];
  782. String dbUserName = Request.Form["dbUserName"];
  783. String dbPassword = Request.Form["dbPassword"];
  784. String sqlReportDaily = Request.Form["sqlReportDaily"];
  785. String sqlReportHourly = Request.Form["sqlReportHourly"];
  786. // call ws
  787. db.InsertSvReport(svCode, dbName, connectionString, dbUserName, dbPassword, sqlReportDaily, sqlReportHourly);
  788. // Returns message that successfully uploaded
  789. return Json(new
  790. {
  791. error_code = "0"
  792. });
  793. }
  794. catch (Exception ex)
  795. {
  796. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  797. }
  798. }
  799. [HttpPost]
  800. public ActionResult AddServiceAdv()
  801. {
  802. Users user = HttpContext.Session.GetComplexData<Users>("user");
  803. if (user == null)
  804. {
  805. return Json(new
  806. {
  807. error = "10",
  808. content = "Timeout"
  809. });
  810. }
  811. if (user.role != Common.UserRole.Admin)
  812. {
  813. return Json(new
  814. {
  815. error = "10",
  816. content = "Timeout"
  817. });
  818. }
  819. try
  820. {
  821. //formData.append('svCode', $("#serviceCode").val());
  822. //formData.append('advName', $("#advName").val());
  823. //formData.append('msgAdv', $("#msgAdv").val());
  824. //formData.append('channelAdv', $("#channelAdv").val());
  825. //formData.append('messageType', $("#messageType").val());
  826. //formData.append('fromMoney', $("#fromMoney").val());
  827. String svCode = Request.Form["svCode"];
  828. String advName = Request.Form["advName"];
  829. String msgAdv = Request.Form["msgAdv"];
  830. String channelAdv = Request.Form["channelAdv"];
  831. String messageType = Request.Form["messageType"];
  832. String fromMoney = Request.Form["fromMoney"];
  833. // call ws
  834. db.InsertSvAdv(svCode, msgAdv, advName, channelAdv, messageType, fromMoney);
  835. //db.InsertSvAdvHistory(svCode, messageType);
  836. // Returns message that successfully uploaded
  837. return Json(new
  838. {
  839. error_code = "0"
  840. });
  841. }
  842. catch (Exception ex)
  843. {
  844. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  845. }
  846. }
  847. [HttpPost]
  848. public ActionResult UpdateServiceInfo()
  849. {
  850. Users user = HttpContext.Session.GetComplexData<Users>("user");
  851. if (user == null)
  852. {
  853. return Json(new
  854. {
  855. error = "10",
  856. content = "Timeout"
  857. });
  858. }
  859. if (user.role != Common.UserRole.Admin)
  860. {
  861. return Json(new
  862. {
  863. error = "10",
  864. content = "Timeout"
  865. });
  866. }
  867. try
  868. {
  869. String serviceId = Request.Form["serviceId"];
  870. String serviceName = Request.Form["serviceName"];
  871. String serviceCode = Request.Form["serviceCode"];
  872. // call ws
  873. db.UpdateServiceInfo(serviceId, serviceCode, serviceName);
  874. return Json(new
  875. {
  876. error_code = "0"
  877. });
  878. }
  879. catch (Exception ex)
  880. {
  881. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  882. }
  883. }
  884. [HttpPost]
  885. public ActionResult UpdateServiceStatus()
  886. {
  887. Users user = HttpContext.Session.GetComplexData<Users>("user");
  888. if (user == null)
  889. {
  890. return Json(new
  891. {
  892. error = "10",
  893. content = "Timeout"
  894. });
  895. }
  896. if (user.role != Common.UserRole.Admin)
  897. {
  898. return Json(new
  899. {
  900. error = "10",
  901. content = "Timeout"
  902. });
  903. }
  904. try
  905. {
  906. String serviceId = Request.Form["serviceId"];
  907. String status = Request.Form["status"];
  908. // call ws
  909. db.UpdateServiceStatus(serviceId, status);
  910. return Json(new
  911. {
  912. error_code = "0"
  913. });
  914. }
  915. catch (Exception ex)
  916. {
  917. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  918. }
  919. }
  920. [HttpPost]
  921. public ActionResult UpdateServiceRp()
  922. {
  923. Users user = HttpContext.Session.GetComplexData<Users>("user");
  924. if (user == null)
  925. {
  926. return Json(new
  927. {
  928. error = "10",
  929. content = "Timeout"
  930. });
  931. }
  932. if (user.role != Common.UserRole.Admin)
  933. {
  934. return Json(new
  935. {
  936. error = "10",
  937. content = "Timeout"
  938. });
  939. }
  940. try
  941. {
  942. String svCode = Request.Form["svCode"];
  943. String dbName = Request.Form["dbName"];
  944. String connectionString = Request.Form["connectionString"];
  945. String dbUserName = Request.Form["dbUserName"];
  946. String dbPassword = Request.Form["dbPassword"];
  947. String sqlReportDaily = Request.Form["sqlReportDaily"];
  948. String sqlReportHourly = Request.Form["sqlReportHourly"];
  949. db.UpdateServiceRpInfo(svCode, dbName, connectionString, dbUserName, dbPassword, sqlReportDaily, sqlReportHourly);
  950. return Json(new
  951. {
  952. error_code = "0"
  953. });
  954. }
  955. catch (Exception ex)
  956. {
  957. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  958. }
  959. }
  960. [HttpPost]
  961. public ActionResult UpdateServiceRpStatus(String svCode, String status)
  962. {
  963. Users user = HttpContext.Session.GetComplexData<Users>("user");
  964. if (user == null)
  965. {
  966. return Json(new
  967. {
  968. error = "10",
  969. content = "Timeout"
  970. });
  971. }
  972. if (user.role != Common.UserRole.Admin)
  973. {
  974. return Json(new
  975. {
  976. error = "10",
  977. content = "Timeout"
  978. });
  979. }
  980. try
  981. {
  982. db.UpdateServiceRpStatus(svCode, status);
  983. return Json(new
  984. {
  985. error_code = "0"
  986. });
  987. }
  988. catch (Exception ex)
  989. {
  990. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  991. }
  992. }
  993. [HttpPost]
  994. public ActionResult UpdateServiceAdv()
  995. {
  996. Users user = HttpContext.Session.GetComplexData<Users>("user");
  997. if (user == null)
  998. {
  999. return Json(new
  1000. {
  1001. error = "10",
  1002. content = "Timeout"
  1003. });
  1004. }
  1005. if (user.role != Common.UserRole.Admin)
  1006. {
  1007. return Json(new
  1008. {
  1009. error = "10",
  1010. content = "Timeout"
  1011. });
  1012. }
  1013. try
  1014. {
  1015. String advId = Request.Form["advId"];
  1016. String svCode = Request.Form["svCode"];
  1017. String advName = Request.Form["advName"];
  1018. String msgAdv = Request.Form["msgAdv"];
  1019. String channelAdv = Request.Form["channelAdv"];
  1020. String messageType = Request.Form["messageType"];
  1021. String fromMoney = Request.Form["fromMoney"];
  1022. db.UpdateServiceAdvInfo(svCode, msgAdv, advName, channelAdv, messageType, fromMoney, advId);
  1023. return Json(new
  1024. {
  1025. error_code = "0"
  1026. });
  1027. }
  1028. catch (Exception ex)
  1029. {
  1030. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1031. }
  1032. }
  1033. [HttpPost]
  1034. public ActionResult UpdateServiceAdvStatus(String advId, String status)
  1035. {
  1036. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1037. if (user == null)
  1038. {
  1039. return Json(new
  1040. {
  1041. error = "10",
  1042. content = "Timeout"
  1043. });
  1044. }
  1045. if (user.role != Common.UserRole.Admin)
  1046. {
  1047. return Json(new
  1048. {
  1049. error = "10",
  1050. content = "Timeout"
  1051. });
  1052. }
  1053. try
  1054. {
  1055. // get adv info
  1056. Services sv = db.GetServiceAdvById(advId);
  1057. if (status == "0")
  1058. {
  1059. // update end time adv
  1060. //db.UpdateServiceAdvEndTime(sv.sv_code);
  1061. }
  1062. else
  1063. {
  1064. // insert new adv
  1065. //db.InsertSvAdvHistory(sv.sv_code, sv.message_type);
  1066. }
  1067. db.UpdateServiceAdvStatus(advId, status);
  1068. return Json(new
  1069. {
  1070. error_code = "0"
  1071. });
  1072. }
  1073. catch (Exception ex)
  1074. {
  1075. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1076. }
  1077. }
  1078. //
  1079. // BROADCAST
  1080. //
  1081. [HttpPost]
  1082. public JsonResult SearchBroadcast(String fromDate, String toDate)
  1083. {
  1084. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1085. if (user == null)
  1086. {
  1087. return Json(new
  1088. {
  1089. error = "10",
  1090. content = "Timeout"
  1091. });
  1092. }
  1093. if (user.role != Common.UserRole.Admin)
  1094. {
  1095. return Json(new
  1096. {
  1097. error = "10",
  1098. content = "Timeout"
  1099. });
  1100. }
  1101. List<Broadcast> listBroadcast = GetBroadcast(fromDate, toDate);
  1102. return Json(new
  1103. {
  1104. error = "0",
  1105. listBroadcast = listBroadcast
  1106. });
  1107. }
  1108. private List<Broadcast> GetBroadcast(String fromdate, String todate)
  1109. {
  1110. DateTime? fr = null;
  1111. if (fromdate != null) fr = DateTime.ParseExact(fromdate, "dd/MM/yyyy", null);
  1112. DateTime? td = null;
  1113. if (todate != null) DateTime.ParseExact(todate, "dd/MM/yyyy", null);
  1114. return db.LoadListBroadcast(fr, td);
  1115. }
  1116. public ActionResult Broadcast()
  1117. {
  1118. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1119. if (user == null)
  1120. {
  1121. ViewBag.username = "Welcome!";
  1122. return Redirect(subDomain + "/Home/Login");
  1123. }
  1124. if (user.role != Common.UserRole.Admin)
  1125. {
  1126. HttpContext.Session.Clear();
  1127. ViewBag.username = "Welcome!";
  1128. return Redirect(subDomain + "/Home/Login");
  1129. }
  1130. List<Broadcast> res = GetBroadcast(DateTime.Now.AddDays(-30).ToString("dd/MM/yyyy"), DateTime.Now.ToString("dd/MM/yyyy"));
  1131. return View(res);
  1132. }
  1133. //-------------
  1134. // SMSGW
  1135. //--------------
  1136. public ActionResult Smsgw()
  1137. {
  1138. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1139. if (user == null)
  1140. {
  1141. ViewBag.username = "Welcome!";
  1142. return Redirect(subDomain + "/Home/Login");
  1143. }
  1144. if (user.role != Common.UserRole.Admin)
  1145. {
  1146. HttpContext.Session.Clear();
  1147. ViewBag.username = "Welcome!";
  1148. return Redirect(subDomain + "/Home/Login");
  1149. }
  1150. List<WebserviceObj> res = GetSmsgw();
  1151. return View(res);
  1152. }
  1153. [HttpPost]
  1154. public JsonResult SearchSmsgw()
  1155. {
  1156. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1157. if (user == null)
  1158. {
  1159. return Json(new
  1160. {
  1161. error = "10",
  1162. content = "Timeout"
  1163. });
  1164. }
  1165. if (user.role != Common.UserRole.Admin)
  1166. {
  1167. return Json(new
  1168. {
  1169. error = "10",
  1170. content = "Timeout"
  1171. });
  1172. }
  1173. List<WebserviceObj> listSmsgw = GetSmsgw();
  1174. return Json(new
  1175. {
  1176. error = "0",
  1177. listSmsgw = listSmsgw
  1178. });
  1179. }
  1180. private List<WebserviceObj> GetSmsgw()
  1181. {
  1182. return db.LoadListWebserivce("sendmt");
  1183. }
  1184. [HttpPost]
  1185. public ActionResult AddSmsgw(IFormFile msgTemplate)
  1186. {
  1187. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1188. if (user == null)
  1189. {
  1190. return Json(new
  1191. {
  1192. error = "10",
  1193. content = "Timeout"
  1194. });
  1195. }
  1196. if (user.role != Common.UserRole.Admin)
  1197. {
  1198. return Json(new
  1199. {
  1200. error = "10",
  1201. content = "Timeout"
  1202. });
  1203. }
  1204. try
  1205. {
  1206. //int countSub = 0;
  1207. //string importFile = "";
  1208. String wsCode = Request.Form["wsCode"];
  1209. String wsName = Request.Form["wsName"];
  1210. String wsdl = Request.Form["wsdl"];
  1211. String msgTemplateStr = "";// Request.Form["msgTemplate"];
  1212. // insert DB
  1213. WebserviceObj wsObj = new WebserviceObj();
  1214. wsObj.ws_code = wsCode;
  1215. wsObj.ws_name = wsName;
  1216. wsObj.wsdl = wsdl;
  1217. // Get all files from Request object
  1218. if (msgTemplate != null)
  1219. {
  1220. using (StreamReader inputStreamReader = new StreamReader(msgTemplate.OpenReadStream()))
  1221. {
  1222. msgTemplateStr = inputStreamReader.ReadToEnd();
  1223. }
  1224. }
  1225. wsObj.msg_template = msgTemplateStr;
  1226. db.InsertWebservice(wsObj);
  1227. // Returns message that successfully uploaded
  1228. return Json(new
  1229. {
  1230. error = "0",
  1231. id = wsObj.ws_id
  1232. });
  1233. }
  1234. catch (Exception ex)
  1235. {
  1236. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  1237. }
  1238. }
  1239. [HttpPost]
  1240. public ActionResult UpdateSmsgw(IFormFile msgTemplate)
  1241. {
  1242. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1243. if (user == null)
  1244. {
  1245. return Json(new
  1246. {
  1247. error = "10",
  1248. content = "Timeout"
  1249. });
  1250. }
  1251. if (user.role != Common.UserRole.Admin)
  1252. {
  1253. return Json(new
  1254. {
  1255. error = "10",
  1256. content = "Timeout"
  1257. });
  1258. }
  1259. try
  1260. {
  1261. String wsCode = Request.Form["wsCode"];
  1262. String wsName = Request.Form["wsName"];
  1263. String wsdl = Request.Form["wsdl"];
  1264. String msgTemplateStr = "";// Request.Form["msgTemplate"];
  1265. String id = Request.Form["id"];
  1266. // insert DB
  1267. WebserviceObj wsObj = new WebserviceObj();
  1268. wsObj.ws_code = wsCode;
  1269. wsObj.ws_name = wsName;
  1270. wsObj.wsdl = wsdl;
  1271. // Get all files from Request object
  1272. if (msgTemplate != null)
  1273. {
  1274. using (StreamReader inputStreamReader = new StreamReader(msgTemplate.OpenReadStream()))
  1275. {
  1276. msgTemplateStr = inputStreamReader.ReadToEnd();
  1277. }
  1278. }
  1279. wsObj.msg_template = msgTemplateStr;
  1280. wsObj.ws_id = int.Parse(id);
  1281. db.UpdateWebservice(wsObj);
  1282. return Json(new
  1283. {
  1284. error = "0",
  1285. content = "Success"
  1286. });
  1287. }
  1288. catch (Exception ex)
  1289. {
  1290. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  1291. }
  1292. }
  1293. [HttpPost]
  1294. public ActionResult UpdateSmsgwStatus()
  1295. {
  1296. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1297. if (user == null)
  1298. {
  1299. return Json(new
  1300. {
  1301. error = "10",
  1302. content = "Timeout"
  1303. });
  1304. }
  1305. if (user.role != Common.UserRole.Admin)
  1306. {
  1307. return Json(new
  1308. {
  1309. error = "10",
  1310. content = "Timeout"
  1311. });
  1312. }
  1313. try
  1314. {
  1315. String status = Request.Form["status"];
  1316. int id = int.Parse(Request.Form["id"]);
  1317. //WebserviceObj wsObj = db.GetWebserviceById(id)[0];
  1318. db.UpdateWebserviceStatus(id, status);
  1319. return Json(new
  1320. {
  1321. error = "0",
  1322. content = "Success"
  1323. });
  1324. }
  1325. catch (Exception ex)
  1326. {
  1327. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  1328. }
  1329. }
  1330. [HttpPost]
  1331. public JsonResult GetSmsgwById(String id)
  1332. {
  1333. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1334. if (user == null)
  1335. {
  1336. return Json(new
  1337. {
  1338. error = "10",
  1339. content = "Timeout"
  1340. });
  1341. }
  1342. if (user.role != Common.UserRole.Admin)
  1343. {
  1344. return Json(new
  1345. {
  1346. error = "10",
  1347. content = "Timeout"
  1348. });
  1349. }
  1350. WebserviceObj wsObj = db.GetWebserviceById(int.Parse(id))[0];
  1351. return Json(new
  1352. {
  1353. error = "0",
  1354. smsgw = wsObj
  1355. });
  1356. }
  1357. //----------------
  1358. // SERVICE ADV SHCEDULE
  1359. //----------------
  1360. public ActionResult ServiceAdvScheduler(int? month, int? year, int? codeType)
  1361. {
  1362. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1363. if (user == null)
  1364. {
  1365. ViewBag.username = "Welcome!";
  1366. return Redirect(subDomain + "/Home/Login");
  1367. }
  1368. if (user.role != Common.UserRole.Admin)
  1369. {
  1370. HttpContext.Session.Clear();
  1371. ViewBag.username = "Welcome!";
  1372. return Redirect(subDomain + "/Home/Login");
  1373. }
  1374. if (month == null)
  1375. {
  1376. month = DateTime.Now.Month;
  1377. }
  1378. if (year == null)
  1379. {
  1380. year = DateTime.Now.Year;
  1381. }
  1382. List<SvAdvSchedule> listService = db.LoadListSvAdvSchedule(month.Value, year.Value, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1383. ViewBag.codeType = codeType;
  1384. return View(listService);
  1385. }
  1386. [HttpPost]
  1387. public JsonResult SearchSvAdvSchedule(int month, int year, int? codeType)
  1388. {
  1389. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1390. if (user == null)
  1391. {
  1392. return Json(new
  1393. {
  1394. error = "10",
  1395. content = "Timeout"
  1396. });
  1397. }
  1398. if (user.role != Common.UserRole.Admin)
  1399. {
  1400. return Json(new
  1401. {
  1402. error = "10",
  1403. content = "Timeout"
  1404. });
  1405. }
  1406. List<SvAdvSchedule> listService = db.LoadListSvAdvSchedule(month, year, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1407. return Json(new
  1408. {
  1409. error = "0",
  1410. content = "Success",
  1411. listService = listService
  1412. });
  1413. }
  1414. [HttpPost]
  1415. public JsonResult GetSvAdvScheduleById(String scheduleId, int? codeType)
  1416. {
  1417. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1418. if (user == null)
  1419. {
  1420. return Json(new
  1421. {
  1422. error = "10",
  1423. content = "Timeout"
  1424. });
  1425. }
  1426. if (user.role != Common.UserRole.Admin)
  1427. {
  1428. return Json(new
  1429. {
  1430. error = "10",
  1431. content = "Timeout"
  1432. });
  1433. }
  1434. SvAdvSchedule service = db.GetSvAdvScheduleById(scheduleId, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1435. return Json(new
  1436. {
  1437. error = "0",
  1438. content = "Success",
  1439. service = service
  1440. });
  1441. }
  1442. [HttpPost]
  1443. public ActionResult AddSvAdvSchedule()
  1444. {
  1445. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1446. if (user == null)
  1447. {
  1448. return Json(new
  1449. {
  1450. error = "10",
  1451. content = "Timeout"
  1452. });
  1453. }
  1454. if (user.role != Common.UserRole.Admin)
  1455. {
  1456. return Json(new
  1457. {
  1458. error = "10",
  1459. content = "Timeout"
  1460. });
  1461. }
  1462. try
  1463. {
  1464. String scheduleName = Request.Form["scheduleName"];
  1465. String fromDate = Request.Form["fromDate"];
  1466. String toDate = Request.Form["toDate"];
  1467. String listAdv = Request.Form["listAdv"];
  1468. String codeType = Request.Form["codeType"];
  1469. Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(listAdv);
  1470. SvAdvSchedule advSchedule = new SvAdvSchedule();
  1471. advSchedule.from_date = DateTime.ParseExact(fromDate, "dd/MM/yyyy HH:mm:ss", null);
  1472. advSchedule.to_date = DateTime.ParseExact(toDate, "dd/MM/yyyy HH:mm:ss", null);
  1473. advSchedule.schedule_name = scheduleName;
  1474. advSchedule.list_adv = new List<SvAdv>();
  1475. foreach (ListAdv adv in myDeserializedClass.listAdv)
  1476. {
  1477. SvAdv svAdv = new SvAdv();
  1478. svAdv.id = int.Parse(adv.id);
  1479. svAdv.percent = int.Parse(adv.percent);
  1480. if (svAdv.percent > 0)
  1481. {
  1482. advSchedule.list_adv.Add(svAdv);
  1483. }
  1484. }
  1485. // insert
  1486. if (db.InsertSvAdvSchedule(advSchedule, int.Parse(codeType)))
  1487. {
  1488. // Returns message that successfully uploaded
  1489. return Json(new
  1490. {
  1491. error_code = "0"
  1492. });
  1493. }
  1494. else
  1495. {
  1496. // Returns message that successfully uploaded
  1497. return Json(new
  1498. {
  1499. error_code = "1",
  1500. error_content = "Error database"
  1501. });
  1502. }
  1503. }
  1504. catch (Exception ex)
  1505. {
  1506. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1507. }
  1508. }
  1509. [HttpPost]
  1510. public ActionResult UpdateSvAdvSchedule()
  1511. {
  1512. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1513. if (user == null)
  1514. {
  1515. return Json(new
  1516. {
  1517. error = "10",
  1518. content = "Timeout"
  1519. });
  1520. }
  1521. if (user.role != Common.UserRole.Admin)
  1522. {
  1523. return Json(new
  1524. {
  1525. error = "10",
  1526. content = "Timeout"
  1527. });
  1528. }
  1529. try
  1530. {
  1531. String scheduleId = Request.Form["scheduleId"];
  1532. String scheduleName = Request.Form["scheduleName"];
  1533. String fromDate = Request.Form["fromDate"];
  1534. String toDate = Request.Form["toDate"];
  1535. String listAdv = Request.Form["listAdv"];
  1536. String codeType = Request.Form["codeType"];
  1537. //JavaScriptSerializer json_serializer = new JavaScriptSerializer();
  1538. //SvAdvJson[] svAdvs = (SvAdvJson[])json_serializer.DeserializeObject(listAdv);
  1539. Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(listAdv);
  1540. SvAdvSchedule advSchedule = new SvAdvSchedule();
  1541. advSchedule.from_date = DateTime.ParseExact(fromDate, "dd/MM/yyyy HH:mm:ss", null);
  1542. advSchedule.to_date = DateTime.ParseExact(toDate, "dd/MM/yyyy HH:mm:ss", null);
  1543. advSchedule.schedule_name = scheduleName;
  1544. advSchedule.id = int.Parse(scheduleId);
  1545. advSchedule.list_adv = new List<SvAdv>();
  1546. foreach (ListAdv adv in myDeserializedClass.listAdv)
  1547. {
  1548. SvAdv svAdv = new SvAdv();
  1549. svAdv.id = int.Parse(adv.id);
  1550. svAdv.percent = int.Parse(adv.percent);
  1551. if (svAdv.percent > 0)
  1552. {
  1553. advSchedule.list_adv.Add(svAdv);
  1554. }
  1555. }
  1556. // insert
  1557. if (db.UpdateSvAdvScheduleInfo(advSchedule, int.Parse(codeType)))
  1558. {
  1559. return Json(new
  1560. {
  1561. error_code = "0"
  1562. });
  1563. }
  1564. else
  1565. {
  1566. return Json(new
  1567. {
  1568. error_code = "1",
  1569. error_content = "Error database"
  1570. });
  1571. }
  1572. }
  1573. catch (Exception ex)
  1574. {
  1575. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1576. }
  1577. }
  1578. [HttpPost]
  1579. public ActionResult UpdateSvAdvScheduleStatus(String scheduleid, String status, String codeType)
  1580. {
  1581. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1582. if (user == null)
  1583. {
  1584. return Json(new
  1585. {
  1586. error = "10",
  1587. content = "Timeout"
  1588. });
  1589. }
  1590. if (user.role != Common.UserRole.Admin)
  1591. {
  1592. return Json(new
  1593. {
  1594. error = "10",
  1595. content = "Timeout"
  1596. });
  1597. }
  1598. try
  1599. {
  1600. db.UpdateSvAdvScheduleStatus(scheduleid, status, int.Parse(codeType));
  1601. return Json(new
  1602. {
  1603. error_code = "0"
  1604. });
  1605. }
  1606. catch (Exception ex)
  1607. {
  1608. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1609. }
  1610. }
  1611. public ActionResult GetServiceAdvPartial(String scheduleId, int? codeType)
  1612. {
  1613. ViewBag.codeType = codeType;
  1614. if (scheduleId == null)
  1615. {
  1616. List<SvAdv> listAdv = db.LoadListServicesAdv();
  1617. SvAdvSchedule scheduler = new SvAdvSchedule();
  1618. scheduler.list_adv = listAdv;
  1619. return PartialView("_ScheduleDetail", scheduler);
  1620. }
  1621. else
  1622. {
  1623. SvAdvSchedule scheduler = db.GetSvAdvScheduleById(scheduleId, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1624. return PartialView("_ScheduleDetail", scheduler);
  1625. }
  1626. }
  1627. // counter
  1628. public ActionResult ServiceAdvCounter(int? month, int? year, int? codeType)
  1629. {
  1630. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1631. if (user == null)
  1632. {
  1633. ViewBag.username = "Welcome!";
  1634. return Redirect(subDomain + "/Home/Login");
  1635. }
  1636. if (user.role != Common.UserRole.Admin)
  1637. {
  1638. HttpContext.Session.Clear();
  1639. ViewBag.username = "Welcome!";
  1640. return Redirect(subDomain + "/Home/Login");
  1641. }
  1642. if (month == null)
  1643. {
  1644. month = DateTime.Now.Month;
  1645. }
  1646. if (year == null)
  1647. {
  1648. year = DateTime.Now.Year;
  1649. }
  1650. List<SvAdv> listService = db.LoadListSvAdvCounter(month.Value, year.Value, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1651. ViewBag.codeType = codeType;
  1652. return View(listService);
  1653. }
  1654. [HttpPost]
  1655. public JsonResult SearchSvAdvCounter(int month, int year, int? codeType)
  1656. {
  1657. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1658. if (user == null)
  1659. {
  1660. return Json(new
  1661. {
  1662. error = "10",
  1663. content = "Timeout"
  1664. });
  1665. }
  1666. if (user.role != Common.UserRole.Admin)
  1667. {
  1668. return Json(new
  1669. {
  1670. error = "10",
  1671. content = "Timeout"
  1672. });
  1673. }
  1674. List<SvAdv> listService = db.LoadListSvAdvCounter(month, year, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1675. return Json(new
  1676. {
  1677. error = "0",
  1678. content = "Success",
  1679. listService = listService
  1680. });
  1681. }
  1682. }
  1683. }