ScenarioController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. using Microsoft.AspNetCore.Hosting;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Configuration;
  4. using ReportWeb.Models;
  5. using SuperAdmin;
  6. using SuperAdmin.Controllers;
  7. using SuperAdmin.Source;
  8. using SuperCms.Extensions;
  9. using System;
  10. using System.Collections.Generic;
  11. namespace ReportWeb.Controllers
  12. {
  13. public class ScenarioController : BaseController
  14. {
  15. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  16. DbConnector db = new DbConnector();
  17. String sdf = "dd/MM/yyyy HH:mm";
  18. String df = "dd/MM/yyyy";
  19. public ScenarioController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
  20. {
  21. // init
  22. }
  23. public IActionResult Index()
  24. {
  25. return View();
  26. }
  27. public ActionResult ScenarioPlay()
  28. {
  29. Users user = HttpContext.Session.GetComplexData<Users>("user");
  30. if (user == null || (user.role <= 0))
  31. {
  32. ViewBag.username = "Welcome!";
  33. return Redirect(subDomain + "/Home/Login");
  34. }
  35. if (user.role != Common.UserRole.Admin)
  36. {
  37. return Redirect(subDomain + "/Home/Login");
  38. }
  39. return View();
  40. }
  41. [HttpPost]
  42. public ActionResult SearchScenario()
  43. {
  44. Users user = HttpContext.Session.GetComplexData<Users>("user");
  45. if (user == null || (user.role <= 0))
  46. {
  47. return Json(new
  48. {
  49. error = "10",
  50. content = "Timeout"
  51. });
  52. }
  53. if (user.role != Common.UserRole.Admin)
  54. {
  55. return Json(new
  56. {
  57. error = "10",
  58. content = "Timeout"
  59. });
  60. }
  61. List<ScenarioPlayObj> list = db.LoadListScenario();
  62. return PartialView("_ListMsisdn", list);
  63. //return Json(new
  64. //{
  65. // error = "0",
  66. // list = list
  67. //});
  68. }
  69. [HttpPost]
  70. public ActionResult AddUpdateScenario(ScenarioPlayObj scenario, int isUpdate)
  71. {
  72. Users user = HttpContext.Session.GetComplexData<Users>("user");
  73. if (user == null || (user.role <= 0))
  74. {
  75. return Json(new
  76. {
  77. error = "10",
  78. content = "Timeout"
  79. });
  80. }
  81. if (user.role != Common.UserRole.Admin)
  82. {
  83. return Json(new
  84. {
  85. error = "10",
  86. content = "Timeout"
  87. });
  88. }
  89. try
  90. {
  91. if (isUpdate > 0)
  92. {
  93. db.UpdateScenarioPlay(scenario);
  94. }
  95. else
  96. {
  97. db.InsertScenarioPlay(scenario);
  98. }
  99. // Returns message that successfully uploaded
  100. return Json(new
  101. {
  102. error = "0",
  103. scenarioId = scenario.id
  104. });
  105. }
  106. catch (Exception ex)
  107. {
  108. return Json(new
  109. {
  110. error = "2",
  111. content = "Error occurred. Error details: " + ex.Message
  112. });
  113. }
  114. }
  115. [HttpPost]
  116. public ActionResult UpdateScenarioStatus()
  117. {
  118. Users user = HttpContext.Session.GetComplexData<Users>("user");
  119. if (user == null || (user.role <= 0))
  120. {
  121. return Json(new
  122. {
  123. error = "10",
  124. content = "Timeout"
  125. });
  126. }
  127. if (user.role != Common.UserRole.Admin)
  128. {
  129. return Json(new
  130. {
  131. error = "10",
  132. content = "Timeout"
  133. });
  134. }
  135. try
  136. {
  137. String status = Request.Form["status"];
  138. int id = int.Parse(Request.Form["id"]);
  139. db.UpdateScenarioStatus(id, status);
  140. return Json(new
  141. {
  142. error = "0",
  143. content = "Success"
  144. });
  145. }
  146. catch (Exception ex)
  147. {
  148. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  149. }
  150. }
  151. [HttpPost]
  152. public JsonResult GetScenarioById(String id)
  153. {
  154. Users user = HttpContext.Session.GetComplexData<Users>("user");
  155. if (user == null || (user.role <= 0))
  156. {
  157. return Json(new
  158. {
  159. error = "10",
  160. content = "Timeout"
  161. });
  162. }
  163. if (user.role != Common.UserRole.Admin)
  164. {
  165. return Json(new
  166. {
  167. error = "10",
  168. content = "Timeout"
  169. });
  170. }
  171. ScenarioPlayObj scenario = db.GetScenarioById(int.Parse(id))[0];
  172. return Json(new
  173. {
  174. error = "0",
  175. scenario = scenario
  176. });
  177. }
  178. // LIST MSISDN
  179. public IActionResult ListMsisdn()
  180. {
  181. Users user = HttpContext.Session.GetComplexData<Users>("user");
  182. if (user == null || (user.role <= 0))
  183. {
  184. ViewBag.username = "Welcome!";
  185. return Redirect(subDomain + "/Home/Login");
  186. }
  187. if (user.role != Common.UserRole.Admin)
  188. {
  189. return Redirect(subDomain + "/Home/Login");
  190. }
  191. return View();
  192. }
  193. [HttpPost]
  194. public JsonResult SearchListMsisdn()
  195. {
  196. Users user = HttpContext.Session.GetComplexData<Users>("user");
  197. if (user == null || (user.role <= 0))
  198. {
  199. return Json(new
  200. {
  201. error = "10",
  202. content = "Timeout"
  203. });
  204. }
  205. if (user.role != Common.UserRole.Admin)
  206. {
  207. return Json(new
  208. {
  209. error = "10",
  210. content = "Timeout"
  211. });
  212. }
  213. List<PhoneInfo> list = db.LoadListMsisdn();
  214. return Json(new
  215. {
  216. error = "0",
  217. list = list
  218. });
  219. }
  220. [HttpPost]
  221. public IActionResult AddUpdateMsisdn(PhoneInfo obj, int isUpdate)
  222. {
  223. Users user = HttpContext.Session.GetComplexData<Users>("user");
  224. if (user == null || (user.role <= 0))
  225. {
  226. return Json(new
  227. {
  228. error = "10",
  229. content = "Timeout"
  230. });
  231. }
  232. if (user.role != Common.UserRole.Admin)
  233. {
  234. return Json(new
  235. {
  236. error = "10",
  237. content = "Timeout"
  238. });
  239. }
  240. try
  241. {
  242. if (isUpdate > 0)
  243. {
  244. db.UpdateListMsisdn(obj);
  245. }
  246. else
  247. {
  248. db.InsertListMsisdn(obj);
  249. }
  250. // Returns message that successfully uploaded
  251. return Json(new
  252. {
  253. error = "0"
  254. });
  255. }
  256. catch (Exception ex)
  257. {
  258. return Json(new
  259. {
  260. error = "2",
  261. content = "Error occurred. Error details: " + ex.Message
  262. });
  263. }
  264. }
  265. [HttpPost]
  266. public IActionResult UpdateMsisdnStatus()
  267. {
  268. Users user = HttpContext.Session.GetComplexData<Users>("user");
  269. if (user == null || (user.role <= 0))
  270. {
  271. return Json(new
  272. {
  273. error = "10",
  274. content = "Timeout"
  275. });
  276. }
  277. if (user.role != Common.UserRole.Admin)
  278. {
  279. return Json(new
  280. {
  281. error = "10",
  282. content = "Timeout"
  283. });
  284. }
  285. try
  286. {
  287. String status = Request.Form["status"];
  288. long id = long.Parse(Request.Form["id"]);
  289. db.UpdateListMsisdnStatus(id, status);
  290. return Json(new
  291. {
  292. error = "0",
  293. content = "Success"
  294. });
  295. }
  296. catch (Exception ex)
  297. {
  298. return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
  299. }
  300. }
  301. [HttpPost]
  302. public JsonResult GetListMsisdnById(String id)
  303. {
  304. Users user = HttpContext.Session.GetComplexData<Users>("user");
  305. if (user == null || (user.role <= 0))
  306. {
  307. return Json(new
  308. {
  309. error = "10",
  310. content = "Timeout"
  311. });
  312. }
  313. if (user.role != Common.UserRole.Admin)
  314. {
  315. return Json(new
  316. {
  317. error = "10",
  318. content = "Timeout"
  319. });
  320. }
  321. PhoneInfo data = db.GetListMsisdnById(id)[0];
  322. return Json(new
  323. {
  324. error = "0",
  325. data = data
  326. });
  327. }
  328. // CONFIGURATION
  329. public IActionResult Configure()
  330. {
  331. Users user = HttpContext.Session.GetComplexData<Users>("user");
  332. if (user == null || (user.role <= 0))
  333. {
  334. ViewBag.username = "Welcome!";
  335. return Redirect(subDomain + "/Home/Login");
  336. }
  337. if (user.role != Common.UserRole.Admin)
  338. {
  339. return Redirect(subDomain + "/Home/Login");
  340. }
  341. return View();
  342. }
  343. [HttpPost]
  344. public IActionResult SearchConfigure()
  345. {
  346. Users user = HttpContext.Session.GetComplexData<Users>("user");
  347. if (user == null || (user.role <= 0))
  348. {
  349. return Json(new
  350. {
  351. error = "10",
  352. content = "Timeout"
  353. });
  354. }
  355. if (user.role != Common.UserRole.Admin)
  356. {
  357. return Json(new
  358. {
  359. error = "10",
  360. content = "Timeout"
  361. });
  362. }
  363. List<ToolConfig> list = db.LoadListToolConfig();
  364. return PartialView("_Configure", list);
  365. //return Json(new
  366. //{
  367. // error = "0",
  368. // list = list
  369. //});
  370. }
  371. [HttpPost]
  372. public IActionResult AddUpdateConfigure(ToolConfig obj, int isUpdate)
  373. {
  374. Users user = HttpContext.Session.GetComplexData<Users>("user");
  375. if (user == null || (user.role <= 0))
  376. {
  377. return Json(new
  378. {
  379. error = "10",
  380. content = "Timeout"
  381. });
  382. }
  383. if (user.role != Common.UserRole.Admin)
  384. {
  385. return Json(new
  386. {
  387. error = "10",
  388. content = "Timeout"
  389. });
  390. }
  391. try
  392. {
  393. bool result = false;
  394. if (isUpdate > 0)
  395. {
  396. result = db.UpdateToolConfig(obj);
  397. }
  398. // Returns message that successfully uploaded
  399. if (result)
  400. {
  401. return Json(new
  402. {
  403. error = "0"
  404. });
  405. }
  406. else
  407. {
  408. return Json(new
  409. {
  410. error = "2",
  411. content = "DB Error"
  412. });
  413. }
  414. }
  415. catch (Exception ex)
  416. {
  417. return Json(new
  418. {
  419. error = "2",
  420. content = "Error occurred. Error details: " + ex.Message
  421. });
  422. }
  423. }
  424. [HttpPost]
  425. public JsonResult GetConfigureById(String id)
  426. {
  427. Users user = HttpContext.Session.GetComplexData<Users>("user");
  428. if (user == null || (user.role <= 0))
  429. {
  430. return Json(new
  431. {
  432. error = "10",
  433. content = "Timeout"
  434. });
  435. }
  436. if (user.role != Common.UserRole.Admin)
  437. {
  438. return Json(new
  439. {
  440. error = "10",
  441. content = "Timeout"
  442. });
  443. }
  444. ToolConfig data = db.GetToolConfigById(int.Parse(id))[0];
  445. return Json(new
  446. {
  447. error = "0",
  448. data = data
  449. });
  450. }
  451. public IActionResult ReportDay()
  452. {
  453. Users user = HttpContext.Session.GetComplexData<Users>("user");
  454. if (user == null || (user.role <= 0))
  455. {
  456. return View("Login");
  457. }
  458. else
  459. {
  460. return View();
  461. }
  462. }
  463. [HttpPost]
  464. public IActionResult GetReportDay(String fromDate, String toDate)
  465. {
  466. Users user = HttpContext.Session.GetComplexData<Users>("user");
  467. if (user == null || (user.role <= 0))
  468. {
  469. ViewBag.username = "Welcome!";
  470. return Json(new
  471. {
  472. error = "10",
  473. content = "Timeout"
  474. });
  475. }
  476. DateTime startTime = DateTime.ParseExact(fromDate, df, null);
  477. DateTime endTime = DateTime.ParseExact(toDate, df, null);
  478. List<ScenarioReport> res = db.GetScenarioReportDay(startTime, endTime);
  479. return PartialView("_ReportDay", res);
  480. }
  481. }
  482. }