ConfigController.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Logging;
  7. using SuperCms.Extensions;
  8. using SuperCms.Models;
  9. using SuperCms.Repositories;
  10. namespace SuperCms.Controllers
  11. {
  12. public class ConfigController : BaseController
  13. {
  14. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  15. private OracleController oracle;
  16. ISuperCmsRepo iSuperCmsRepo;
  17. public ConfigController(ISuperCmsRepo ISuperCmsRepo)
  18. {
  19. iSuperCmsRepo = ISuperCmsRepo;
  20. }
  21. public IActionResult Index(String tableType, String page)
  22. {
  23. try
  24. {
  25. if (!CheckAuthToken())
  26. {
  27. return Redirect("/Home/Login");
  28. }
  29. oracle = new OracleController(iSuperCmsRepo);
  30. String pageNow = page != null ? page : "1";
  31. HttpContext.Session.SetComplexData("page", pageNow);
  32. String type = tableType != null ? tableType : UtilsController.Constant.BOTS;
  33. ConfigViewModel model = new ConfigViewModel();
  34. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  35. if (telcos == null)
  36. {
  37. telcos = oracle.getConnTelcos();
  38. HttpContext.Session.SetComplexData("telcos", telcos);
  39. }
  40. model.telcos = telcos;
  41. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  42. if (companies == null)
  43. {
  44. companies = oracle.getConnCompanies();
  45. HttpContext.Session.SetComplexData("companies", companies);
  46. }
  47. model.companies = companies;
  48. ConnConfigs services = oracle.getConnConfigs();
  49. HttpContext.Session.SetComplexData("services", services);
  50. model.services = services;
  51. // get all bots
  52. BotStructures bots = oracle.getBotstructures();
  53. GroupStructures groups = oracle.getGroupstructures();
  54. Configs configs = oracle.getConfigs();
  55. // get all send mail
  56. SendMails sendMails = oracle.getSendMails();
  57. //save to session
  58. HttpContext.Session.SetComplexData("configs", configs);
  59. HttpContext.Session.SetComplexData("bots", bots);
  60. HttpContext.Session.SetComplexData("groups", groups);
  61. HttpContext.Session.SetComplexData("sendMails", sendMails);
  62. HttpContext.Session.SetComplexData("services", services);
  63. ScheduleStructures schedules = oracle.getSchedulestructures(pageNow, UtilsController.Constant.NUMBER_ROW_ON_PAGE);
  64. HttpContext.Session.SetComplexData("schedules", schedules);
  65. model.totalPage = type == UtilsController.Constant.SERVICE_CONFIG ? "1" : oracle.getTotalRow(type, UtilsController.Constant.NUMBER_ROW_ON_PAGE);
  66. model.configs = configs;
  67. model.bots = bots;
  68. model.groups = groups;
  69. model.sendMails = sendMails;
  70. model.schedules = schedules;
  71. model.services = services;
  72. model.companies = companies;
  73. model.telcos = telcos;
  74. model.tableType = type;
  75. model.page = pageNow;
  76. return View("Index", model);
  77. }
  78. catch (Exception ex)
  79. {
  80. log.Error("Exception: ", ex);
  81. return Redirect("/Home");
  82. }
  83. }
  84. public IActionResult ExportSendMail(String tableType, SendMail data)
  85. {
  86. try
  87. {
  88. if (!CheckAuthToken())
  89. {
  90. return Redirect("/Home/Login");
  91. }
  92. ConfigViewModel model = new ConfigViewModel();
  93. model.tableType = tableType != null ? tableType : UtilsController.Constant.SENDMAIL;
  94. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  95. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  96. ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
  97. model.telcos = telcos;
  98. model.companies = companies;
  99. model.services = new ConnConfigs();
  100. List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
  101. DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == data.telcoId);
  102. if (dis == null)
  103. {
  104. model.telco = disByTelcoAndCompany[0].telco;
  105. model.company = disByTelcoAndCompany[0].companies.data[0];
  106. model.services.data = services.data.FindAll(x => x.telcoID == data.telcoId && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
  107. }
  108. else
  109. {
  110. model.telco = dis.telco;
  111. model.companies = dis.companies;
  112. model.company = data.companyId != null && data.companyId != "null" ? dis.companies.data.Find(x => x.id == data.companyId) : dis.companies.data[0];
  113. model.services.data = services.data.FindAll(x => x.telcoID == data.telcoId && x.companyID == (data.companyId != null && data.companyId != "null" ? data.companyId : dis.companies.data[0].id));
  114. }
  115. model.sendMail = data;
  116. return PartialView("Adding", model);
  117. }
  118. catch (Exception ex)
  119. {
  120. return Redirect("/Home");
  121. }
  122. }
  123. public IActionResult ExportService(String tableType, ConnConfig data)
  124. {
  125. try
  126. {
  127. if (!CheckAuthToken())
  128. {
  129. return Redirect("/Home/Login");
  130. }
  131. ConfigViewModel model = new ConfigViewModel();
  132. model.tableType = tableType != null ? tableType : UtilsController.Constant.SERVICE_CONFIG;
  133. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  134. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  135. ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
  136. model.telcos = telcos;
  137. model.companies = companies;
  138. model.services = new ConnConfigs();
  139. List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
  140. DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == data.telcoID);
  141. if (dis == null)
  142. {
  143. model.telco = disByTelcoAndCompany[0].telco;
  144. model.company = disByTelcoAndCompany[0].companies.data[0];
  145. model.services.data = services.data.FindAll(x => x.telcoID == data.telcoID && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
  146. }
  147. else
  148. {
  149. model.telco = dis.telco;
  150. model.companies = dis.companies;
  151. model.company = data.companyID != null && data.companyID != "null" ? dis.companies.data.Find(x => x.id == data.companyID) : dis.companies.data[0];
  152. model.services.data = services.data.FindAll(x => x.telcoID == data.telcoID && x.companyID == (data.companyID != null && data.companyID != "null" ? data.companyID : dis.companies.data[0].id));
  153. }
  154. model.service = data;
  155. return PartialView("Adding", model);
  156. }
  157. catch (Exception ex)
  158. {
  159. return Redirect("/Home");
  160. }
  161. }
  162. public IActionResult Adding(String tableType)
  163. {
  164. try
  165. {
  166. if (!CheckAuthToken())
  167. {
  168. return Redirect("/Home/Login");
  169. }
  170. ConfigViewModel model = new ConfigViewModel();
  171. model.bots = new BotStructures();
  172. model.groups = new GroupStructures();
  173. model.tableType = tableType;
  174. BotStructures bots = HttpContext.Session.GetComplexData<BotStructures>("bots");
  175. GroupStructures groups = HttpContext.Session.GetComplexData<GroupStructures>("groups");
  176. Configs configs = HttpContext.Session.GetComplexData<Configs>("configs");
  177. SendMails sendMails = HttpContext.Session.GetComplexData<SendMails>("sendMails");
  178. model.bots.data = bots.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
  179. model.groups.data = groups.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
  180. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  181. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  182. model.telcos = telcos;
  183. model.companies = companies;
  184. List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
  185. model.telco = disByTelcoAndCompany[0].telco;
  186. model.company = disByTelcoAndCompany[0].companies.data[0];
  187. model.services = disByTelcoAndCompany[0].services;
  188. return PartialView("Adding", model);
  189. }
  190. catch (Exception ex)
  191. {
  192. log.Error("Exception: ", ex);
  193. return Redirect("/Home");
  194. }
  195. }
  196. [ValidateAntiForgeryToken]
  197. public JsonResult AddingBotAction(BotStructure data)
  198. {
  199. try
  200. {
  201. if (!CheckAuthToken())
  202. {
  203. return Json(new
  204. {
  205. code = UtilsController.Constant.ERROR,
  206. href = "/Home/Login"
  207. });
  208. }
  209. String page = HttpContext.Session.GetComplexData<String>("page");
  210. data.startDate = convertToDateTimeServer(data.startDate);
  211. data.endDate = convertToDateTimeServer(data.endDate);
  212. oracle = new OracleController(iSuperCmsRepo);
  213. BotStructures bots = oracle.addingBotStructure(data);
  214. if (bots.data.Count > 0)
  215. {
  216. return Json(new
  217. {
  218. code = UtilsController.Constant.SUCCESS,
  219. href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
  220. });
  221. }
  222. else
  223. {
  224. return Json(new
  225. {
  226. code = UtilsController.Constant.ERROR,
  227. href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
  228. });
  229. }
  230. }
  231. catch (Exception ex)
  232. {
  233. log.Error("Exception " + ex);
  234. return Json(new
  235. {
  236. code = UtilsController.Constant.ERROR,
  237. href = "/Home"
  238. });
  239. }
  240. }
  241. [ValidateAntiForgeryToken]
  242. public JsonResult AddingGroupAction(GroupStructure data)
  243. {
  244. try
  245. {
  246. if (!CheckAuthToken())
  247. {
  248. return Json(new
  249. {
  250. code = UtilsController.Constant.ERROR,
  251. href = "/Home/Login"
  252. });
  253. }
  254. String page = HttpContext.Session.GetComplexData<String>("page");
  255. data.startDate = convertToDateTimeServer(data.startDate);
  256. data.endDate = convertToDateTimeServer(data.endDate);
  257. oracle = new OracleController(iSuperCmsRepo);
  258. GroupStructures groups = oracle.addingGroupStructure(data);
  259. if (groups.data.Count > 0)
  260. {
  261. return Json(new
  262. {
  263. code = UtilsController.Constant.SUCCESS,
  264. href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
  265. });
  266. }
  267. else
  268. {
  269. return Json(new
  270. {
  271. code = UtilsController.Constant.ERROR,
  272. href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
  273. });
  274. }
  275. }
  276. catch (Exception ex)
  277. {
  278. log.Error("Exception " + ex);
  279. return Json(new
  280. {
  281. code = UtilsController.Constant.ERROR,
  282. href = "/Home"
  283. });
  284. }
  285. }
  286. [ValidateAntiForgeryToken]
  287. public JsonResult AddingScheduleAction(ScheduleStructure data)
  288. {
  289. try
  290. {
  291. if (!CheckAuthToken())
  292. {
  293. return Json(new
  294. {
  295. code = UtilsController.Constant.ERROR,
  296. href = "/Home/Login"
  297. });
  298. }
  299. String page = HttpContext.Session.GetComplexData<String>("page");
  300. data.timeRun = convertToDateTimeServer(data.timeRun);
  301. oracle = new OracleController(iSuperCmsRepo);
  302. ScheduleStructures schedules = oracle.addingScheduleStructure(data);
  303. if (schedules.data.Count > 0)
  304. {
  305. return Json(new
  306. {
  307. code = UtilsController.Constant.SUCCESS,
  308. href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
  309. });
  310. }
  311. else
  312. {
  313. return Json(new
  314. {
  315. code = UtilsController.Constant.ERROR,
  316. href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
  317. });
  318. }
  319. }
  320. catch (Exception ex)
  321. {
  322. log.Error("Exception " + ex);
  323. return Json(new
  324. {
  325. code = UtilsController.Constant.ERROR,
  326. href = "/Home"
  327. });
  328. }
  329. }
  330. [ValidateAntiForgeryToken]
  331. public JsonResult AddingConfigAction(Config data)
  332. {
  333. try
  334. {
  335. if (!CheckAuthToken())
  336. {
  337. return Json(new
  338. {
  339. code = UtilsController.Constant.ERROR,
  340. href = "/Home/Login"
  341. });
  342. }
  343. String page = HttpContext.Session.GetComplexData<String>("page");
  344. oracle = new OracleController(iSuperCmsRepo);
  345. Configs configs = oracle.addingConfig(data);
  346. if (configs.data.Count > 0)
  347. {
  348. return Json(new
  349. {
  350. code = UtilsController.Constant.SUCCESS,
  351. href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
  352. });
  353. }
  354. else
  355. {
  356. return Json(new
  357. {
  358. code = UtilsController.Constant.ERROR,
  359. href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
  360. });
  361. }
  362. }
  363. catch (Exception ex)
  364. {
  365. log.Error("Exception " + ex);
  366. return Json(new
  367. {
  368. code = UtilsController.Constant.ERROR,
  369. href = "/Home"
  370. });
  371. }
  372. }
  373. [ValidateAntiForgeryToken]
  374. public JsonResult AddingSendMailAction(SendMail data)
  375. {
  376. try
  377. {
  378. if (!CheckAuthToken())
  379. {
  380. return Json(new
  381. {
  382. code = UtilsController.Constant.ERROR,
  383. href = "/Home/Login"
  384. });
  385. }
  386. String page = HttpContext.Session.GetComplexData<String>("page");
  387. data.timeSend = convertToDateTimeServer(data.timeSend);
  388. oracle = new OracleController(iSuperCmsRepo);
  389. SendMails sendMails = oracle.addingSendMail(data);
  390. if (sendMails.data.Count > 0)
  391. {
  392. return Json(new
  393. {
  394. code = UtilsController.Constant.SUCCESS,
  395. href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
  396. });
  397. }
  398. else
  399. {
  400. return Json(new
  401. {
  402. code = UtilsController.Constant.ERROR,
  403. href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
  404. });
  405. }
  406. }
  407. catch (Exception ex)
  408. {
  409. log.Error("Exception " + ex);
  410. return Json(new
  411. {
  412. code = UtilsController.Constant.ERROR,
  413. href = "/Home"
  414. });
  415. }
  416. }
  417. [ValidateAntiForgeryToken]
  418. public JsonResult AddingServiceAction(ConnConfig data)
  419. {
  420. try
  421. {
  422. if (!CheckAuthToken())
  423. {
  424. return Json(new
  425. {
  426. code = UtilsController.Constant.ERROR,
  427. href = "/Home/Login"
  428. });
  429. }
  430. String page = HttpContext.Session.GetComplexData<String>("page");
  431. //data.timeSend = convertToDateTimeServer(data.timeSend);
  432. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  433. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  434. ConnCompany company = companies.data.Find(x => x.id == data.companyID);
  435. ConnTelco telco = telcos.data.Find(x => x.id == data.telcoID);
  436. data.telco = telco.telcoName;
  437. String timeNow = DateTime.Now.ToString("dd/MM/yyyy");
  438. data.totalRun = "0";
  439. data.dateRun = timeNow;
  440. data.dateGet = timeNow;
  441. data.hourRun = data.hourRun + ":00";
  442. oracle = new OracleController(iSuperCmsRepo);
  443. ConnConfigs connConfigs = oracle.addConnConfigs(data);
  444. if (connConfigs.data.Count > 0)
  445. {
  446. return Json(new
  447. {
  448. code = UtilsController.Constant.SUCCESS,
  449. href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
  450. });
  451. }
  452. else
  453. {
  454. return Json(new
  455. {
  456. code = UtilsController.Constant.ERROR,
  457. href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
  458. });
  459. }
  460. }
  461. catch (Exception ex)
  462. {
  463. log.Error("Exception " + ex);
  464. return Json(new
  465. {
  466. code = UtilsController.Constant.ERROR,
  467. href = "/Home"
  468. });
  469. }
  470. }
  471. public IActionResult Editing(String tableType, String id)
  472. {
  473. try
  474. {
  475. if (!CheckAuthToken())
  476. {
  477. return Redirect("/Home/Login");
  478. }
  479. ConfigViewModel model = new ConfigViewModel();
  480. model.tableType = tableType;
  481. model.bots = new BotStructures();
  482. model.groups = new GroupStructures();
  483. BotStructures bots = HttpContext.Session.GetComplexData<BotStructures>("bots");
  484. GroupStructures groups = HttpContext.Session.GetComplexData<GroupStructures>("groups");
  485. ScheduleStructures schedules = HttpContext.Session.GetComplexData<ScheduleStructures>("schedules");
  486. Configs configs = HttpContext.Session.GetComplexData<Configs>("configs");
  487. SendMails sendMails = HttpContext.Session.GetComplexData<SendMails>("sendMails");
  488. ConnConfigs connConfigs = HttpContext.Session.GetComplexData<ConnConfigs>("services");
  489. if (tableType == UtilsController.Constant.BOTS)
  490. {
  491. BotStructure bot = bots.data.Find(x => x.id == id);
  492. if (bot == null)
  493. {
  494. log.Error("No existed bot: " + id);
  495. return Redirect("/Home");
  496. }
  497. model.bot = bot;
  498. HttpContext.Session.SetComplexData("bot", bot);
  499. }
  500. else if (tableType == UtilsController.Constant.GROUPS)
  501. {
  502. GroupStructure group = groups.data.Find(x => x.id == id);
  503. if (group == null)
  504. {
  505. log.Error("No existed group: " + id);
  506. return Redirect("/Home");
  507. }
  508. model.group = group;
  509. HttpContext.Session.SetComplexData("group", group);
  510. }
  511. else if (tableType == UtilsController.Constant.SCHEDULES)
  512. {
  513. ScheduleStructure schedule = schedules.data.Find(x => x.id == id);
  514. if (schedule == null)
  515. {
  516. log.Error("No existed schedule: " + id);
  517. return Redirect("/Home");
  518. }
  519. model.schedule = schedule;
  520. HttpContext.Session.SetComplexData("schedule", schedule);
  521. }
  522. else if (tableType == UtilsController.Constant.CONFIGS)
  523. {
  524. Config config = configs.data.Find(x => x.id == id);
  525. if (config == null)
  526. {
  527. log.Error("No existed config: " + id);
  528. return Redirect("/Home");
  529. }
  530. model.config = config;
  531. HttpContext.Session.SetComplexData("config", config);
  532. }
  533. else if (tableType == UtilsController.Constant.SENDMAIL)
  534. {
  535. SendMail sendMail = sendMails.data.Find(x => x.id == id);
  536. if (sendMail == null)
  537. {
  538. log.Error("No existed config: " + id);
  539. return Redirect("/Home");
  540. }
  541. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  542. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  543. ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
  544. List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
  545. DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == sendMail.telcoId);
  546. model.telcos = telcos;
  547. model.companies = companies;
  548. model.services = new ConnConfigs();
  549. if (dis == null)
  550. {
  551. model.telco = disByTelcoAndCompany[0].telco;
  552. model.company = disByTelcoAndCompany[0].companies.data[0];
  553. model.services.data = services.data.FindAll(x => x.telcoID == sendMail.telcoId && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
  554. }
  555. else
  556. {
  557. model.telco = dis.telco;
  558. model.companies = dis.companies;
  559. model.company = dis.companies.data.Find(x => x.id == sendMail.companyId);
  560. model.services.data = services.data.FindAll(x => x.telcoID == sendMail.telcoId && x.companyID == sendMail.companyId);
  561. }
  562. model.service = services.data.Find(x => x.id == sendMail.serviceId);
  563. model.sendMail = sendMail;
  564. HttpContext.Session.SetComplexData("sendMail", sendMail);
  565. }
  566. else if (tableType == UtilsController.Constant.SERVICE_CONFIG)
  567. {
  568. ConnConfig connConfig = connConfigs.data.Find(x => x.id == id);
  569. if (connConfig == null)
  570. {
  571. log.Error("No existed config: " + id);
  572. return Redirect("/Home");
  573. }
  574. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  575. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  576. ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
  577. List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
  578. DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == connConfig.telcoID);
  579. model.telcos = telcos;
  580. model.companies = companies;
  581. model.services = new ConnConfigs();
  582. model.service = connConfig;
  583. if (dis == null)
  584. {
  585. model.telco = disByTelcoAndCompany[0].telco;
  586. model.company = disByTelcoAndCompany[0].companies.data[0];
  587. model.services.data = services.data.FindAll(x => x.telcoID == connConfig.telcoID && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
  588. }
  589. else
  590. {
  591. model.telco = dis.telco;
  592. model.companies = dis.companies;
  593. model.company = dis.companies.data.Find(x => x.id == connConfig.companyID);
  594. model.services.data = services.data.FindAll(x => x.telcoID == connConfig.telcoID && x.companyID == connConfig.companyID);
  595. }
  596. HttpContext.Session.SetComplexData("service", connConfig);
  597. }
  598. else
  599. {
  600. log.Error("No existed table type: " + tableType);
  601. return Redirect("/Home");
  602. }
  603. model.bots.data = bots.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
  604. model.groups.data = groups.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
  605. return PartialView("Editing", model);
  606. }
  607. catch (Exception ex)
  608. {
  609. log.Error("Exception: ", ex);
  610. return Redirect("/Home");
  611. }
  612. }
  613. [ValidateAntiForgeryToken]
  614. public JsonResult EditingBotAction(BotStructure data)
  615. {
  616. try
  617. {
  618. if (!CheckAuthToken())
  619. {
  620. return Json(new
  621. {
  622. code = UtilsController.Constant.ERROR,
  623. href = "/Home/Login"
  624. });
  625. }
  626. String page = HttpContext.Session.GetComplexData<String>("page");
  627. BotStructure bot = HttpContext.Session.GetComplexData<BotStructure>("bot");
  628. data.id = bot.id;
  629. data.startDate = convertToDateTimeServer(data.startDate);
  630. data.endDate = convertToDateTimeServer(data.endDate);
  631. oracle = new OracleController(iSuperCmsRepo);
  632. BotStructures bots = oracle.editingBotStructure(data);
  633. if (bots.data.Count > 0)
  634. {
  635. return Json(new
  636. {
  637. code = UtilsController.Constant.SUCCESS,
  638. href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
  639. });
  640. }
  641. else
  642. {
  643. return Json(new
  644. {
  645. code = UtilsController.Constant.ERROR,
  646. href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
  647. });
  648. }
  649. }
  650. catch (Exception ex)
  651. {
  652. log.Error("Exception " + ex);
  653. return Json(new
  654. {
  655. code = UtilsController.Constant.ERROR,
  656. href = "/Home"
  657. });
  658. }
  659. }
  660. [ValidateAntiForgeryToken]
  661. public JsonResult EditingGroupAction(GroupStructure data)
  662. {
  663. try
  664. {
  665. if (!CheckAuthToken())
  666. {
  667. return Json(new
  668. {
  669. code = UtilsController.Constant.ERROR,
  670. href = "/Home/Login"
  671. });
  672. }
  673. String page = HttpContext.Session.GetComplexData<String>("page");
  674. GroupStructure group = HttpContext.Session.GetComplexData<GroupStructure>("group");
  675. data.id = group.id;
  676. data.startDate = convertToDateTimeServer(data.startDate);
  677. data.endDate = convertToDateTimeServer(data.endDate);
  678. oracle = new OracleController(iSuperCmsRepo);
  679. GroupStructures groups = oracle.editingGroupStructure(data);
  680. if (groups.data.Count > 0)
  681. {
  682. return Json(new
  683. {
  684. code = UtilsController.Constant.SUCCESS,
  685. href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
  686. });
  687. }
  688. else
  689. {
  690. return Json(new
  691. {
  692. code = UtilsController.Constant.ERROR,
  693. href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
  694. });
  695. }
  696. }
  697. catch (Exception ex)
  698. {
  699. log.Error("Exception " + ex);
  700. return Json(new
  701. {
  702. code = UtilsController.Constant.ERROR,
  703. href = "/Home"
  704. });
  705. }
  706. }
  707. [ValidateAntiForgeryToken]
  708. public JsonResult EditingScheduleAction(ScheduleStructure data)
  709. {
  710. try
  711. {
  712. if (!CheckAuthToken())
  713. {
  714. return Json(new
  715. {
  716. code = UtilsController.Constant.ERROR,
  717. href = "/Home/Login"
  718. });
  719. }
  720. String page = HttpContext.Session.GetComplexData<String>("page");
  721. ScheduleStructure schedule = HttpContext.Session.GetComplexData<ScheduleStructure>("schedule");
  722. data.id = schedule.id;
  723. data.timeRun = convertToDateTimeServer(data.timeRun);
  724. oracle = new OracleController(iSuperCmsRepo);
  725. ScheduleStructures schedules = oracle.editingScheduleStructure(data);
  726. if (schedules.data.Count > 0)
  727. {
  728. return Json(new
  729. {
  730. code = UtilsController.Constant.SUCCESS,
  731. href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
  732. });
  733. }
  734. else
  735. {
  736. return Json(new
  737. {
  738. code = UtilsController.Constant.ERROR,
  739. href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
  740. });
  741. }
  742. }
  743. catch (Exception ex)
  744. {
  745. log.Error("Exception " + ex);
  746. return Json(new
  747. {
  748. code = UtilsController.Constant.ERROR,
  749. href = "/Home"
  750. });
  751. }
  752. }
  753. [ValidateAntiForgeryToken]
  754. public JsonResult EditingSendMailAction(SendMail data)
  755. {
  756. try
  757. {
  758. if (!CheckAuthToken())
  759. {
  760. return Json(new
  761. {
  762. code = UtilsController.Constant.ERROR,
  763. href = "/Home/Login"
  764. });
  765. }
  766. String page = HttpContext.Session.GetComplexData<String>("page");
  767. SendMail sendMail = HttpContext.Session.GetComplexData<SendMail>("sendMail");
  768. data.id = sendMail.id;
  769. data.timeSend = convertToDateTimeServer(data.timeSend);
  770. oracle = new OracleController(iSuperCmsRepo);
  771. SendMails sendMails = oracle.editingSendMail(data);
  772. if (sendMails.data.Count > 0)
  773. {
  774. return Json(new
  775. {
  776. code = UtilsController.Constant.SUCCESS,
  777. href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
  778. });
  779. }
  780. else
  781. {
  782. return Json(new
  783. {
  784. code = UtilsController.Constant.ERROR,
  785. href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
  786. });
  787. }
  788. }
  789. catch (Exception ex)
  790. {
  791. log.Error("Exception " + ex);
  792. return Json(new
  793. {
  794. code = UtilsController.Constant.ERROR,
  795. href = "/Home"
  796. });
  797. }
  798. }
  799. [ValidateAntiForgeryToken]
  800. public JsonResult EditingConfigAction(Config data)
  801. {
  802. try
  803. {
  804. if (!CheckAuthToken())
  805. {
  806. return Json(new
  807. {
  808. code = UtilsController.Constant.ERROR,
  809. href = "/Home/Login"
  810. });
  811. }
  812. String page = HttpContext.Session.GetComplexData<String>("page");
  813. Config config = HttpContext.Session.GetComplexData<Config>("config");
  814. data.id = config.id;
  815. oracle = new OracleController(iSuperCmsRepo);
  816. Configs configs = oracle.editingConfig(data);
  817. if (configs.data.Count > 0)
  818. {
  819. return Json(new
  820. {
  821. code = UtilsController.Constant.SUCCESS,
  822. href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
  823. });
  824. }
  825. else
  826. {
  827. return Json(new
  828. {
  829. code = UtilsController.Constant.ERROR,
  830. href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
  831. });
  832. }
  833. }
  834. catch (Exception ex)
  835. {
  836. log.Error("Exception " + ex);
  837. return Json(new
  838. {
  839. code = UtilsController.Constant.ERROR,
  840. href = "/Home"
  841. });
  842. }
  843. }
  844. [ValidateAntiForgeryToken]
  845. public JsonResult EditingServiceAction(ConnConfig data)
  846. {
  847. try
  848. {
  849. if (!CheckAuthToken())
  850. {
  851. return Json(new
  852. {
  853. code = UtilsController.Constant.ERROR,
  854. href = "/Home/Login"
  855. });
  856. }
  857. String page = HttpContext.Session.GetComplexData<String>("page");
  858. ConnConfig connConfig = HttpContext.Session.GetComplexData<ConnConfig>("service");
  859. data.id = connConfig.id;
  860. ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
  861. ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
  862. ConnCompany company = companies.data.Find(x => x.id == data.companyID);
  863. ConnTelco telco = telcos.data.Find(x => x.id == data.telcoID);
  864. data.telco = telco.telcoName;
  865. String timeNow = DateTime.Now.ToString("dd/MM/yyyy");
  866. data.totalRun = "0";
  867. data.dateRun = timeNow;
  868. data.dateGet = timeNow;
  869. if (data.hourRun.Length > 5)
  870. {
  871. data.hourRun = data.hourRun;
  872. }
  873. else
  874. {
  875. data.hourRun = data.hourRun + ":00";
  876. }
  877. oracle = new OracleController(iSuperCmsRepo);
  878. ConnConfigs connConfigs = oracle.editConnConfigs(data);
  879. if (connConfigs.data.Count > 0)
  880. {
  881. return Json(new
  882. {
  883. code = UtilsController.Constant.SUCCESS,
  884. href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
  885. });
  886. }
  887. else
  888. {
  889. return Json(new
  890. {
  891. code = UtilsController.Constant.ERROR,
  892. href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
  893. });
  894. }
  895. }
  896. catch (Exception ex)
  897. {
  898. log.Error("Exception " + ex);
  899. return Json(new
  900. {
  901. code = UtilsController.Constant.ERROR,
  902. href = "/Home"
  903. });
  904. }
  905. }
  906. [ValidateAntiForgeryToken]
  907. public JsonResult DeletingAction(String tableType, String id)
  908. {
  909. try
  910. {
  911. if (!CheckAuthToken())
  912. {
  913. return Json(new
  914. {
  915. code = UtilsController.Constant.ERROR,
  916. href = "/Home/Login"
  917. });
  918. }
  919. oracle = new OracleController(iSuperCmsRepo);
  920. ConfigViewModel model = new ConfigViewModel();
  921. model.tableType = tableType;
  922. String page = HttpContext.Session.GetComplexData<String>("page");
  923. BotStructures bots = HttpContext.Session.GetComplexData<BotStructures>("bots");
  924. GroupStructures groups = HttpContext.Session.GetComplexData<GroupStructures>("groups");
  925. ScheduleStructures schedules = HttpContext.Session.GetComplexData<ScheduleStructures>("schedules");
  926. SendMails sendMails = HttpContext.Session.GetComplexData<SendMails>("sendMails");
  927. ConnConfigs connConfigs = HttpContext.Session.GetComplexData<ConnConfigs>("services");
  928. if (tableType == null || id == null)
  929. {
  930. log.Error("Null ");
  931. return Json(new
  932. {
  933. code = UtilsController.Constant.ERROR,
  934. href = "/Home"
  935. });
  936. }
  937. Boolean response;
  938. if (tableType == UtilsController.Constant.BOTS)
  939. {
  940. BotStructure bot = bots.data.Find(x => x.id == id);
  941. if (bot == null)
  942. {
  943. log.Error("No existed bot: " + id);
  944. return Json(new
  945. {
  946. code = UtilsController.Constant.ERROR,
  947. message = "An error was happened",
  948. href = "/Config?tableType=" + tableType + "&page=" + page,
  949. });
  950. }
  951. }
  952. else if (tableType == UtilsController.Constant.GROUPS)
  953. {
  954. GroupStructure group = groups.data.Find(x => x.id == id);
  955. if (group == null)
  956. {
  957. log.Error("No existed group: " + id);
  958. return Json(new
  959. {
  960. code = UtilsController.Constant.ERROR,
  961. message = "An error was happened",
  962. href = "/Config?tableType=" + tableType + "&page=" + page,
  963. });
  964. }
  965. model.group = group;
  966. }
  967. else if (tableType == UtilsController.Constant.SCHEDULES)
  968. {
  969. ScheduleStructure schedule = schedules.data.Find(x => x.id == id);
  970. if (schedule == null)
  971. {
  972. log.Error("No existed schedule: " + id);
  973. return Json(new
  974. {
  975. code = UtilsController.Constant.ERROR,
  976. message = "An error was happened",
  977. href = "/Config?tableType=" + tableType + "&page=" + page,
  978. });
  979. }
  980. model.schedule = schedule;
  981. }
  982. else if (tableType == UtilsController.Constant.SENDMAIL)
  983. {
  984. SendMail sendMail = sendMails.data.Find(x => x.id == id);
  985. if (sendMail == null)
  986. {
  987. log.Error("No existed schedule: " + id);
  988. return Json(new
  989. {
  990. code = UtilsController.Constant.ERROR,
  991. message = "An error was happened",
  992. href = "/Config?tableType=" + tableType + "&page=" + page,
  993. });
  994. }
  995. model.sendMail = sendMail;
  996. }
  997. else if (tableType == UtilsController.Constant.SERVICE_CONFIG)
  998. {
  999. ConnConfig connConfig = connConfigs.data.Find(x => x.id == id);
  1000. if (connConfig == null)
  1001. {
  1002. log.Error("No existed connConfig: " + id);
  1003. return Json(new
  1004. {
  1005. code = UtilsController.Constant.ERROR,
  1006. message = "An error was happened",
  1007. href = "/Config?tableType=" + tableType + "&page=" + page,
  1008. });
  1009. }
  1010. model.service = connConfig;
  1011. }
  1012. else
  1013. {
  1014. log.Error("No existed table type: " + tableType);
  1015. return Json(new
  1016. {
  1017. code = UtilsController.Constant.ERROR,
  1018. message = "An error was happened",
  1019. href = "/Home",
  1020. });
  1021. }
  1022. response = oracle.deleteStructure(tableType, id);
  1023. if (!response)
  1024. {
  1025. return Json(new
  1026. {
  1027. code = UtilsController.Constant.ERROR,
  1028. message = "Delete failure",
  1029. href = "/Config?tableType=" + tableType + "&page=" + page,
  1030. });
  1031. }
  1032. else
  1033. {
  1034. return Json(new
  1035. {
  1036. code = UtilsController.Constant.SUCCESS,
  1037. message = "Delete successful",
  1038. href = "/Config?tableType=" + tableType + "&page=" + page,
  1039. });
  1040. }
  1041. }
  1042. catch (Exception ex)
  1043. {
  1044. log.Error("Exception " + ex);
  1045. return Json(new
  1046. {
  1047. code = UtilsController.Constant.ERROR,
  1048. href = "/Home"
  1049. });
  1050. }
  1051. }
  1052. }
  1053. }