| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using SuperCms.Models;
- using SuperCms.Repositories;
- using static SuperCms.Controllers.UtilsController;
- namespace SuperCms.Controllers
- {
- public class OracleController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- private readonly ILogger<ReportController> _logger;
- ISuperCmsRepo iSuperCmsRepo;
- public OracleController(ISuperCmsRepo ISuperCmsRepo)
- {
- iSuperCmsRepo = ISuperCmsRepo;
- }
- // get all schedules within today
- public BotStructures getBotstructures()
- {
- BotStructures bots = new BotStructures();
- bots.data = new List<BotStructure>();
- var resultC = iSuperCmsRepo.GetAllBots(log);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- BotStructure dataGet = new BotStructure(json.ToString());
- bots.data.Add(dataGet);
- }
- }
- return bots;
- }
- public ScheduleStructures getSchedulestructures(String seqPage, String rowsOnPage)
- {
- ScheduleStructures schedules = new ScheduleStructures();
- schedules.data = new List<ScheduleStructure>();
- var resultC = iSuperCmsRepo.GetScheduleByRow(log, seqPage, rowsOnPage);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- ScheduleStructure dataGet = new ScheduleStructure(json.ToString());
- schedules.data.Add(dataGet);
- }
- }
- return schedules;
- }
- public GroupStructures getGroupstructures()
- {
- GroupStructures groups = new GroupStructures();
- groups.data = new List<GroupStructure>();
- var resultC = iSuperCmsRepo.GetAllGroups(log);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- GroupStructure dataGet = new GroupStructure(json.ToString());
- groups.data.Add(dataGet);
- }
- }
- return groups;
- }
- public Configs getConfigs()
- {
- Configs configs = new Configs();
- configs.data = new List<Config>();
- var resultC = iSuperCmsRepo.GetAllConfigs(log);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- Config dataGet = new Config(json.ToString());
- configs.data.Add(dataGet);
- }
- }
- return configs;
- }
- public String getTotalRow(String type, String rowsOnPage)
- {
- ScheduleStructures schedules = new ScheduleStructures();
- schedules.data = new List<ScheduleStructure>();
- var resultC = iSuperCmsRepo.GetTotalRow(log, type);
- String number = "1";
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JObject.Parse(JsonConvert.SerializeObject(row));
- number = (string)json["COUNT(*)"].ToString();
- }
- int totalPage = int.Parse(number) / int.Parse(rowsOnPage);
- if (int.Parse(number) % int.Parse(rowsOnPage) != 0)
- {
- totalPage++;
- }
- number = totalPage.ToString();
- }
- return number;
- }
- public BotStructures addingBotStructure(BotStructure bot)
- {
- BotStructures bots = new BotStructures();
- bots.data = new List<BotStructure>();
- var resultC = iSuperCmsRepo.AddingBotStructure(log, bot);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- BotStructure dataGet = new BotStructure(json.ToString());
- bots.data.Add(dataGet);
- }
- }
- return bots;
- }
- public GroupStructures addingGroupStructure(GroupStructure group)
- {
- GroupStructures groups = new GroupStructures();
- groups.data = new List<GroupStructure>();
- var resultC = iSuperCmsRepo.AddingGroupStructure(log, group);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- GroupStructure dataGet = new GroupStructure(json.ToString());
- groups.data.Add(dataGet);
- }
- }
- return groups;
- }
- public ScheduleStructures addingScheduleStructure(ScheduleStructure schedule)
- {
- ScheduleStructures schedules = new ScheduleStructures();
- schedules.data = new List<ScheduleStructure>();
- var resultC = iSuperCmsRepo.AddingScheduleStructure(log, schedule);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- ScheduleStructure dataGet = new ScheduleStructure(json.ToString());
- schedules.data.Add(dataGet);
- }
- }
- return schedules;
- }
- public Configs addingConfig(Config config)
- {
- Configs configs = new Configs();
- configs.data = new List<Config>();
- var resultC = iSuperCmsRepo.AddingConfig(log, config);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- Config dataGet = new Config(json.ToString());
- configs.data.Add(dataGet);
- }
- }
- return configs;
- }
- public BotStructures editingBotStructure(BotStructure bot)
- {
- BotStructures bots = new BotStructures();
- bots.data = new List<BotStructure>();
- var resultC = iSuperCmsRepo.EditingBotStructure(log, bot);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- BotStructure dataGet = new BotStructure(json.ToString());
- bots.data.Add(dataGet);
- }
- }
- return bots;
- }
- public GroupStructures editingGroupStructure(GroupStructure group)
- {
- GroupStructures groups = new GroupStructures();
- groups.data = new List<GroupStructure>();
- var resultC = iSuperCmsRepo.EditingGroupStructure(log, group);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- GroupStructure dataGet = new GroupStructure(json.ToString());
- groups.data.Add(dataGet);
- }
- }
- return groups;
- }
- public ScheduleStructures editingScheduleStructure(ScheduleStructure schedule)
- {
- ScheduleStructures schedules = new ScheduleStructures();
- schedules.data = new List<ScheduleStructure>();
- var resultC = iSuperCmsRepo.EditingScheduleStructure(log, schedule);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- ScheduleStructure dataGet = new ScheduleStructure(json.ToString());
- schedules.data.Add(dataGet);
- }
- }
- return schedules;
- }
- public Configs editingConfig(Config config)
- {
- Configs configs = new Configs();
- configs.data = new List<Config>();
- var resultC = iSuperCmsRepo.EditingConfig(log, config);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- Config dataGet = new Config(json.ToString());
- configs.data.Add(dataGet);
- }
- }
- return configs;
- }
- public Boolean deleteStructure(String tableType, String id)
- {
- ResponseStructures response = new ResponseStructures();
- response.data = new List<ResponseStructure>();
- var resultC = iSuperCmsRepo.DeleteStructure(log, tableType, id);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- ResponseStructure dataGet = new ResponseStructure(json.ToString());
- response.data.Add(dataGet);
- }
- }
- if (response.data[0].code == Constant.SUCCESS)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public SendMails getSendMails()
- {
- SendMails sendMails = new SendMails();
- sendMails.data = new List<SendMail>();
- var resultC = iSuperCmsRepo.GetAllSendMails(log);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- SendMail dataGet = new SendMail(json.ToString());
- sendMails.data.Add(dataGet);
- }
- }
- return sendMails;
- }
- public SendMails addingSendMail(SendMail sendMail)
- {
- SendMails sendMails = new SendMails();
- sendMails.data = new List<SendMail>();
- var resultC = iSuperCmsRepo.AddingSendMail(log, sendMail);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- SendMail dataGet = new SendMail(json.ToString());
- sendMails.data.Add(dataGet);
- }
- }
- return sendMails;
- }
- public SendMails editingSendMail(SendMail sendMail)
- {
- SendMails sendMails = new SendMails();
- sendMails.data = new List<SendMail>();
- var resultC = iSuperCmsRepo.EditingSendMail(log, sendMail);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- SendMail dataGet = new SendMail(json.ToString());
- sendMails.data.Add(dataGet);
- }
- }
- return sendMails;
- }
- public ConnConfigs getConnConfigs()
- {
- ConnConfigs data = new ConnConfigs();
- data.data = new List<ConnConfig>();
- var resultC = iSuperCmsRepo.GetConnConfig(log);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- ConnConfig dataGet = new ConnConfig(json.ToString());
- data.data.Add(dataGet);
- }
- }
- return data;
- }
- public ConnTelcos getConnTelcos()
- {
- ConnTelcos data = new ConnTelcos();
- data.data = new List<ConnTelco>();
- var resultT = iSuperCmsRepo.GetConnTelco(log);
- var propertyT = typeof(ICollection).GetProperty("Count");
- int countT = (int)propertyT.GetValue(resultT, null);
- if (resultT != null && countT > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultT)
- {
- var json = JsonConvert.SerializeObject(row);
- ConnTelco dataGet = new ConnTelco(json.ToString());
- data.data.Add(dataGet);
- }
- //sort
- data.data.Sort(delegate (ConnTelco x, ConnTelco y)
- {
- return int.Parse(x.id).CompareTo(int.Parse(y.id));
- });
- }
- return data;
- }
- public ConnCompanies getConnCompanies()
- {
- ConnCompanies data = new ConnCompanies();
- data.data = new List<ConnCompany>();
- var resultT = iSuperCmsRepo.GetConnCompany(log);
- var propertyT = typeof(ICollection).GetProperty("Count");
- int countT = (int)propertyT.GetValue(resultT, null);
- if (resultT != null && countT > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultT)
- {
- var json = JsonConvert.SerializeObject(row);
- ConnCompany dataGet = new ConnCompany(json.ToString());
- data.data.Add(dataGet);
- }
- data.data.Sort(delegate (ConnCompany x, ConnCompany y)
- {
- return int.Parse(x.id).CompareTo(int.Parse(y.id));
- });
- }
- return data;
- }
- public ConnConfigs addConnConfigs(ConnConfig connConfig)
- {
- ConnConfigs data = new ConnConfigs();
- data.data = new List<ConnConfig>();
- var resultC = iSuperCmsRepo.AddConnConfig(log, connConfig);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- ConnConfig dataGet = new ConnConfig(json.ToString());
- data.data.Add(dataGet);
- }
- }
- return data;
- }
- public ConnConfigs editConnConfigs(ConnConfig connConfig)
- {
- ConnConfigs data = new ConnConfigs();
- data.data = new List<ConnConfig>();
- var resultC = iSuperCmsRepo.EditConnConfig(log, connConfig);
- var propertyC = typeof(ICollection).GetProperty("Count");
- int countC = (int)propertyC.GetValue(resultC, null);
- if (resultC != null && countC > 0)
- {
- foreach (IDictionary<string, object> row in (IEnumerable<object>)resultC)
- {
- var json = JsonConvert.SerializeObject(row);
- ConnConfig dataGet = new ConnConfig(json.ToString());
- data.data.Add(dataGet);
- }
- }
- return data;
- }
- }
- }
|