OracleController.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Logging;
  8. using Newtonsoft.Json;
  9. using Newtonsoft.Json.Linq;
  10. using SuperCms.Models;
  11. using SuperCms.Repositories;
  12. using static SuperCms.Controllers.UtilsController;
  13. namespace SuperCms.Controllers
  14. {
  15. public class OracleController
  16. {
  17. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  18. private readonly ILogger<ReportController> _logger;
  19. ISuperCmsRepo iSuperCmsRepo;
  20. public OracleController(ISuperCmsRepo ISuperCmsRepo)
  21. {
  22. iSuperCmsRepo = ISuperCmsRepo;
  23. }
  24. // get all schedules within today
  25. public BotStructures getBotstructures()
  26. {
  27. BotStructures bots = new BotStructures();
  28. bots.data = new List<BotStructure>();
  29. var resultC = iSuperCmsRepo.GetAllBots(log);
  30. var propertyC = typeof(ICollection).GetProperty("Count");
  31. int countC = (int)propertyC.GetValue(resultC, null);
  32. if (resultC != null && countC > 0)
  33. {
  34. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  35. {
  36. var json = JsonConvert.SerializeObject(row);
  37. BotStructure dataGet = new BotStructure(json.ToString());
  38. bots.data.Add(dataGet);
  39. }
  40. }
  41. return bots;
  42. }
  43. public ScheduleStructures getSchedulestructures(String seqPage, String rowsOnPage)
  44. {
  45. ScheduleStructures schedules = new ScheduleStructures();
  46. schedules.data = new List<ScheduleStructure>();
  47. var resultC = iSuperCmsRepo.GetScheduleByRow(log, seqPage, rowsOnPage);
  48. var propertyC = typeof(ICollection).GetProperty("Count");
  49. int countC = (int)propertyC.GetValue(resultC, null);
  50. if (resultC != null && countC > 0)
  51. {
  52. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  53. {
  54. var json = JsonConvert.SerializeObject(row);
  55. ScheduleStructure dataGet = new ScheduleStructure(json.ToString());
  56. schedules.data.Add(dataGet);
  57. }
  58. }
  59. return schedules;
  60. }
  61. public GroupStructures getGroupstructures()
  62. {
  63. GroupStructures groups = new GroupStructures();
  64. groups.data = new List<GroupStructure>();
  65. var resultC = iSuperCmsRepo.GetAllGroups(log);
  66. var propertyC = typeof(ICollection).GetProperty("Count");
  67. int countC = (int)propertyC.GetValue(resultC, null);
  68. if (resultC != null && countC > 0)
  69. {
  70. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  71. {
  72. var json = JsonConvert.SerializeObject(row);
  73. GroupStructure dataGet = new GroupStructure(json.ToString());
  74. groups.data.Add(dataGet);
  75. }
  76. }
  77. return groups;
  78. }
  79. public Configs getConfigs()
  80. {
  81. Configs configs = new Configs();
  82. configs.data = new List<Config>();
  83. var resultC = iSuperCmsRepo.GetAllConfigs(log);
  84. var propertyC = typeof(ICollection).GetProperty("Count");
  85. int countC = (int)propertyC.GetValue(resultC, null);
  86. if (resultC != null && countC > 0)
  87. {
  88. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  89. {
  90. var json = JsonConvert.SerializeObject(row);
  91. Config dataGet = new Config(json.ToString());
  92. configs.data.Add(dataGet);
  93. }
  94. }
  95. return configs;
  96. }
  97. public String getTotalRow(String type, String rowsOnPage)
  98. {
  99. ScheduleStructures schedules = new ScheduleStructures();
  100. schedules.data = new List<ScheduleStructure>();
  101. var resultC = iSuperCmsRepo.GetTotalRow(log, type);
  102. String number = "1";
  103. var propertyC = typeof(ICollection).GetProperty("Count");
  104. int countC = (int)propertyC.GetValue(resultC, null);
  105. if (resultC != null && countC > 0)
  106. {
  107. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  108. {
  109. var json = JObject.Parse(JsonConvert.SerializeObject(row));
  110. number = (string)json["COUNT(*)"].ToString();
  111. }
  112. int totalPage = int.Parse(number) / int.Parse(rowsOnPage);
  113. if (int.Parse(number) % int.Parse(rowsOnPage) != 0)
  114. {
  115. totalPage++;
  116. }
  117. number = totalPage.ToString();
  118. }
  119. return number;
  120. }
  121. public BotStructures addingBotStructure(BotStructure bot)
  122. {
  123. BotStructures bots = new BotStructures();
  124. bots.data = new List<BotStructure>();
  125. var resultC = iSuperCmsRepo.AddingBotStructure(log, bot);
  126. var propertyC = typeof(ICollection).GetProperty("Count");
  127. int countC = (int)propertyC.GetValue(resultC, null);
  128. if (resultC != null && countC > 0)
  129. {
  130. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  131. {
  132. var json = JsonConvert.SerializeObject(row);
  133. BotStructure dataGet = new BotStructure(json.ToString());
  134. bots.data.Add(dataGet);
  135. }
  136. }
  137. return bots;
  138. }
  139. public GroupStructures addingGroupStructure(GroupStructure group)
  140. {
  141. GroupStructures groups = new GroupStructures();
  142. groups.data = new List<GroupStructure>();
  143. var resultC = iSuperCmsRepo.AddingGroupStructure(log, group);
  144. var propertyC = typeof(ICollection).GetProperty("Count");
  145. int countC = (int)propertyC.GetValue(resultC, null);
  146. if (resultC != null && countC > 0)
  147. {
  148. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  149. {
  150. var json = JsonConvert.SerializeObject(row);
  151. GroupStructure dataGet = new GroupStructure(json.ToString());
  152. groups.data.Add(dataGet);
  153. }
  154. }
  155. return groups;
  156. }
  157. public ScheduleStructures addingScheduleStructure(ScheduleStructure schedule)
  158. {
  159. ScheduleStructures schedules = new ScheduleStructures();
  160. schedules.data = new List<ScheduleStructure>();
  161. var resultC = iSuperCmsRepo.AddingScheduleStructure(log, schedule);
  162. var propertyC = typeof(ICollection).GetProperty("Count");
  163. int countC = (int)propertyC.GetValue(resultC, null);
  164. if (resultC != null && countC > 0)
  165. {
  166. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  167. {
  168. var json = JsonConvert.SerializeObject(row);
  169. ScheduleStructure dataGet = new ScheduleStructure(json.ToString());
  170. schedules.data.Add(dataGet);
  171. }
  172. }
  173. return schedules;
  174. }
  175. public Configs addingConfig(Config config)
  176. {
  177. Configs configs = new Configs();
  178. configs.data = new List<Config>();
  179. var resultC = iSuperCmsRepo.AddingConfig(log, config);
  180. var propertyC = typeof(ICollection).GetProperty("Count");
  181. int countC = (int)propertyC.GetValue(resultC, null);
  182. if (resultC != null && countC > 0)
  183. {
  184. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  185. {
  186. var json = JsonConvert.SerializeObject(row);
  187. Config dataGet = new Config(json.ToString());
  188. configs.data.Add(dataGet);
  189. }
  190. }
  191. return configs;
  192. }
  193. public BotStructures editingBotStructure(BotStructure bot)
  194. {
  195. BotStructures bots = new BotStructures();
  196. bots.data = new List<BotStructure>();
  197. var resultC = iSuperCmsRepo.EditingBotStructure(log, bot);
  198. var propertyC = typeof(ICollection).GetProperty("Count");
  199. int countC = (int)propertyC.GetValue(resultC, null);
  200. if (resultC != null && countC > 0)
  201. {
  202. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  203. {
  204. var json = JsonConvert.SerializeObject(row);
  205. BotStructure dataGet = new BotStructure(json.ToString());
  206. bots.data.Add(dataGet);
  207. }
  208. }
  209. return bots;
  210. }
  211. public GroupStructures editingGroupStructure(GroupStructure group)
  212. {
  213. GroupStructures groups = new GroupStructures();
  214. groups.data = new List<GroupStructure>();
  215. var resultC = iSuperCmsRepo.EditingGroupStructure(log, group);
  216. var propertyC = typeof(ICollection).GetProperty("Count");
  217. int countC = (int)propertyC.GetValue(resultC, null);
  218. if (resultC != null && countC > 0)
  219. {
  220. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  221. {
  222. var json = JsonConvert.SerializeObject(row);
  223. GroupStructure dataGet = new GroupStructure(json.ToString());
  224. groups.data.Add(dataGet);
  225. }
  226. }
  227. return groups;
  228. }
  229. public ScheduleStructures editingScheduleStructure(ScheduleStructure schedule)
  230. {
  231. ScheduleStructures schedules = new ScheduleStructures();
  232. schedules.data = new List<ScheduleStructure>();
  233. var resultC = iSuperCmsRepo.EditingScheduleStructure(log, schedule);
  234. var propertyC = typeof(ICollection).GetProperty("Count");
  235. int countC = (int)propertyC.GetValue(resultC, null);
  236. if (resultC != null && countC > 0)
  237. {
  238. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  239. {
  240. var json = JsonConvert.SerializeObject(row);
  241. ScheduleStructure dataGet = new ScheduleStructure(json.ToString());
  242. schedules.data.Add(dataGet);
  243. }
  244. }
  245. return schedules;
  246. }
  247. public Configs editingConfig(Config config)
  248. {
  249. Configs configs = new Configs();
  250. configs.data = new List<Config>();
  251. var resultC = iSuperCmsRepo.EditingConfig(log, config);
  252. var propertyC = typeof(ICollection).GetProperty("Count");
  253. int countC = (int)propertyC.GetValue(resultC, null);
  254. if (resultC != null && countC > 0)
  255. {
  256. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  257. {
  258. var json = JsonConvert.SerializeObject(row);
  259. Config dataGet = new Config(json.ToString());
  260. configs.data.Add(dataGet);
  261. }
  262. }
  263. return configs;
  264. }
  265. public Boolean deleteStructure(String tableType, String id)
  266. {
  267. ResponseStructures response = new ResponseStructures();
  268. response.data = new List<ResponseStructure>();
  269. var resultC = iSuperCmsRepo.DeleteStructure(log, tableType, id);
  270. var propertyC = typeof(ICollection).GetProperty("Count");
  271. int countC = (int)propertyC.GetValue(resultC, null);
  272. if (resultC != null && countC > 0)
  273. {
  274. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  275. {
  276. var json = JsonConvert.SerializeObject(row);
  277. ResponseStructure dataGet = new ResponseStructure(json.ToString());
  278. response.data.Add(dataGet);
  279. }
  280. }
  281. if (response.data[0].code == Constant.SUCCESS)
  282. {
  283. return true;
  284. }
  285. else
  286. {
  287. return false;
  288. }
  289. }
  290. public SendMails getSendMails()
  291. {
  292. SendMails sendMails = new SendMails();
  293. sendMails.data = new List<SendMail>();
  294. var resultC = iSuperCmsRepo.GetAllSendMails(log);
  295. var propertyC = typeof(ICollection).GetProperty("Count");
  296. int countC = (int)propertyC.GetValue(resultC, null);
  297. if (resultC != null && countC > 0)
  298. {
  299. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  300. {
  301. var json = JsonConvert.SerializeObject(row);
  302. SendMail dataGet = new SendMail(json.ToString());
  303. sendMails.data.Add(dataGet);
  304. }
  305. }
  306. return sendMails;
  307. }
  308. public SendMails addingSendMail(SendMail sendMail)
  309. {
  310. SendMails sendMails = new SendMails();
  311. sendMails.data = new List<SendMail>();
  312. var resultC = iSuperCmsRepo.AddingSendMail(log, sendMail);
  313. var propertyC = typeof(ICollection).GetProperty("Count");
  314. int countC = (int)propertyC.GetValue(resultC, null);
  315. if (resultC != null && countC > 0)
  316. {
  317. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  318. {
  319. var json = JsonConvert.SerializeObject(row);
  320. SendMail dataGet = new SendMail(json.ToString());
  321. sendMails.data.Add(dataGet);
  322. }
  323. }
  324. return sendMails;
  325. }
  326. public SendMails editingSendMail(SendMail sendMail)
  327. {
  328. SendMails sendMails = new SendMails();
  329. sendMails.data = new List<SendMail>();
  330. var resultC = iSuperCmsRepo.EditingSendMail(log, sendMail);
  331. var propertyC = typeof(ICollection).GetProperty("Count");
  332. int countC = (int)propertyC.GetValue(resultC, null);
  333. if (resultC != null && countC > 0)
  334. {
  335. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  336. {
  337. var json = JsonConvert.SerializeObject(row);
  338. SendMail dataGet = new SendMail(json.ToString());
  339. sendMails.data.Add(dataGet);
  340. }
  341. }
  342. return sendMails;
  343. }
  344. public ConnConfigs getConnConfigs()
  345. {
  346. ConnConfigs data = new ConnConfigs();
  347. data.data = new List<ConnConfig>();
  348. var resultC = iSuperCmsRepo.GetConnConfig(log);
  349. var propertyC = typeof(ICollection).GetProperty("Count");
  350. int countC = (int)propertyC.GetValue(resultC, null);
  351. if (resultC != null && countC > 0)
  352. {
  353. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  354. {
  355. var json = JsonConvert.SerializeObject(row);
  356. ConnConfig dataGet = new ConnConfig(json.ToString());
  357. data.data.Add(dataGet);
  358. }
  359. }
  360. return data;
  361. }
  362. public ConnTelcos getConnTelcos()
  363. {
  364. ConnTelcos data = new ConnTelcos();
  365. data.data = new List<ConnTelco>();
  366. var resultT = iSuperCmsRepo.GetConnTelco(log);
  367. var propertyT = typeof(ICollection).GetProperty("Count");
  368. int countT = (int)propertyT.GetValue(resultT, null);
  369. if (resultT != null && countT > 0)
  370. {
  371. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultT)
  372. {
  373. var json = JsonConvert.SerializeObject(row);
  374. ConnTelco dataGet = new ConnTelco(json.ToString());
  375. data.data.Add(dataGet);
  376. }
  377. //sort
  378. data.data.Sort(delegate (ConnTelco x, ConnTelco y)
  379. {
  380. return int.Parse(x.id).CompareTo(int.Parse(y.id));
  381. });
  382. }
  383. return data;
  384. }
  385. public ConnCompanies getConnCompanies()
  386. {
  387. ConnCompanies data = new ConnCompanies();
  388. data.data = new List<ConnCompany>();
  389. var resultT = iSuperCmsRepo.GetConnCompany(log);
  390. var propertyT = typeof(ICollection).GetProperty("Count");
  391. int countT = (int)propertyT.GetValue(resultT, null);
  392. if (resultT != null && countT > 0)
  393. {
  394. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultT)
  395. {
  396. var json = JsonConvert.SerializeObject(row);
  397. ConnCompany dataGet = new ConnCompany(json.ToString());
  398. data.data.Add(dataGet);
  399. }
  400. data.data.Sort(delegate (ConnCompany x, ConnCompany y)
  401. {
  402. return int.Parse(x.id).CompareTo(int.Parse(y.id));
  403. });
  404. }
  405. return data;
  406. }
  407. public ConnConfigs addConnConfigs(ConnConfig connConfig)
  408. {
  409. ConnConfigs data = new ConnConfigs();
  410. data.data = new List<ConnConfig>();
  411. var resultC = iSuperCmsRepo.AddConnConfig(log, connConfig);
  412. var propertyC = typeof(ICollection).GetProperty("Count");
  413. int countC = (int)propertyC.GetValue(resultC, null);
  414. if (resultC != null && countC > 0)
  415. {
  416. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  417. {
  418. var json = JsonConvert.SerializeObject(row);
  419. ConnConfig dataGet = new ConnConfig(json.ToString());
  420. data.data.Add(dataGet);
  421. }
  422. }
  423. return data;
  424. }
  425. public ConnConfigs editConnConfigs(ConnConfig connConfig)
  426. {
  427. ConnConfigs data = new ConnConfigs();
  428. data.data = new List<ConnConfig>();
  429. var resultC = iSuperCmsRepo.EditConnConfig(log, connConfig);
  430. var propertyC = typeof(ICollection).GetProperty("Count");
  431. int countC = (int)propertyC.GetValue(resultC, null);
  432. if (resultC != null && countC > 0)
  433. {
  434. foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
  435. {
  436. var json = JsonConvert.SerializeObject(row);
  437. ConnConfig dataGet = new ConnConfig(json.ToString());
  438. data.data.Add(dataGet);
  439. }
  440. }
  441. return data;
  442. }
  443. }
  444. }