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("telcos"); if (telcos == null) { telcos = oracle.getConnTelcos(); HttpContext.Session.SetComplexData("telcos", telcos); } model.telcos = telcos; ConnCompanies companies = HttpContext.Session.GetComplexData("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("telcos"); ConnCompanies companies = HttpContext.Session.GetComplexData("companies"); ConnConfigs services = HttpContext.Session.GetComplexData("services"); model.telcos = telcos; model.companies = companies; model.services = new ConnConfigs(); List disByTelcoAndCompany = HttpContext.Session.GetComplexData>("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("telcos"); ConnCompanies companies = HttpContext.Session.GetComplexData("companies"); ConnConfigs services = HttpContext.Session.GetComplexData("services"); model.telcos = telcos; model.companies = companies; model.services = new ConnConfigs(); List disByTelcoAndCompany = HttpContext.Session.GetComplexData>("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("bots"); GroupStructures groups = HttpContext.Session.GetComplexData("groups"); Configs configs = HttpContext.Session.GetComplexData("configs"); SendMails sendMails = HttpContext.Session.GetComplexData("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("telcos"); ConnCompanies companies = HttpContext.Session.GetComplexData("companies"); model.telcos = telcos; model.companies = companies; List disByTelcoAndCompany = HttpContext.Session.GetComplexData>("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("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("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("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("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("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("page"); //data.timeSend = convertToDateTimeServer(data.timeSend); ConnTelcos telcos = HttpContext.Session.GetComplexData("telcos"); ConnCompanies companies = HttpContext.Session.GetComplexData("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("bots"); GroupStructures groups = HttpContext.Session.GetComplexData("groups"); ScheduleStructures schedules = HttpContext.Session.GetComplexData("schedules"); Configs configs = HttpContext.Session.GetComplexData("configs"); SendMails sendMails = HttpContext.Session.GetComplexData("sendMails"); ConnConfigs connConfigs = HttpContext.Session.GetComplexData("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("telcos"); ConnCompanies companies = HttpContext.Session.GetComplexData("companies"); ConnConfigs services = HttpContext.Session.GetComplexData("services"); List disByTelcoAndCompany = HttpContext.Session.GetComplexData>("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("telcos"); ConnCompanies companies = HttpContext.Session.GetComplexData("companies"); ConnConfigs services = HttpContext.Session.GetComplexData("services"); List disByTelcoAndCompany = HttpContext.Session.GetComplexData>("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("page"); BotStructure bot = HttpContext.Session.GetComplexData("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("page"); GroupStructure group = HttpContext.Session.GetComplexData("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("page"); ScheduleStructure schedule = HttpContext.Session.GetComplexData("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("page"); SendMail sendMail = HttpContext.Session.GetComplexData("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("page"); Config config = HttpContext.Session.GetComplexData("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("page"); ConnConfig connConfig = HttpContext.Session.GetComplexData("service"); data.id = connConfig.id; ConnTelcos telcos = HttpContext.Session.GetComplexData("telcos"); ConnCompanies companies = HttpContext.Session.GetComplexData("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("page"); BotStructures bots = HttpContext.Session.GetComplexData("bots"); GroupStructures groups = HttpContext.Session.GetComplexData("groups"); ScheduleStructures schedules = HttpContext.Session.GetComplexData("schedules"); SendMails sendMails = HttpContext.Session.GetComplexData("sendMails"); ConnConfigs connConfigs = HttpContext.Session.GetComplexData("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" }); } } } }