| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using ReportWeb.Models;
- using SuperAdmin;
- using SuperAdmin.Controllers;
- using SuperAdmin.Source;
- using SuperCms.Extensions;
- using System;
- using System.Collections.Generic;
- namespace ReportWeb.Controllers
- {
- public class ScenarioController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- DbConnector db = new DbConnector();
- String sdf = "dd/MM/yyyy HH:mm";
- String df = "dd/MM/yyyy";
- public ScenarioController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
- {
- // init
- }
- public IActionResult Index()
- {
- return View();
- }
- public ActionResult ScenarioPlay()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Redirect(subDomain + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public ActionResult SearchScenario()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<ScenarioPlayObj> list = db.LoadListScenario();
- return PartialView("_ListMsisdn", list);
- //return Json(new
- //{
- // error = "0",
- // list = list
- //});
- }
- [HttpPost]
- public ActionResult AddUpdateScenario(ScenarioPlayObj scenario, int isUpdate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- if (isUpdate > 0)
- {
- db.UpdateScenarioPlay(scenario);
- }
- else
- {
- db.InsertScenarioPlay(scenario);
- }
- // Returns message that successfully uploaded
- return Json(new
- {
- error = "0",
- scenarioId = scenario.id
- });
- }
- catch (Exception ex)
- {
- return Json(new
- {
- error = "2",
- content = "Error occurred. Error details: " + ex.Message
- });
- }
- }
- [HttpPost]
- public ActionResult UpdateScenarioStatus()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String status = Request.Form["status"];
- int id = int.Parse(Request.Form["id"]);
- db.UpdateScenarioStatus(id, status);
- return Json(new
- {
- error = "0",
- content = "Success"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public JsonResult GetScenarioById(String id)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- ScenarioPlayObj scenario = db.GetScenarioById(int.Parse(id))[0];
- return Json(new
- {
- error = "0",
- scenario = scenario
- });
- }
- // LIST MSISDN
- public IActionResult ListMsisdn()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Redirect(subDomain + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public JsonResult SearchListMsisdn()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<PhoneInfo> list = db.LoadListMsisdn();
- return Json(new
- {
- error = "0",
- list = list
- });
- }
- [HttpPost]
- public IActionResult AddUpdateMsisdn(PhoneInfo obj, int isUpdate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- if (isUpdate > 0)
- {
- db.UpdateListMsisdn(obj);
- }
- else
- {
- db.InsertListMsisdn(obj);
- }
- // Returns message that successfully uploaded
- return Json(new
- {
- error = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new
- {
- error = "2",
- content = "Error occurred. Error details: " + ex.Message
- });
- }
- }
- [HttpPost]
- public IActionResult UpdateMsisdnStatus()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String status = Request.Form["status"];
- long id = long.Parse(Request.Form["id"]);
- db.UpdateListMsisdnStatus(id, status);
- return Json(new
- {
- error = "0",
- content = "Success"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public JsonResult GetListMsisdnById(String id)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- PhoneInfo data = db.GetListMsisdnById(id)[0];
- return Json(new
- {
- error = "0",
- data = data
- });
- }
- // CONFIGURATION
- public IActionResult Configure()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Redirect(subDomain + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public IActionResult SearchConfigure()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<ToolConfig> list = db.LoadListToolConfig();
- return PartialView("_Configure", list);
- //return Json(new
- //{
- // error = "0",
- // list = list
- //});
- }
- [HttpPost]
- public IActionResult AddUpdateConfigure(ToolConfig obj, int isUpdate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- bool result = false;
- if (isUpdate > 0)
- {
- result = db.UpdateToolConfig(obj);
- }
- // Returns message that successfully uploaded
- if (result)
- {
- return Json(new
- {
- error = "0"
- });
- }
- else
- {
- return Json(new
- {
- error = "2",
- content = "DB Error"
- });
- }
- }
- catch (Exception ex)
- {
- return Json(new
- {
- error = "2",
- content = "Error occurred. Error details: " + ex.Message
- });
- }
- }
- [HttpPost]
- public JsonResult GetConfigureById(String id)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- ToolConfig data = db.GetToolConfigById(int.Parse(id))[0];
- return Json(new
- {
- error = "0",
- data = data
- });
- }
- public IActionResult ReportDay()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return View("Login");
- }
- else
- {
- return View();
- }
- }
- [HttpPost]
- public IActionResult GetReportDay(String fromDate, String toDate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- ViewBag.username = "Welcome!";
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- DateTime startTime = DateTime.ParseExact(fromDate, df, null);
- DateTime endTime = DateTime.ParseExact(toDate, df, null);
- List<ScenarioReport> res = db.GetScenarioReportDay(startTime, endTime);
- return PartialView("_ReportDay", res);
- }
- }
- }
|