AdminController.cs 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913
  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 activeHour = Request.Form["activeHour"];
  833. String maxNumberMsg = Request.Form["maxNumberMsg"];
  834. if (activeHour != null)
  835. {
  836. activeHour = activeHour.Replace(" ", "");
  837. }
  838. String fromMoney = Request.Form["fromMoney"];
  839. // call ws
  840. bool isSuccess = db.InsertSvAdv(svCode, msgAdv, advName, channelAdv, messageType, activeHour, maxNumberMsg, fromMoney);
  841. //db.InsertSvAdvHistory(svCode, messageType);
  842. // Returns message that successfully uploaded
  843. if (isSuccess)
  844. {
  845. return Json(new { error_code = "0", content = "Add service adv success" });
  846. }
  847. else
  848. {
  849. return Json(new { error_code = "2", content = "Add service adv failed! DB error." });
  850. }
  851. }
  852. catch (Exception ex)
  853. {
  854. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  855. }
  856. }
  857. [HttpPost]
  858. public ActionResult UpdateServiceInfo()
  859. {
  860. Users user = HttpContext.Session.GetComplexData<Users>("user");
  861. if (user == null)
  862. {
  863. return Json(new
  864. {
  865. error = "10",
  866. content = "Timeout"
  867. });
  868. }
  869. if (user.role != Common.UserRole.Admin)
  870. {
  871. return Json(new
  872. {
  873. error = "10",
  874. content = "Timeout"
  875. });
  876. }
  877. try
  878. {
  879. String serviceId = Request.Form["serviceId"];
  880. String serviceName = Request.Form["serviceName"];
  881. String serviceCode = Request.Form["serviceCode"];
  882. // call ws
  883. db.UpdateServiceInfo(serviceId, serviceCode, serviceName);
  884. return Json(new
  885. {
  886. error_code = "0"
  887. });
  888. }
  889. catch (Exception ex)
  890. {
  891. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  892. }
  893. }
  894. [HttpPost]
  895. public ActionResult UpdateServiceStatus()
  896. {
  897. Users user = HttpContext.Session.GetComplexData<Users>("user");
  898. if (user == null)
  899. {
  900. return Json(new
  901. {
  902. error = "10",
  903. content = "Timeout"
  904. });
  905. }
  906. if (user.role != Common.UserRole.Admin)
  907. {
  908. return Json(new
  909. {
  910. error = "10",
  911. content = "Timeout"
  912. });
  913. }
  914. try
  915. {
  916. String serviceId = Request.Form["serviceId"];
  917. String status = Request.Form["status"];
  918. // call ws
  919. db.UpdateServiceStatus(serviceId, status);
  920. return Json(new
  921. {
  922. error_code = "0"
  923. });
  924. }
  925. catch (Exception ex)
  926. {
  927. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  928. }
  929. }
  930. [HttpPost]
  931. public ActionResult UpdateServiceRp()
  932. {
  933. Users user = HttpContext.Session.GetComplexData<Users>("user");
  934. if (user == null)
  935. {
  936. return Json(new
  937. {
  938. error = "10",
  939. content = "Timeout"
  940. });
  941. }
  942. if (user.role != Common.UserRole.Admin)
  943. {
  944. return Json(new
  945. {
  946. error = "10",
  947. content = "Timeout"
  948. });
  949. }
  950. try
  951. {
  952. String svCode = Request.Form["svCode"];
  953. String dbName = Request.Form["dbName"];
  954. String connectionString = Request.Form["connectionString"];
  955. String dbUserName = Request.Form["dbUserName"];
  956. String dbPassword = Request.Form["dbPassword"];
  957. String sqlReportDaily = Request.Form["sqlReportDaily"];
  958. String sqlReportHourly = Request.Form["sqlReportHourly"];
  959. db.UpdateServiceRpInfo(svCode, dbName, connectionString, dbUserName, dbPassword, sqlReportDaily, sqlReportHourly);
  960. return Json(new
  961. {
  962. error_code = "0"
  963. });
  964. }
  965. catch (Exception ex)
  966. {
  967. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  968. }
  969. }
  970. [HttpPost]
  971. public ActionResult UpdateServiceRpStatus(String svCode, String status)
  972. {
  973. Users user = HttpContext.Session.GetComplexData<Users>("user");
  974. if (user == null)
  975. {
  976. return Json(new
  977. {
  978. error = "10",
  979. content = "Timeout"
  980. });
  981. }
  982. if (user.role != Common.UserRole.Admin)
  983. {
  984. return Json(new
  985. {
  986. error = "10",
  987. content = "Timeout"
  988. });
  989. }
  990. try
  991. {
  992. db.UpdateServiceRpStatus(svCode, status);
  993. return Json(new
  994. {
  995. error_code = "0"
  996. });
  997. }
  998. catch (Exception ex)
  999. {
  1000. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1001. }
  1002. }
  1003. [HttpPost]
  1004. public ActionResult UpdateServiceAdv()
  1005. {
  1006. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1007. if (user == null)
  1008. {
  1009. return Json(new
  1010. {
  1011. error = "10",
  1012. content = "Timeout"
  1013. });
  1014. }
  1015. if (user.role != Common.UserRole.Admin)
  1016. {
  1017. return Json(new
  1018. {
  1019. error = "10",
  1020. content = "Timeout"
  1021. });
  1022. }
  1023. try
  1024. {
  1025. String advId = Request.Form["advId"];
  1026. String svCode = Request.Form["svCode"];
  1027. String advName = Request.Form["advName"];
  1028. String msgAdv = Request.Form["msgAdv"];
  1029. String channelAdv = Request.Form["channelAdv"];
  1030. String messageType = Request.Form["messageType"];
  1031. String activeHour = Request.Form["activeHour"];
  1032. String maxNumberMsg = Request.Form["maxNumberMsg"];
  1033. if (activeHour != null)
  1034. {
  1035. activeHour = activeHour.Replace(" ", "");
  1036. }
  1037. String fromMoney = Request.Form["fromMoney"];
  1038. bool isSuccess = db.UpdateServiceAdvInfo(svCode, msgAdv, advName, channelAdv, messageType, activeHour, maxNumberMsg, fromMoney, advId);
  1039. if (isSuccess)
  1040. {
  1041. return Json(new { error_code = "0", content = "Update service adv success" });
  1042. }
  1043. else
  1044. {
  1045. return Json(new { error_code = "2", content = "Update service adv failed! DB error." });
  1046. }
  1047. }
  1048. catch (Exception ex)
  1049. {
  1050. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1051. }
  1052. }
  1053. [HttpPost]
  1054. public ActionResult UpdateServiceAdvStatus(String advId, String status)
  1055. {
  1056. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1057. if (user == null)
  1058. {
  1059. return Json(new
  1060. {
  1061. error = "10",
  1062. content = "Timeout"
  1063. });
  1064. }
  1065. if (user.role != Common.UserRole.Admin)
  1066. {
  1067. return Json(new
  1068. {
  1069. error = "10",
  1070. content = "Timeout"
  1071. });
  1072. }
  1073. try
  1074. {
  1075. // get adv info
  1076. Services sv = db.GetServiceAdvById(advId);
  1077. if (status == "0")
  1078. {
  1079. // update end time adv
  1080. //db.UpdateServiceAdvEndTime(sv.sv_code);
  1081. }
  1082. else
  1083. {
  1084. // insert new adv
  1085. //db.InsertSvAdvHistory(sv.sv_code, sv.message_type);
  1086. }
  1087. db.UpdateServiceAdvStatus(advId, status);
  1088. return Json(new
  1089. {
  1090. error_code = "0"
  1091. });
  1092. }
  1093. catch (Exception ex)
  1094. {
  1095. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1096. }
  1097. }
  1098. //
  1099. // BROADCAST
  1100. //
  1101. [HttpPost]
  1102. public JsonResult SearchBroadcast(String fromDate, String toDate)
  1103. {
  1104. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1105. if (user == null)
  1106. {
  1107. return Json(new
  1108. {
  1109. error = "10",
  1110. content = "Timeout"
  1111. });
  1112. }
  1113. if (user.role != Common.UserRole.Admin)
  1114. {
  1115. return Json(new
  1116. {
  1117. error = "10",
  1118. content = "Timeout"
  1119. });
  1120. }
  1121. List<Broadcast> listBroadcast = GetBroadcast(fromDate, toDate);
  1122. return Json(new
  1123. {
  1124. error = "0",
  1125. listBroadcast = listBroadcast
  1126. });
  1127. }
  1128. private List<Broadcast> GetBroadcast(String fromdate, String todate)
  1129. {
  1130. DateTime? fr = null;
  1131. if (fromdate != null) fr = DateTime.ParseExact(fromdate, "dd/MM/yyyy", null);
  1132. DateTime? td = null;
  1133. if (todate != null) DateTime.ParseExact(todate, "dd/MM/yyyy", null);
  1134. return db.LoadListBroadcast(fr, td);
  1135. }
  1136. public ActionResult Broadcast()
  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<Broadcast> res = GetBroadcast(DateTime.Now.AddDays(-30).ToString("dd/MM/yyyy"), DateTime.Now.ToString("dd/MM/yyyy"));
  1151. return View(res);
  1152. }
  1153. //-------------
  1154. // SMSGW
  1155. //--------------
  1156. public ActionResult Smsgw()
  1157. {
  1158. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1159. if (user == null)
  1160. {
  1161. ViewBag.username = "Welcome!";
  1162. return Redirect(subDomain + "/Home/Login");
  1163. }
  1164. if (user.role != Common.UserRole.Admin)
  1165. {
  1166. HttpContext.Session.Clear();
  1167. ViewBag.username = "Welcome!";
  1168. return Redirect(subDomain + "/Home/Login");
  1169. }
  1170. List<WebserviceObj> res = GetSmsgw();
  1171. return View(res);
  1172. }
  1173. [HttpPost]
  1174. public JsonResult SearchSmsgw()
  1175. {
  1176. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1177. if (user == null)
  1178. {
  1179. return Json(new
  1180. {
  1181. error = "10",
  1182. content = "Timeout"
  1183. });
  1184. }
  1185. if (user.role != Common.UserRole.Admin)
  1186. {
  1187. return Json(new
  1188. {
  1189. error = "10",
  1190. content = "Timeout"
  1191. });
  1192. }
  1193. List<WebserviceObj> listSmsgw = GetSmsgw();
  1194. return Json(new
  1195. {
  1196. error = "0",
  1197. listSmsgw = listSmsgw
  1198. });
  1199. }
  1200. private List<WebserviceObj> GetSmsgw()
  1201. {
  1202. return db.LoadListWebserivce("sendmt");
  1203. }
  1204. [HttpPost]
  1205. public ActionResult AddSmsgw(IFormFile msgTemplate)
  1206. {
  1207. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1208. if (user == null)
  1209. {
  1210. return Json(new
  1211. {
  1212. error = "10",
  1213. content = "Timeout"
  1214. });
  1215. }
  1216. if (user.role != Common.UserRole.Admin)
  1217. {
  1218. return Json(new
  1219. {
  1220. error = "10",
  1221. content = "Timeout"
  1222. });
  1223. }
  1224. try
  1225. {
  1226. //int countSub = 0;
  1227. //string importFile = "";
  1228. String wsCode = Request.Form["wsCode"];
  1229. String wsName = Request.Form["wsName"];
  1230. String wsdl = Request.Form["wsdl"];
  1231. String msgTemplateStr = "";// Request.Form["msgTemplate"];
  1232. // insert DB
  1233. WebserviceObj wsObj = new WebserviceObj();
  1234. wsObj.ws_code = wsCode;
  1235. wsObj.ws_name = wsName;
  1236. wsObj.wsdl = wsdl;
  1237. // Get all files from Request object
  1238. if (msgTemplate != null)
  1239. {
  1240. using (StreamReader inputStreamReader = new StreamReader(msgTemplate.OpenReadStream()))
  1241. {
  1242. msgTemplateStr = inputStreamReader.ReadToEnd();
  1243. }
  1244. }
  1245. wsObj.msg_template = msgTemplateStr;
  1246. db.InsertWebservice(wsObj);
  1247. // Returns message that successfully uploaded
  1248. return Json(new
  1249. {
  1250. error = "0",
  1251. id = wsObj.ws_id
  1252. });
  1253. }
  1254. catch (Exception ex)
  1255. {
  1256. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  1257. }
  1258. }
  1259. [HttpPost]
  1260. public ActionResult UpdateSmsgw(IFormFile msgTemplate)
  1261. {
  1262. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1263. if (user == null)
  1264. {
  1265. return Json(new
  1266. {
  1267. error = "10",
  1268. content = "Timeout"
  1269. });
  1270. }
  1271. if (user.role != Common.UserRole.Admin)
  1272. {
  1273. return Json(new
  1274. {
  1275. error = "10",
  1276. content = "Timeout"
  1277. });
  1278. }
  1279. try
  1280. {
  1281. String wsCode = Request.Form["wsCode"];
  1282. String wsName = Request.Form["wsName"];
  1283. String wsdl = Request.Form["wsdl"];
  1284. String msgTemplateStr = "";// Request.Form["msgTemplate"];
  1285. String id = Request.Form["id"];
  1286. // insert DB
  1287. WebserviceObj wsObj = new WebserviceObj();
  1288. wsObj.ws_code = wsCode;
  1289. wsObj.ws_name = wsName;
  1290. wsObj.wsdl = wsdl;
  1291. // Get all files from Request object
  1292. if (msgTemplate != null)
  1293. {
  1294. using (StreamReader inputStreamReader = new StreamReader(msgTemplate.OpenReadStream()))
  1295. {
  1296. msgTemplateStr = inputStreamReader.ReadToEnd();
  1297. }
  1298. }
  1299. wsObj.msg_template = msgTemplateStr;
  1300. wsObj.ws_id = int.Parse(id);
  1301. db.UpdateWebservice(wsObj);
  1302. return Json(new
  1303. {
  1304. error = "0",
  1305. content = "Success"
  1306. });
  1307. }
  1308. catch (Exception ex)
  1309. {
  1310. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  1311. }
  1312. }
  1313. [HttpPost]
  1314. public ActionResult UpdateSmsgwStatus()
  1315. {
  1316. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1317. if (user == null)
  1318. {
  1319. return Json(new
  1320. {
  1321. error = "10",
  1322. content = "Timeout"
  1323. });
  1324. }
  1325. if (user.role != Common.UserRole.Admin)
  1326. {
  1327. return Json(new
  1328. {
  1329. error = "10",
  1330. content = "Timeout"
  1331. });
  1332. }
  1333. try
  1334. {
  1335. String status = Request.Form["status"];
  1336. int id = int.Parse(Request.Form["id"]);
  1337. //WebserviceObj wsObj = db.GetWebserviceById(id)[0];
  1338. db.UpdateWebserviceStatus(id, status);
  1339. return Json(new
  1340. {
  1341. error = "0",
  1342. content = "Success"
  1343. });
  1344. }
  1345. catch (Exception ex)
  1346. {
  1347. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  1348. }
  1349. }
  1350. [HttpPost]
  1351. public JsonResult GetSmsgwById(String id)
  1352. {
  1353. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1354. if (user == null)
  1355. {
  1356. return Json(new
  1357. {
  1358. error = "10",
  1359. content = "Timeout"
  1360. });
  1361. }
  1362. if (user.role != Common.UserRole.Admin)
  1363. {
  1364. return Json(new
  1365. {
  1366. error = "10",
  1367. content = "Timeout"
  1368. });
  1369. }
  1370. WebserviceObj wsObj = db.GetWebserviceById(int.Parse(id))[0];
  1371. return Json(new
  1372. {
  1373. error = "0",
  1374. smsgw = wsObj
  1375. });
  1376. }
  1377. //----------------
  1378. // SERVICE ADV SHCEDULE
  1379. //----------------
  1380. public ActionResult ServiceAdvScheduler(int? month, int? year, int? codeType)
  1381. {
  1382. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1383. if (user == null)
  1384. {
  1385. ViewBag.username = "Welcome!";
  1386. return Redirect(subDomain + "/Home/Login");
  1387. }
  1388. if (user.role != Common.UserRole.Admin)
  1389. {
  1390. HttpContext.Session.Clear();
  1391. ViewBag.username = "Welcome!";
  1392. return Redirect(subDomain + "/Home/Login");
  1393. }
  1394. if (month == null)
  1395. {
  1396. month = DateTime.Now.Month;
  1397. }
  1398. if (year == null)
  1399. {
  1400. year = DateTime.Now.Year;
  1401. }
  1402. List<SvAdvSchedule> listService = db.LoadListSvAdvSchedule(month.Value, year.Value, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1403. ViewBag.codeType = codeType;
  1404. return View(listService);
  1405. }
  1406. [HttpPost]
  1407. public JsonResult SearchSvAdvSchedule(int month, int year, int? codeType)
  1408. {
  1409. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1410. if (user == null)
  1411. {
  1412. return Json(new
  1413. {
  1414. error = "10",
  1415. content = "Timeout"
  1416. });
  1417. }
  1418. if (user.role != Common.UserRole.Admin)
  1419. {
  1420. return Json(new
  1421. {
  1422. error = "10",
  1423. content = "Timeout"
  1424. });
  1425. }
  1426. List<SvAdvSchedule> listService = db.LoadListSvAdvSchedule(month, year, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1427. return Json(new
  1428. {
  1429. error = "0",
  1430. content = "Success",
  1431. listService = listService
  1432. });
  1433. }
  1434. [HttpPost]
  1435. public JsonResult GetSvAdvScheduleById(String scheduleId, int? codeType)
  1436. {
  1437. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1438. if (user == null)
  1439. {
  1440. return Json(new
  1441. {
  1442. error = "10",
  1443. content = "Timeout"
  1444. });
  1445. }
  1446. if (user.role != Common.UserRole.Admin)
  1447. {
  1448. return Json(new
  1449. {
  1450. error = "10",
  1451. content = "Timeout"
  1452. });
  1453. }
  1454. SvAdvSchedule service = db.GetSvAdvScheduleById(scheduleId, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1455. return Json(new
  1456. {
  1457. error = "0",
  1458. content = "Success",
  1459. service = service
  1460. });
  1461. }
  1462. [HttpPost]
  1463. public ActionResult AddSvAdvSchedule()
  1464. {
  1465. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1466. if (user == null)
  1467. {
  1468. return Json(new
  1469. {
  1470. error = "10",
  1471. content = "Timeout"
  1472. });
  1473. }
  1474. if (user.role != Common.UserRole.Admin)
  1475. {
  1476. return Json(new
  1477. {
  1478. error = "10",
  1479. content = "Timeout"
  1480. });
  1481. }
  1482. try
  1483. {
  1484. String scheduleName = Request.Form["scheduleName"];
  1485. String maxTotalMsg = Request.Form["maxTotalMsg"];
  1486. String fromDate = Request.Form["fromDate"];
  1487. String toDate = Request.Form["toDate"];
  1488. String listAdv = Request.Form["listAdv"];
  1489. String codeType = Request.Form["codeType"];
  1490. Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(listAdv);
  1491. SvAdvSchedule advSchedule = new SvAdvSchedule();
  1492. advSchedule.from_date = DateTime.ParseExact(fromDate, "dd/MM/yyyy HH:mm:ss", null);
  1493. advSchedule.to_date = DateTime.ParseExact(toDate, "dd/MM/yyyy HH:mm:ss", null);
  1494. advSchedule.schedule_name = scheduleName;
  1495. if (maxTotalMsg != null)
  1496. {
  1497. advSchedule.max_total_msg = int.Parse(maxTotalMsg);
  1498. }
  1499. else
  1500. {
  1501. advSchedule.max_total_msg = 0;
  1502. }
  1503. advSchedule.list_adv = new List<SvAdv>();
  1504. foreach (ListAdv adv in myDeserializedClass.listAdv)
  1505. {
  1506. SvAdv svAdv = new SvAdv();
  1507. svAdv.id = int.Parse(adv.id);
  1508. svAdv.percent = int.Parse(adv.percent);
  1509. if (svAdv.percent > 0)
  1510. {
  1511. advSchedule.list_adv.Add(svAdv);
  1512. }
  1513. }
  1514. // insert
  1515. if (db.InsertSvAdvSchedule(advSchedule, int.Parse(codeType)))
  1516. {
  1517. // Returns message that successfully uploaded
  1518. return Json(new
  1519. {
  1520. error_code = "0"
  1521. });
  1522. }
  1523. else
  1524. {
  1525. // Returns message that successfully uploaded
  1526. return Json(new
  1527. {
  1528. error_code = "1",
  1529. error_content = "Error database"
  1530. });
  1531. }
  1532. }
  1533. catch (Exception ex)
  1534. {
  1535. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1536. }
  1537. }
  1538. [HttpPost]
  1539. public ActionResult UpdateSvAdvSchedule()
  1540. {
  1541. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1542. if (user == null)
  1543. {
  1544. return Json(new
  1545. {
  1546. error = "10",
  1547. content = "Timeout"
  1548. });
  1549. }
  1550. if (user.role != Common.UserRole.Admin)
  1551. {
  1552. return Json(new
  1553. {
  1554. error = "10",
  1555. content = "Timeout"
  1556. });
  1557. }
  1558. try
  1559. {
  1560. String scheduleId = Request.Form["scheduleId"];
  1561. String scheduleName = Request.Form["scheduleName"];
  1562. String maxTotalMsg = Request.Form["maxTotalMsg"];
  1563. String fromDate = Request.Form["fromDate"];
  1564. String toDate = Request.Form["toDate"];
  1565. String listAdv = Request.Form["listAdv"];
  1566. String codeType = Request.Form["codeType"];
  1567. //JavaScriptSerializer json_serializer = new JavaScriptSerializer();
  1568. //SvAdvJson[] svAdvs = (SvAdvJson[])json_serializer.DeserializeObject(listAdv);
  1569. Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(listAdv);
  1570. SvAdvSchedule advSchedule = new SvAdvSchedule();
  1571. advSchedule.from_date = DateTime.ParseExact(fromDate, "dd/MM/yyyy HH:mm:ss", null);
  1572. advSchedule.to_date = DateTime.ParseExact(toDate, "dd/MM/yyyy HH:mm:ss", null);
  1573. advSchedule.schedule_name = scheduleName;
  1574. if (maxTotalMsg != null)
  1575. {
  1576. advSchedule.max_total_msg = int.Parse(maxTotalMsg);
  1577. }
  1578. else
  1579. {
  1580. advSchedule.max_total_msg = 0;
  1581. }
  1582. advSchedule.id = int.Parse(scheduleId);
  1583. advSchedule.list_adv = new List<SvAdv>();
  1584. foreach (ListAdv adv in myDeserializedClass.listAdv)
  1585. {
  1586. SvAdv svAdv = new SvAdv();
  1587. svAdv.id = int.Parse(adv.id);
  1588. svAdv.percent = int.Parse(adv.percent);
  1589. if (svAdv.percent > 0)
  1590. {
  1591. advSchedule.list_adv.Add(svAdv);
  1592. }
  1593. }
  1594. // insert
  1595. if (db.UpdateSvAdvScheduleInfo(advSchedule, int.Parse(codeType)))
  1596. {
  1597. return Json(new
  1598. {
  1599. error_code = "0"
  1600. });
  1601. }
  1602. else
  1603. {
  1604. return Json(new
  1605. {
  1606. error_code = "1",
  1607. error_content = "Error database"
  1608. });
  1609. }
  1610. }
  1611. catch (Exception ex)
  1612. {
  1613. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1614. }
  1615. }
  1616. [HttpPost]
  1617. public ActionResult UpdateSvAdvScheduleStatus(String scheduleid, String status, String codeType)
  1618. {
  1619. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1620. if (user == null)
  1621. {
  1622. return Json(new
  1623. {
  1624. error = "10",
  1625. content = "Timeout"
  1626. });
  1627. }
  1628. if (user.role != Common.UserRole.Admin)
  1629. {
  1630. return Json(new
  1631. {
  1632. error = "10",
  1633. content = "Timeout"
  1634. });
  1635. }
  1636. try
  1637. {
  1638. db.UpdateSvAdvScheduleStatus(scheduleid, status, int.Parse(codeType));
  1639. return Json(new
  1640. {
  1641. error_code = "0"
  1642. });
  1643. }
  1644. catch (Exception ex)
  1645. {
  1646. return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
  1647. }
  1648. }
  1649. public ActionResult GetServiceAdvPartial(String scheduleId, int? codeType)
  1650. {
  1651. ViewBag.codeType = codeType;
  1652. if (scheduleId == null)
  1653. {
  1654. List<SvAdv> listAdv = db.LoadListServicesAdv();
  1655. SvAdvSchedule scheduler = new SvAdvSchedule();
  1656. scheduler.list_adv = listAdv;
  1657. return PartialView("_ScheduleDetail", scheduler);
  1658. }
  1659. else
  1660. {
  1661. SvAdvSchedule scheduler = db.GetSvAdvScheduleById(scheduleId, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1662. return PartialView("_ScheduleDetail", scheduler);
  1663. }
  1664. }
  1665. // counter
  1666. public ActionResult ServiceAdvCounter(int? month, int? year, int? codeType)
  1667. {
  1668. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1669. if (user == null)
  1670. {
  1671. ViewBag.username = "Welcome!";
  1672. return Redirect(subDomain + "/Home/Login");
  1673. }
  1674. if (user.role != Common.UserRole.Admin)
  1675. {
  1676. HttpContext.Session.Clear();
  1677. ViewBag.username = "Welcome!";
  1678. return Redirect(subDomain + "/Home/Login");
  1679. }
  1680. if (month == null)
  1681. {
  1682. month = DateTime.Now.Month;
  1683. }
  1684. if (year == null)
  1685. {
  1686. year = DateTime.Now.Year;
  1687. }
  1688. List<SvAdv> listService = db.LoadListSvAdvCounter(month.Value, year.Value, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1689. ViewBag.codeType = codeType;
  1690. return View(listService);
  1691. }
  1692. [HttpPost]
  1693. public JsonResult SearchSvAdvCounter(int month, int year, int? codeType)
  1694. {
  1695. Users user = HttpContext.Session.GetComplexData<Users>("user");
  1696. if (user == null)
  1697. {
  1698. return Json(new
  1699. {
  1700. error = "10",
  1701. content = "Timeout"
  1702. });
  1703. }
  1704. if (user.role != Common.UserRole.Admin)
  1705. {
  1706. return Json(new
  1707. {
  1708. error = "10",
  1709. content = "Timeout"
  1710. });
  1711. }
  1712. List<SvAdv> listService = db.LoadListSvAdvCounter(month, year, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
  1713. return Json(new
  1714. {
  1715. error = "0",
  1716. content = "Success",
  1717. listService = listService
  1718. });
  1719. }
  1720. }
  1721. }