| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using SuperCms.Extensions;
- using SuperCms.Models;
- using SuperCms.Repositories;
- namespace SuperCms.Controllers
- {
- public class ConfigController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- private OracleController oracle;
- ISuperCmsRepo iSuperCmsRepo;
- public ConfigController(ISuperCmsRepo ISuperCmsRepo)
- {
- iSuperCmsRepo = ISuperCmsRepo;
- }
- public IActionResult Index(String tableType, String page)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect("/Home/Login");
- }
- oracle = new OracleController(iSuperCmsRepo);
- String pageNow = page != null ? page : "1";
- HttpContext.Session.SetComplexData("page", pageNow);
- String type = tableType != null ? tableType : UtilsController.Constant.BOTS;
- ConfigViewModel model = new ConfigViewModel();
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- if (telcos == null)
- {
- telcos = oracle.getConnTelcos();
- HttpContext.Session.SetComplexData("telcos", telcos);
- }
- model.telcos = telcos;
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- if (companies == null)
- {
- companies = oracle.getConnCompanies();
- HttpContext.Session.SetComplexData("companies", companies);
- }
- model.companies = companies;
- ConnConfigs services = oracle.getConnConfigs();
- HttpContext.Session.SetComplexData("services", services);
- model.services = services;
- // get all bots
- BotStructures bots = oracle.getBotstructures();
- GroupStructures groups = oracle.getGroupstructures();
- Configs configs = oracle.getConfigs();
- // get all send mail
- SendMails sendMails = oracle.getSendMails();
- //save to session
- HttpContext.Session.SetComplexData("configs", configs);
- HttpContext.Session.SetComplexData("bots", bots);
- HttpContext.Session.SetComplexData("groups", groups);
- HttpContext.Session.SetComplexData("sendMails", sendMails);
- HttpContext.Session.SetComplexData("services", services);
- ScheduleStructures schedules = oracle.getSchedulestructures(pageNow, UtilsController.Constant.NUMBER_ROW_ON_PAGE);
- HttpContext.Session.SetComplexData("schedules", schedules);
- model.totalPage = type == UtilsController.Constant.SERVICE_CONFIG ? "1" : oracle.getTotalRow(type, UtilsController.Constant.NUMBER_ROW_ON_PAGE);
- model.configs = configs;
- model.bots = bots;
- model.groups = groups;
- model.sendMails = sendMails;
- model.schedules = schedules;
- model.services = services;
- model.companies = companies;
- model.telcos = telcos;
- model.tableType = type;
- model.page = pageNow;
- return View("Index", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception: ", ex);
- return Redirect("/Home");
- }
- }
- public IActionResult ExportSendMail(String tableType, SendMail data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect("/Home/Login");
- }
- ConfigViewModel model = new ConfigViewModel();
- model.tableType = tableType != null ? tableType : UtilsController.Constant.SENDMAIL;
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
- model.telcos = telcos;
- model.companies = companies;
- model.services = new ConnConfigs();
- List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
- DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == data.telcoId);
- if (dis == null)
- {
- model.telco = disByTelcoAndCompany[0].telco;
- model.company = disByTelcoAndCompany[0].companies.data[0];
- model.services.data = services.data.FindAll(x => x.telcoID == data.telcoId && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
- }
- else
- {
- model.telco = dis.telco;
- model.companies = dis.companies;
- model.company = data.companyId != null && data.companyId != "null" ? dis.companies.data.Find(x => x.id == data.companyId) : dis.companies.data[0];
- 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));
- }
- model.sendMail = data;
- return PartialView("Adding", model);
- }
- catch (Exception ex)
- {
- return Redirect("/Home");
- }
- }
- public IActionResult ExportService(String tableType, ConnConfig data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect("/Home/Login");
- }
- ConfigViewModel model = new ConfigViewModel();
- model.tableType = tableType != null ? tableType : UtilsController.Constant.SERVICE_CONFIG;
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
- model.telcos = telcos;
- model.companies = companies;
- model.services = new ConnConfigs();
- List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
- DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == data.telcoID);
- if (dis == null)
- {
- model.telco = disByTelcoAndCompany[0].telco;
- model.company = disByTelcoAndCompany[0].companies.data[0];
- model.services.data = services.data.FindAll(x => x.telcoID == data.telcoID && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
- }
- else
- {
- model.telco = dis.telco;
- model.companies = dis.companies;
- model.company = data.companyID != null && data.companyID != "null" ? dis.companies.data.Find(x => x.id == data.companyID) : dis.companies.data[0];
- 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));
- }
- model.service = data;
- return PartialView("Adding", model);
- }
- catch (Exception ex)
- {
- return Redirect("/Home");
- }
- }
- public IActionResult Adding(String tableType)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect("/Home/Login");
- }
- ConfigViewModel model = new ConfigViewModel();
- model.bots = new BotStructures();
- model.groups = new GroupStructures();
- model.tableType = tableType;
- BotStructures bots = HttpContext.Session.GetComplexData<BotStructures>("bots");
- GroupStructures groups = HttpContext.Session.GetComplexData<GroupStructures>("groups");
- Configs configs = HttpContext.Session.GetComplexData<Configs>("configs");
- SendMails sendMails = HttpContext.Session.GetComplexData<SendMails>("sendMails");
- model.bots.data = bots.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
- model.groups.data = groups.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- model.telcos = telcos;
- model.companies = companies;
- List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
- model.telco = disByTelcoAndCompany[0].telco;
- model.company = disByTelcoAndCompany[0].companies.data[0];
- model.services = disByTelcoAndCompany[0].services;
- return PartialView("Adding", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception: ", ex);
- return Redirect("/Home");
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult AddingBotAction(BotStructure data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- data.startDate = convertToDateTimeServer(data.startDate);
- data.endDate = convertToDateTimeServer(data.endDate);
- oracle = new OracleController(iSuperCmsRepo);
- BotStructures bots = oracle.addingBotStructure(data);
- if (bots.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult AddingGroupAction(GroupStructure data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- data.startDate = convertToDateTimeServer(data.startDate);
- data.endDate = convertToDateTimeServer(data.endDate);
- oracle = new OracleController(iSuperCmsRepo);
- GroupStructures groups = oracle.addingGroupStructure(data);
- if (groups.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult AddingScheduleAction(ScheduleStructure data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- data.timeRun = convertToDateTimeServer(data.timeRun);
- oracle = new OracleController(iSuperCmsRepo);
- ScheduleStructures schedules = oracle.addingScheduleStructure(data);
- if (schedules.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult AddingConfigAction(Config data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- oracle = new OracleController(iSuperCmsRepo);
- Configs configs = oracle.addingConfig(data);
- if (configs.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult AddingSendMailAction(SendMail data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- data.timeSend = convertToDateTimeServer(data.timeSend);
- oracle = new OracleController(iSuperCmsRepo);
- SendMails sendMails = oracle.addingSendMail(data);
- if (sendMails.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult AddingServiceAction(ConnConfig data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- //data.timeSend = convertToDateTimeServer(data.timeSend);
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- ConnCompany company = companies.data.Find(x => x.id == data.companyID);
- ConnTelco telco = telcos.data.Find(x => x.id == data.telcoID);
- data.telco = telco.telcoName;
- String timeNow = DateTime.Now.ToString("dd/MM/yyyy");
- data.totalRun = "0";
- data.dateRun = timeNow;
- data.dateGet = timeNow;
- data.hourRun = data.hourRun + ":00";
- oracle = new OracleController(iSuperCmsRepo);
- ConnConfigs connConfigs = oracle.addConnConfigs(data);
- if (connConfigs.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- public IActionResult Editing(String tableType, String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect("/Home/Login");
- }
- ConfigViewModel model = new ConfigViewModel();
- model.tableType = tableType;
- model.bots = new BotStructures();
- model.groups = new GroupStructures();
- BotStructures bots = HttpContext.Session.GetComplexData<BotStructures>("bots");
- GroupStructures groups = HttpContext.Session.GetComplexData<GroupStructures>("groups");
- ScheduleStructures schedules = HttpContext.Session.GetComplexData<ScheduleStructures>("schedules");
- Configs configs = HttpContext.Session.GetComplexData<Configs>("configs");
- SendMails sendMails = HttpContext.Session.GetComplexData<SendMails>("sendMails");
- ConnConfigs connConfigs = HttpContext.Session.GetComplexData<ConnConfigs>("services");
- if (tableType == UtilsController.Constant.BOTS)
- {
- BotStructure bot = bots.data.Find(x => x.id == id);
- if (bot == null)
- {
- log.Error("No existed bot: " + id);
- return Redirect("/Home");
- }
- model.bot = bot;
- HttpContext.Session.SetComplexData("bot", bot);
- }
- else if (tableType == UtilsController.Constant.GROUPS)
- {
- GroupStructure group = groups.data.Find(x => x.id == id);
- if (group == null)
- {
- log.Error("No existed group: " + id);
- return Redirect("/Home");
- }
- model.group = group;
- HttpContext.Session.SetComplexData("group", group);
- }
- else if (tableType == UtilsController.Constant.SCHEDULES)
- {
- ScheduleStructure schedule = schedules.data.Find(x => x.id == id);
- if (schedule == null)
- {
- log.Error("No existed schedule: " + id);
- return Redirect("/Home");
- }
- model.schedule = schedule;
- HttpContext.Session.SetComplexData("schedule", schedule);
- }
- else if (tableType == UtilsController.Constant.CONFIGS)
- {
- Config config = configs.data.Find(x => x.id == id);
- if (config == null)
- {
- log.Error("No existed config: " + id);
- return Redirect("/Home");
- }
- model.config = config;
- HttpContext.Session.SetComplexData("config", config);
- }
- else if (tableType == UtilsController.Constant.SENDMAIL)
- {
- SendMail sendMail = sendMails.data.Find(x => x.id == id);
- if (sendMail == null)
- {
- log.Error("No existed config: " + id);
- return Redirect("/Home");
- }
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
- List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
- DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == sendMail.telcoId);
- model.telcos = telcos;
- model.companies = companies;
- model.services = new ConnConfigs();
- if (dis == null)
- {
- model.telco = disByTelcoAndCompany[0].telco;
- model.company = disByTelcoAndCompany[0].companies.data[0];
- model.services.data = services.data.FindAll(x => x.telcoID == sendMail.telcoId && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
- }
- else
- {
- model.telco = dis.telco;
- model.companies = dis.companies;
- model.company = dis.companies.data.Find(x => x.id == sendMail.companyId);
- model.services.data = services.data.FindAll(x => x.telcoID == sendMail.telcoId && x.companyID == sendMail.companyId);
- }
- model.service = services.data.Find(x => x.id == sendMail.serviceId);
- model.sendMail = sendMail;
- HttpContext.Session.SetComplexData("sendMail", sendMail);
- }
- else if (tableType == UtilsController.Constant.SERVICE_CONFIG)
- {
- ConnConfig connConfig = connConfigs.data.Find(x => x.id == id);
- if (connConfig == null)
- {
- log.Error("No existed config: " + id);
- return Redirect("/Home");
- }
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- ConnConfigs services = HttpContext.Session.GetComplexData<ConnConfigs>("services");
- List<DistributedByTelcoAndCompany> disByTelcoAndCompany = HttpContext.Session.GetComplexData<List<DistributedByTelcoAndCompany>>("distributedByTelcoAndCompany");
- DistributedByTelcoAndCompany dis = disByTelcoAndCompany.Find(x => x.telco.id == connConfig.telcoID);
- model.telcos = telcos;
- model.companies = companies;
- model.services = new ConnConfigs();
- model.service = connConfig;
- if (dis == null)
- {
- model.telco = disByTelcoAndCompany[0].telco;
- model.company = disByTelcoAndCompany[0].companies.data[0];
- model.services.data = services.data.FindAll(x => x.telcoID == connConfig.telcoID && x.companyID == disByTelcoAndCompany[0].companies.data[0].id);
- }
- else
- {
- model.telco = dis.telco;
- model.companies = dis.companies;
- model.company = dis.companies.data.Find(x => x.id == connConfig.companyID);
- model.services.data = services.data.FindAll(x => x.telcoID == connConfig.telcoID && x.companyID == connConfig.companyID);
- }
- HttpContext.Session.SetComplexData("service", connConfig);
- }
- else
- {
- log.Error("No existed table type: " + tableType);
- return Redirect("/Home");
- }
- model.bots.data = bots.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
- model.groups.data = groups.data.FindAll(x => x.status != UtilsController.Constant.DISABLE);
- return PartialView("Editing", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception: ", ex);
- return Redirect("/Home");
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult EditingBotAction(BotStructure data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- BotStructure bot = HttpContext.Session.GetComplexData<BotStructure>("bot");
- data.id = bot.id;
- data.startDate = convertToDateTimeServer(data.startDate);
- data.endDate = convertToDateTimeServer(data.endDate);
- oracle = new OracleController(iSuperCmsRepo);
- BotStructures bots = oracle.editingBotStructure(data);
- if (bots.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.BOTS + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult EditingGroupAction(GroupStructure data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- GroupStructure group = HttpContext.Session.GetComplexData<GroupStructure>("group");
- data.id = group.id;
- data.startDate = convertToDateTimeServer(data.startDate);
- data.endDate = convertToDateTimeServer(data.endDate);
- oracle = new OracleController(iSuperCmsRepo);
- GroupStructures groups = oracle.editingGroupStructure(data);
- if (groups.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.GROUPS + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult EditingScheduleAction(ScheduleStructure data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- ScheduleStructure schedule = HttpContext.Session.GetComplexData<ScheduleStructure>("schedule");
- data.id = schedule.id;
- data.timeRun = convertToDateTimeServer(data.timeRun);
- oracle = new OracleController(iSuperCmsRepo);
- ScheduleStructures schedules = oracle.editingScheduleStructure(data);
- if (schedules.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.SCHEDULES + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult EditingSendMailAction(SendMail data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- SendMail sendMail = HttpContext.Session.GetComplexData<SendMail>("sendMail");
- data.id = sendMail.id;
- data.timeSend = convertToDateTimeServer(data.timeSend);
- oracle = new OracleController(iSuperCmsRepo);
- SendMails sendMails = oracle.editingSendMail(data);
- if (sendMails.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.SENDMAIL + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult EditingConfigAction(Config data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- Config config = HttpContext.Session.GetComplexData<Config>("config");
- data.id = config.id;
- oracle = new OracleController(iSuperCmsRepo);
- Configs configs = oracle.editingConfig(data);
- if (configs.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.CONFIGS + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult EditingServiceAction(ConnConfig data)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- ConnConfig connConfig = HttpContext.Session.GetComplexData<ConnConfig>("service");
- data.id = connConfig.id;
- ConnTelcos telcos = HttpContext.Session.GetComplexData<ConnTelcos>("telcos");
- ConnCompanies companies = HttpContext.Session.GetComplexData<ConnCompanies>("companies");
- ConnCompany company = companies.data.Find(x => x.id == data.companyID);
- ConnTelco telco = telcos.data.Find(x => x.id == data.telcoID);
- data.telco = telco.telcoName;
- String timeNow = DateTime.Now.ToString("dd/MM/yyyy");
- data.totalRun = "0";
- data.dateRun = timeNow;
- data.dateGet = timeNow;
- if (data.hourRun.Length > 5)
- {
- data.hourRun = data.hourRun;
- }
- else
- {
- data.hourRun = data.hourRun + ":00";
- }
- oracle = new OracleController(iSuperCmsRepo);
- ConnConfigs connConfigs = oracle.editConnConfigs(data);
- if (connConfigs.data.Count > 0)
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Config?tableType=" + UtilsController.Constant.SERVICE_CONFIG + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult DeletingAction(String tableType, String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home/Login"
- });
- }
- oracle = new OracleController(iSuperCmsRepo);
- ConfigViewModel model = new ConfigViewModel();
- model.tableType = tableType;
- String page = HttpContext.Session.GetComplexData<String>("page");
- BotStructures bots = HttpContext.Session.GetComplexData<BotStructures>("bots");
- GroupStructures groups = HttpContext.Session.GetComplexData<GroupStructures>("groups");
- ScheduleStructures schedules = HttpContext.Session.GetComplexData<ScheduleStructures>("schedules");
- SendMails sendMails = HttpContext.Session.GetComplexData<SendMails>("sendMails");
- ConnConfigs connConfigs = HttpContext.Session.GetComplexData<ConnConfigs>("services");
- if (tableType == null || id == null)
- {
- log.Error("Null ");
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- Boolean response;
- if (tableType == UtilsController.Constant.BOTS)
- {
- BotStructure bot = bots.data.Find(x => x.id == id);
- if (bot == null)
- {
- log.Error("No existed bot: " + id);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- message = "An error was happened",
- href = "/Config?tableType=" + tableType + "&page=" + page,
- });
- }
- }
- else if (tableType == UtilsController.Constant.GROUPS)
- {
- GroupStructure group = groups.data.Find(x => x.id == id);
- if (group == null)
- {
- log.Error("No existed group: " + id);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- message = "An error was happened",
- href = "/Config?tableType=" + tableType + "&page=" + page,
- });
- }
- model.group = group;
- }
- else if (tableType == UtilsController.Constant.SCHEDULES)
- {
- ScheduleStructure schedule = schedules.data.Find(x => x.id == id);
- if (schedule == null)
- {
- log.Error("No existed schedule: " + id);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- message = "An error was happened",
- href = "/Config?tableType=" + tableType + "&page=" + page,
- });
- }
- model.schedule = schedule;
- }
- else if (tableType == UtilsController.Constant.SENDMAIL)
- {
- SendMail sendMail = sendMails.data.Find(x => x.id == id);
- if (sendMail == null)
- {
- log.Error("No existed schedule: " + id);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- message = "An error was happened",
- href = "/Config?tableType=" + tableType + "&page=" + page,
- });
- }
- model.sendMail = sendMail;
- }
- else if (tableType == UtilsController.Constant.SERVICE_CONFIG)
- {
- ConnConfig connConfig = connConfigs.data.Find(x => x.id == id);
- if (connConfig == null)
- {
- log.Error("No existed connConfig: " + id);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- message = "An error was happened",
- href = "/Config?tableType=" + tableType + "&page=" + page,
- });
- }
- model.service = connConfig;
- }
- else
- {
- log.Error("No existed table type: " + tableType);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- message = "An error was happened",
- href = "/Home",
- });
- }
- response = oracle.deleteStructure(tableType, id);
- if (!response)
- {
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- message = "Delete failure",
- href = "/Config?tableType=" + tableType + "&page=" + page,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- message = "Delete successful",
- href = "/Config?tableType=" + tableType + "&page=" + page,
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.ERROR,
- href = "/Home"
- });
- }
- }
- }
- }
|