| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766 |
- using ClosedXML.Excel;
- using DocumentFormat.OpenXml.Drawing;
- using DocumentFormat.OpenXml.Wordprocessing;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Server.IISIntegration;
- using Microsoft.Extensions.Configuration;
- using Nancy;
- using OfficeOpenXml;
- using SuperAdmin.Models.Http;
- using SuperAdmin.Models.Object;
- using SuperAdmin.Source;
- using SuperCms.Extensions;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Timor_BPSuperAdmin.Models.Http;
- using static SuperAdmin.Source.CommonUtils;
- namespace SuperAdmin.Controllers
- {
- public class AdminController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- public AdminController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
- {
- }
- public IActionResult ReportUssdDetail()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public IActionResult ReportUssdDetailSearch(PushUssdDetailReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- req.rowsOnPage = req.rowsOnPage ?? "100";
- req.seqPage = req.seqPage ?? "1";
- req.order = req.order ?? "desc";
- req.msisdn = ValidateMsisdn(req.msisdn);
- String url = GetParameter(CommonUtils.WsType.PushUssdDetailGetList);
- PushUssdDetailRes res = PushUssdDetailRes.Parse(SendPost(req, url));
- var fdsds = "dsds";
- return PartialView("../Partial/_ReportUssdDetail", res.list);
- }
- [HttpPost]
- public IActionResult ReportUssdDetailExport(PushUssdDetailReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- // Áp dụng cùng logic phân trang/thứ tự như ReportUssdDetailSearch để dữ liệu export khớp với search
- req.rowsOnPage = req.rowsOnPage ?? "100";
- req.seqPage = req.seqPage ?? "1";
- req.order = req.order ?? "desc";
- String url = GetParameter(CommonUtils.WsType.PushUssdDetailGetList);
- PushUssdDetailRes res = PushUssdDetailRes.Parse(SendPost(req, url));
- var list = res.list ?? new List<PushUssdDetail>();
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "campaign_detail.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Campaign Detail");
- worksheet.Column(i).Width = 15; worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "Request ID";
- worksheet.Column(i).Width = 30; worksheet.Cell(1, i++).Value = "Campaign";
- worksheet.Column(i).Width = 18; worksheet.Cell(1, i++).Value = "Msisdn";
- worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Send Time";
- worksheet.Column(i).Width = 12; worksheet.Cell(1, i++).Value = "Send Status";
- worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "Total Step";
- worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "Is Step 1";
- worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Step 1 Time";
- worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "Is Step 2";
- worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Step 2 Time";
- worksheet.Column(i).Width = 18; worksheet.Cell(1, i++).Value = "Error Code";
- worksheet.Column(i).Width = 12; worksheet.Cell(1, i++).Value = "Is Success";
- worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Insert Time";
- worksheet.Column(i).Width = 22; worksheet.Cell(1, i++).Value = "Last Update";
- worksheet.Column(i).Width = 50; worksheet.Cell(1, i++).Value = "Msg Content";
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- if (list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).Value = obj.requestId ?? "";
- // Campaign: ID + Name (giống view)
- string campaignDisplay = obj.campaignId ?? "";
- if (!string.IsNullOrEmpty(obj.campaignName))
- {
- campaignDisplay += " - " + obj.campaignName;
- }
- worksheet.Cell(index + 1, i++).Value = campaignDisplay;
- worksheet.Cell(index + 1, i++).Value = obj.msisdn ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.sendTime ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.sendStatus ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.totalStep ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.isStep1 ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.step1Time ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.isStep2 ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.step2Time ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.errorCode ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.isSuccess ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.insertTime ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.lastUpdate ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.msgContent ?? "";
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception)
- {
- return null;
- }
- }
- public IActionResult Index(String fromDate, String toDate)
- {
- try
- {
- if (!CheckAuthToken())
- {
- //return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- UserRoles vsa = HttpContext.Session.GetComplexData<UserRoles>("userInfo");
- //var listMenu = new List<String>();
- if (vsa != null && vsa.function != null)
- {
- var listObj = vsa.function;
- foreach (Function obj in listObj)
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + obj.link);
- }
- }
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- fromDate = fromDate ?? DateTime.Now.ToString("dd/MM/yyyy 00:00:00");
- toDate = toDate ?? DateTime.Now.ToString("dd/MM/yyyy 23:59:59");
- //DashboardModel model = LoadDashboard(fromDate, toDate);
- // init
- try
- {
- var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
- if (listService == null)
- {
- PreLoadService();
- }
- }
- catch (Exception ex)
- {
- PreLoadService();
- }
- return View();
- }
- catch (Exception ex)
- {
- log.Error("Error admin index: " + ex.Message, ex);
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- }
- public IActionResult Dashboard(String fromDate, String toDate)
- {
- DashboardModel model = LoadDashboard(fromDate, toDate);
- var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
- if (listService == null)
- {
- PreLoadService();
- }
- //
- return PartialView("../Partial/_Dashboard", model);
- }
- private DashboardModel LoadDashboard(String fromDate, String toDate)
- {
- string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
- string subDomain = GetParameter(UtilsController.Constant.SUB_DOMAIN);
- HttpContext.Session.SetComplexData("serviceName", serviceName);
- HttpContext.Session.SetComplexData("subDomain", subDomain);
- //String fromDate = DateTime.Now.AddDays(-30).ToString("dd/MM/yyyy");
- //String toDate = DateTime.Now.ToString("dd/MM/yyyy");
- //
- DashboardModel model = new DashboardModel();
- string url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListReq req = new CampaignGetListReq();
- req.fromDate = fromDate;
- req.toDate = toDate;
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- // running
- req.status = CampaignStatus.Running;
- CampaignGetListRes running = CampaignGetListRes.Parse(SendPost(req, url));
- model.listRunning = running.list;
- // pending
- req.status = CampaignStatus.Pending + "," + CampaignStatus.Paused;
- CampaignGetListRes pending = CampaignGetListRes.Parse(SendPost(req, url));
- model.listPending = pending.list;
- return model;
- }
- // CAMPAIGN
- [HttpPost]
- public JsonResult UpdateCampaignStatus(String id, String status)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // get campaign by id
- string url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListReq req = new CampaignGetListReq();
- req.id = id;
- CampaignGetListRes cpRes = CampaignGetListRes.Parse(SendPost(req, url));
- var cmp = cpRes.list[0];
- // update status
- ChangeStatusReq updateReq = new ChangeStatusReq();
- updateReq.id = id;
- updateReq.status = status;
- updateReq.users = account;
- string result = SendPost(updateReq, GetParameter(CommonUtils.WsType.changeStatus));
- CommonRes res = CommonRes.Parse(result);
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- public IActionResult CampaignManagement()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- CriteriaSearchReq req = new CriteriaSearchReq();
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "asc";
- req.isActive = "1";
- // load criteria
- CriteriaGetListRes res1 = CriteriaGetListRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.balanceGetList)));
- HttpContext.Session.SetComplexData("listBalance", res1.list);
- CriteriaGetListRes res2 = CriteriaGetListRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.expGetList)));
- HttpContext.Session.SetComplexData("listExpire", res2.list);
- CriteriaGetListRes res3 = CriteriaGetListRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.shortCodeGetList)));
- HttpContext.Session.SetComplexData("listShortCode", res3.list);
- // load whitelist sub active
- GetListSubReq req2 = new GetListSubReq();
- req2.rowsOnPage = "1000000";
- req2.seqPage = "1";
- req2.order = "asc";
- req2.subType = CommonUtils.ListSubType.Whitelist;
- GetListSubRes res4 = GetListSubRes.Parse(SendPost(req, GetParameter(CommonUtils.WsType.listSubGetList)));
- HttpContext.Session.SetComplexData("listSubFile", res4.list);
- PreLoadService();
- return View();
- }
- public IActionResult CampaignSearch(CampaignGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- //string account = HttpContext.Session.GetString("account");
- //req.usersName = account;
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- //req.type = "1"; // already result
- String url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
- //HttpContext.Session.SetComplexData("ExportGetListRes", res);
- //return Json(new
- //{
- // error = res.responseCode,
- // content = res.responseMessage,
- // data = res.list
- //});
- return PartialView("../Partial/_ListCampaign", res.list);
- }
- [HttpPost]
- public IActionResult CampaignExport(CampaignGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- String url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
- var list = res.list;
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "campaigns.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Campaigns");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 30;
- worksheet.Cell(1, i++).Value = "Name";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "From date";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "To Date";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Type";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Service Type";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Services in Campaign";
- worksheet.Column(i).Width = 10;
- worksheet.Cell(1, i++).Value = "Priority";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Modify Date";
- worksheet.Column(i).Width = 10;
- worksheet.Cell(1, i++).Value = "Status";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).Value = obj.name;
- worksheet.Cell(index + 1, i++).SetValue(obj.fromDate);
- worksheet.Cell(index + 1, i++).SetValue(obj.toDate);
- worksheet.Cell(index + 1, i++).Value = obj.isDefault == "1" ? "Default" : "Normal";
- worksheet.Cell(index + 1, i++).Value = (int.Parse(obj.addType) - 1) + "-Verification";
- string services = "";
- if (obj.listServiceMapCam != null)
- {
- foreach (var sv in obj.listServiceMapCam)
- {
- services += @sv.serviceObj.name + "; ";
- }
- if (services.Length > 2)
- {
- services = services.Substring(0, services.Length - 2);
- }
- }
- worksheet.Cell(index + 1, i++).Value = services;
- worksheet.Cell(index + 1, i++).Value = obj.priority;
- worksheet.Cell(index + 1, i++).SetValue(obj.dateUpdate);
- worksheet.Cell(index + 1, i++).Value = CommonUtils.StatusToStr(obj.status);
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- [HttpPost]
- public JsonResult CampaignClone(CampaignCopyReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- request.users = account;
- // send change status
- string url = GetParameter(CommonUtils.WsType.camCopy);
- var res = CommonRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- [HttpPost]
- public IActionResult CampaignLoadInfo(CampaignGetListReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = GetParameter(CommonUtils.WsType.CamGetList);
- var res = CampaignGetListRes.Parse(SendPost(request, url));
- if (res.responseCode == "0")
- {
- return PartialView("../Partial/_Campaign", res.list[0]);
- }
- else
- {
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- }
- [HttpPost]
- public JsonResult CampaignAddUpdate(CampaignAddUpdateObj campAddUpdateObj)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- string errorContent = "";
- // check update or add
- string url = "";
- if (campAddUpdateObj.campReq.id == null || campAddUpdateObj.campReq.id == "")
- {
- url = GetParameter(CommonUtils.WsType.CamInsert);
- }
- else
- {
- url = GetParameter(CommonUtils.WsType.CamUpdate);
- }
- campAddUpdateObj.campReq.users = account;
- campAddUpdateObj.campReq.type = "0";
- //campAddUpdateObj.campReq.status = CampaignStatus.draft;
- var res = CampaignInsertRes.Parse(SendPost(campAddUpdateObj.campReq, url));
- if (res.responseCode == "0")
- {
- // create campaign success -> add service to campaign
- string campId = campAddUpdateObj.campReq.id;
- if (campId == null || campId == "")
- {
- campId = res.id;
- }
- // get info to remove
- if (campAddUpdateObj.campReq.id != null && campAddUpdateObj.campReq.id != "")
- {
- // remove service
- url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListReq getCamReq = new CampaignGetListReq();
- getCamReq.id = campAddUpdateObj.campReq.id;
- var camInfo = CampaignGetListRes.Parse(SendPost(getCamReq, url)).list[0];
- if (camInfo.listServiceMapCam != null)
- {
- url = GetParameter(CommonUtils.WsType.CamSvRemove);
- CamServiceAddReq svRemoveReq = new CamServiceAddReq();
- svRemoveReq.type = "1";
- foreach (var oldSv in camInfo.listServiceMapCam)
- {
- svRemoveReq.id = oldSv.id;
- SendPost(svRemoveReq, url);
- }
- }
- // remove criteria
- CriteriaMapCamReq criRemoveReq = new CriteriaMapCamReq();
- criRemoveReq.type = "1";
- url = GetParameter(CommonUtils.WsType.camBalanceUpdate);
- foreach (var oldSv in camInfo.listBalanceMapCam)
- {
- criRemoveReq.id = oldSv.id;
- SendPost(criRemoveReq, url);
- }
- url = GetParameter(CommonUtils.WsType.camSubUpdate);
- foreach (var oldSv in camInfo.listSubMapCam)
- {
- criRemoveReq.id = oldSv.id;
- SendPost(criRemoveReq, url);
- }
- url = GetParameter(CommonUtils.WsType.camExpireUpdate);
- foreach (var oldSv in camInfo.listExpireMapCam)
- {
- criRemoveReq.id = oldSv.id;
- SendPost(criRemoveReq, url);
- }
- url = GetParameter(CommonUtils.WsType.camShortCodeUpdate);
- foreach (var oldSv in camInfo.listShortCodeMapCam)
- {
- criRemoveReq.id = oldSv.id;
- SendPost(criRemoveReq, url);
- }
- }
- // remove old services
- //CampaignServiceListReq listSvReq = new CampaignServiceListReq();
- //listSvReq.campaignId = campId;
- //listSvReq.rowsOnPage = "1000000";
- //listSvReq.seqPage = "1";
- //url = GetParameter(CommonUtils.WsType.CamSvGetList);
- //var listSvRes = CampaignServiceListRes.Parse(SendPost(listSvReq, url));
- //if (listSvRes.list != null)
- //{
- // url = GetParameter(CommonUtils.WsType.CamSvRemove);
- // CamServiceAddReq svRemoveReq = new CamServiceAddReq();
- // svRemoveReq.type = "1";
- // foreach (var oldSv in listSvRes.list)
- // {
- // svRemoveReq.id = oldSv.id;
- // SendPost(svRemoveReq, url);
- // }
- //}
- // add new services
- if (campAddUpdateObj.listCampSv != null)
- {
- url = GetParameter(CommonUtils.WsType.CamAddInsert);
- foreach (var campSv in campAddUpdateObj.listCampSv)
- {
- campSv.users = account;
- campSv.campaignId = campId;
- var resAdd = CommonRes.Parse(SendPost(campSv, url));
- if (resAdd.responseCode != "0")
- {
- errorContent += "<br />" + "Error add service " + campSv.note + ": " + resAdd.responseMessage;
- }
- }
- }
- // add balances
- if (campAddUpdateObj.balances != null)
- {
- url = GetParameter(CommonUtils.WsType.camBalanceInsert);
- foreach (var campCri in campAddUpdateObj.balances)
- {
- campCri.users = account;
- campCri.campaignId = campId;
- var resAdd = CommonRes.Parse(SendPost(campCri, url));
- if (resAdd.responseCode != "0")
- {
- errorContent += "<br />" + "Error add criteria " + campCri.note + ": " + resAdd.responseMessage;
- }
- }
- }
- // add expires
- if (campAddUpdateObj.expires != null)
- {
- url = GetParameter(CommonUtils.WsType.camExpireInsert);
- foreach (var campCri in campAddUpdateObj.expires)
- {
- campCri.users = account;
- campCri.campaignId = campId;
- var resAdd = CommonRes.Parse(SendPost(campCri, url));
- if (resAdd.responseCode != "0")
- {
- errorContent += "<br />" + "Error add criteria " + campCri.note + ": " + resAdd.responseMessage;
- }
- }
- }
- // add shortcode
- url = GetParameter(CommonUtils.WsType.camShortCodeInsert);
- CriteriaMapCamReq camShortCode = new CriteriaMapCamReq();
- camShortCode.users = account;
- camShortCode.campaignId = campId;
- camShortCode.shortCodeId = campAddUpdateObj.shortCodeId;
- var resAdd2 = CommonRes.Parse(SendPost(camShortCode, url));
- if (resAdd2.responseCode != "0")
- {
- errorContent += "<br />" + "Error add shortcode " + camShortCode.note + ": " + resAdd2.responseMessage;
- }
- // add list sub
- if (campAddUpdateObj.listSubs != null)
- {
- url = GetParameter(CommonUtils.WsType.camSubInsert);
- foreach (var campCri in campAddUpdateObj.listSubs)
- {
- campCri.users = account;
- campCri.campaignId = campId;
- var resAdd = CommonRes.Parse(SendPost(campCri, url));
- if (resAdd.responseCode != "0")
- {
- errorContent += "<br />" + "Error add sub " + campCri.note + ": " + resAdd.responseMessage;
- }
- }
- }
- // check result
- if (errorContent != "")
- {
- return Json(new
- {
- error = res.responseCode,
- warning = "1",
- campId = campId,
- content = "Create campaign success with warning:" + errorContent
- });
- }
- else
- {
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- }
- else
- {
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- }
- // ApiWebserviceManagement
- public IActionResult ApiWebserviceManagement()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public IActionResult GetApiServices()
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- var req = new ApiServiceReq
- {
- rowsOnPage = "1000000",
- seqPage = "1",
- order = "desc"
- };
- string url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
- ApiServiceRes res = ApiServiceRes.Parse(SendPost(req, url));
- if (res == null || res.list == null)
- {
- return Json(new
- {
- error = "1",
- content = "No data found"
- });
- }
- return Json(new
- {
- error = 0,
- data = res.list
- });
- }
- public IActionResult ApiServiceSearch(ApiServiceReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
- ApiServiceRes res = ApiServiceRes.Parse(SendPost(req, url));
- HttpContext.Session.SetComplexData("apiServiceData", res.list);
- return PartialView("../Partial/_ApiWebserviceManagement", res.list);
- }
- [HttpPost]
- public IActionResult ApiServiceExport(ApiServiceReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- // Ensure same paging/order behavior as search
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- string url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
- ApiServiceRes res = ApiServiceRes.Parse(SendPost(req, url));
- var list = res.list ?? new List<ApiService>();
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "api_services.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("API Services");
- worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 10; worksheet.Cell(1, i++).Value = "ID";
- worksheet.Column(i).Width = 30; worksheet.Cell(1, i++).Value = "ws_name";
- worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "ws_code";
- worksheet.Column(i).Width = 50; worksheet.Cell(1, i++).Value = "wsdl";
- worksheet.Column(i).Width = 40; worksheet.Cell(1, i++).Value = "msg_template";
- worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "error_tag";
- worksheet.Column(i).Width = 20; worksheet.Cell(1, i++).Value = "success_code";
- worksheet.Column(i).Width = 12; worksheet.Cell(1, i++).Value = "Status";
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- if (list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).Value = obj.ws_id;
- worksheet.Cell(index + 1, i++).Value = obj.ws_name;
- worksheet.Cell(index + 1, i++).Value = obj.ws_code;
- worksheet.Cell(index + 1, i++).Value = obj.wsdl;
- worksheet.Cell(index + 1, i++).Value = obj.msg_template;
- worksheet.Cell(index + 1, i++).Value = obj.error_tag;
- worksheet.Cell(index + 1, i++).Value = obj.success_code;
- worksheet.Cell(index + 1, i++).Value = obj.isActive == "1" ? "Active" : "Inactive";
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception)
- {
- return null;
- }
- }
- [HttpPost]
- public JsonResult ApiServiceLoadInfo(ApiServiceReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = GetParameter(CommonUtils.WsType.ApiServiceLoad);
- var res = ApiServiceRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage,
- data = res.list[0]
- });
- }
- [HttpPost]
- public JsonResult ApiServiceAddUpdate(ApiServiceUpdateReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = "";
- if (request.id != null)
- {
- url = GetParameter(CommonUtils.WsType.ApiServiceUpdate);
- }
- else
- {
- // add
- url = GetParameter(CommonUtils.WsType.ApiServiceInsert);
- }
- request.users = account;
- var res = ApiServiceUpdateRes.Parse(SendPost(request, url));
- // reload
- PreLoadService();
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- // SERVICE
- public IActionResult ServiceManagement()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- public IActionResult ServiceSearch(ServiceGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.SvGetList);
- ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
- HttpContext.Session.SetComplexData("listService", res.list);
- return PartialView("../Partial/_Services", res.list);
- }
- [HttpPost]
- public JsonResult ServiceLoadInfo(ServiceGetListReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = GetParameter(CommonUtils.WsType.SvGetList);
- var res = ServiceGetListRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage,
- data = res.list[0]
- });
- }
- [HttpPost]
- public JsonResult ServiceAddUpdate(ServiceUpdateReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = "";
- if (request.id != null)
- {
- url = GetParameter(CommonUtils.WsType.SvUpdate);
- }
- else
- {
- // add
- url = GetParameter(CommonUtils.WsType.SvInsert);
- }
- request.users = account;
- var res = ServiceUpdateRes.Parse(SendPost(request, url));
- // reload
- PreLoadService();
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- // SERVICE
- public IActionResult CampaignScheduler()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- public IActionResult SchedulerSearch(CalendarGetListReq req, string viewType = "calendar")
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- String url = GetParameter(CommonUtils.WsType.CalendarGetList);
- CalendarGetListRes res = CalendarGetListRes.Parse(SendPost(req, url));
- string viewName = viewType == "table" ? "../Partial/_CampaignSchedulerTable" : "../Partial/_CampaignSchedulerCalendar";
- return PartialView(viewName, res.list);
- }
- [HttpPost]
- public IActionResult SchedulerExport(CalendarGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- String url = GetParameter(CommonUtils.WsType.CalendarGetList);
- CalendarGetListRes res = CalendarGetListRes.Parse(SendPost(req, url));
- var list = res.list;
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "calendar.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Scheduler");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Date";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "ID";
- worksheet.Column(i).Width = 30;
- worksheet.Cell(1, i++).Value = "Campaign Name";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Campaign Type";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Start Date";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "End Date";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Services";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Status";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- int rownum = 1;
- for (int index = 1; index <= list.Count; index++)
- {
-
- var calendar = list[index - 1];
- if (calendar.list == null || calendar.list.Count == 0)
- {
- i = 1;
- rownum++;
- worksheet.Cell(rownum, i++).Value = rownum-1;
- worksheet.Cell(rownum, i++).SetValue(calendar.date);
- }
- else
- {
- for (int j = 0; j < calendar.list.Count; j++)
- {
- i = 1;
- rownum++;
- var obj = calendar.list[j];
- worksheet.Cell(rownum, i++).Value = rownum-1;
- if (j == 0)
- {
- // merge cell
- worksheet.Range($"B{rownum}:B{rownum + calendar.list.Count - 1}").Merge();
- worksheet.Cell(rownum, i).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
- worksheet.Cell(rownum, i++).SetValue(calendar.date);
- } else
- {
- i++;
- }
- worksheet.Cell(rownum, i++).Value = obj.id;
- worksheet.Cell(rownum, i++).Value = obj.name;
- worksheet.Cell(rownum, i++).Value = obj.isDefault == "1" ? "Default" : "Normal";
- worksheet.Cell(rownum, i++).SetValue(obj.fromDate);
- worksheet.Cell(rownum, i++).SetValue(obj.toDate);
- string services = "";
- if (obj.listServiceMapCam != null)
- {
- foreach (var sv in obj.listServiceMapCam)
- {
- services += @sv.serviceObj.name + "; ";
- }
- if (services.Length > 2)
- {
- services = services.Substring(0, services.Length - 2);
- }
- }
- worksheet.Cell(rownum, i++).Value = services;
- worksheet.Cell(rownum, i++).Value = CommonUtils.StatusToStr(obj.status);
- }
- }
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- // COMMON
- [HttpPost]
- public JsonResult ChangeStatus(ChangeStatusReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- request.users = account;
- // send change status
- string url = GetParameter(CommonUtils.WsType.changeStatus);
- var res = CommonRes.Parse(SendPost(request, url));
- // reload
- if (request.type == CommonUtils.ActionType.Service)
- {
- PreLoadService();
- }
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- [HttpPost]
- public IActionResult ServiceExport(ServiceGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- try
- {
- // Initialize req if null
- if (req == null)
- {
- req = new ServiceGetListReq();
- }
- // Set pagination to get all records, same as ServiceSearch
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.SvGetList);
- ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
- var list = res.list ?? new List<Service>();
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "services.xlsx";
-
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Services");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Name";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Short code";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Command";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Description";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Created date";
- worksheet.Column(i).Width = 50;
- worksheet.Cell(1, i++).Value = "Message USSD return success";
- worksheet.Column(i).Width = 50;
- worksheet.Cell(1, i++).Value = "Message USSD return failed";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).Value = obj.name ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.shortCode ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.command ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.description ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.dateCreated ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.msgRegisterSuccess ?? "";
- worksheet.Cell(index + 1, i++).Value = obj.msgRegisterFlase ?? "";
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- log.Error("Error in ServiceExport: " + ex.Message, ex);
- return null;
- }
- }
- [HttpPost]
- public IActionResult CampaignService(CampaignServiceListReq req)
- {
- if (!CheckAuthToken())
- {
- return PartialView("../Partial/_CampaignService", null);
- }
- if (req.rowsOnPage == null)
- {
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "asc";
- String url = GetParameter(CommonUtils.WsType.CamSvGetList);
- CampaignServiceListRes res = CampaignServiceListRes.Parse(SendPost(req, url));
- return PartialView("../Partial/_CampaignService", res.list);
- }
- else
- {
- ViewBag.nextIndex = req.rowsOnPage;
- return PartialView("../Partial/_CampaignService", null);
- }
- }
- [HttpPost]
- public IActionResult SvGroup(ServiceGroupReq req)
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- string url = GetParameter(CommonUtils.WsType.SvGroupGetList);
- ServiceGroupRes res = ServiceGroupRes.Parse(SendPost(req, url));
- HttpContext.Session.SetComplexData("serviceGroupData", res.list);
- return Json(new { success = true });
- }
- [HttpPost]
- public IActionResult SvGroupLoad(ServiceGroupReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string url = GetParameter(CommonUtils.WsType.SvGroupGetList);
- ServiceGroupRes res = ServiceGroupRes.Parse(SendPost(req, url));
- if (res == null || res.list == null)
- {
- return Json(new
- {
- error = "1",
- content = "No data found"
- });
- }
- return Json(new
- {
- error = 0,
- data = res.list
- });
- }
- // ReportCampaign
- public IActionResult ReportCampaign()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public IActionResult ReportCampaignSearch(RpByCampaignReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string url = GetParameter(CommonUtils.WsType.ReportByCampaign);
- string result = SendPost(req, url);
- RpByCampaignRes res = RpByCampaignRes.Parse(result);
- return PartialView("../Partial/_ReportCampaign", res.list);
- }
- [HttpPost]
- public IActionResult ReportCampaignExport(RpByCampaignReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- string url = GetParameter(CommonUtils.WsType.ReportByCampaign);
- string result = SendPost(req, url);
- RpByCampaignRes res = RpByCampaignRes.Parse(result);
- List<RpByCampaign> list = res.list;
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "report_campaign.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Report Campaign");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "ID";
- worksheet.Column(i).Width = 30;
- worksheet.Cell(1, i++).Value = "Name";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Priority";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Campaign Type";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Service Type";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Service Name";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Total Send 1";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Total press 1 of send 1";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Total Send 2";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Total press 1 of send 2";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Total Success";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Total Failed";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).Value = obj.campaignId;
- worksheet.Cell(index + 1, i++).Value = obj.campaignName;
- worksheet.Cell(index + 1, i++).Value = obj.priority;
- worksheet.Cell(index + 1, i++).Value = obj.campaignType == "1" ? "Default" : "Normal";
- worksheet.Cell(index + 1, i++).Value = (int.Parse(obj.serviceType) - 1) + "-Verification";
- worksheet.Cell(index + 1, i++).Value = obj.serviceName;
- worksheet.Cell(index + 1, i++).Value = obj.totalView1;
- worksheet.Cell(index + 1, i++).Value = obj.activation1;
- worksheet.Cell(index + 1, i++).Value = obj.totalView2;
- worksheet.Cell(index + 1, i++).Value = obj.activation2;
- worksheet.Cell(index + 1, i++).Value = obj.success;
- worksheet.Cell(index + 1, i++).Value = obj.fail;
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- private String formatStatus(String status)
- {
- if (status == "0")
- {
- return "Processing";
- }
- else if (status == "1")
- {
- return "Success";
- }
- else if (status == "2")
- {
- return "Pending";
- }
- else if (status == "3")
- {
- return "Revert";
- }
- return status;
- }
- private void PreLoadService()
- {
- try
- {
- ServiceGetListReq req = new ServiceGetListReq();
- req.isActive = "1";
- req.rowsOnPage = "20000";
- req.seqPage = "1";
- String url = GetParameter(CommonUtils.WsType.SvGetList);
- ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
- HttpContext.Session.SetComplexData("listService", res.list);
- }
- catch (Exception ex)
- {
- log.Error("Error load service: ", ex);
- }
- }
- // List import
- public IActionResult ListMsisdn()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- CampaignGetListReq req = new CampaignGetListReq();
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
- HttpContext.Session.SetComplexData("listCampaign", res.list);
- return View();
- }
- public IActionResult ListMsisdnSearch(ListMsisdnGetReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- //string account = HttpContext.Session.GetString("account");
- //req.users = account;
- req.msisdn = BaseController.ValidateMsisdn(req.msisdn);
- string url = GetParameter(CommonUtils.WsType.MsisdnSearch);
- string result = SendPost(req, url);
- ListMsisdnGetRes res = ListMsisdnGetRes.Parse(result);
- return PartialView("../Partial/_ListMsisdn", res);
- //return Json(new
- //{
- // error = res.responseCode,
- // content = res.responseMessage,
- // data = res.list
- //});
- }
- [HttpPost]
- public IActionResult ListMsisdnExport(ListMsisdnGetReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- string url = GetParameter(CommonUtils.WsType.MsisdnSearch);
- string result = SendPost(req, url);
- ListMsisdnGetRes res = ListMsisdnGetRes.Parse(result);
- List<MsisdnList> list = res.list;
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "player_list.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Player List");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Phone number";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Type";
- worksheet.Column(i).Width = 25;
- worksheet.Cell(1, i++).Value = "Campaign";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Import date";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).Value = obj.msisdn;
- worksheet.Cell(index + 1, i++).Value = obj.type == "2" ? "Blacklist" : "Whitelist";
- worksheet.Cell(index + 1, i++).Value = obj.campaignId == "-1" ? "All" : (obj.campaignId + " - " + obj.campaignName);
- worksheet.Cell(index + 1, i++).Value = obj.sysdate;
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- [HttpPost]
- public JsonResult ListMsisdnRemove(ImportMsisdn request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = GetParameter(CommonUtils.WsType.MsisdnAddUpdate);
- request.users = account;
- var res = ServiceUpdateRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- [HttpPost]
- public IActionResult ListMsisdnImport(ImportMsisdn req, IFormFile file_upload)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- //ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- try
- {
- if (file_upload != null && (file_upload.FileName.EndsWith(".txt") || file_upload.FileName.EndsWith(".csv")))
- {
- String fileUpload = UploadedFile(file_upload, "import_msisdn");
- if (fileUpload != "")
- {
- // import data
- return importMsisdn(req, fileUpload);
- }
- else
- {
- return Json(new
- {
- error_code = UtilsController.Constant.FAILURE,
- error_content = "Invalid file",
- });
- }
- }
- else
- {
- return Json(new
- {
- error_code = UtilsController.Constant.FAILURE,
- error_content = "Import file invalid",
- });
- }
- }
- catch (Exception ex)
- {
- return Json(new
- {
- error_code = UtilsController.Constant.FAILURE,
- error_content = "System failed!",
- });
- }
- }
- private JsonResult importMsisdn(ImportMsisdn req, String importFile)
- {
- using (StreamReader f = new StreamReader(importFile))
- {
- string account = HttpContext.Session.GetString("account");
- req.users = account;
- //
- List<Datum> listMsisdn = new List<Datum>();
- int ct = 0;
- string ln;
- while ((ln = f.ReadLine()) != null)
- {
- ct++;
- listMsisdn.Add(new Datum(ValidateMsisdn(ln.Trim()), "1"));
- }
- f.Close();
- req.data = listMsisdn;
- // send request
- string url = GetParameter(CommonUtils.WsType.MsisdnAddUpdate);
- string result = SendPost(req, url);
- CommonRes res = CommonRes.Parse(result);
- //
- listMsisdn.Clear();
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- }
- // PARAM
- public IActionResult ParamManagement()
- {
- return View();
- }
- public IActionResult ParamSearch(ParamGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- String url = GetParameter(CommonUtils.WsType.ParamGetList);
- ParamGetListRes res = ParamGetListRes.Parse(SendPost(req, url));
- return PartialView("../Partial/_Params", res.list);
- }
- [HttpPost]
- public JsonResult ParamLoadInfo(ParamGetListReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = GetParameter(CommonUtils.WsType.ParamGetList);
- var res = ParamGetListRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage,
- data = res.list[0]
- });
- }
- [HttpPost]
- public JsonResult ParamAddUpdate(String id, String value, String note)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // get param by id
- string url = GetParameter(CommonUtils.WsType.ParamGetList);
- ParamGetListReq req = new ParamGetListReq();
- req.id = id;
- ParamGetListRes cpRes = ParamGetListRes.Parse(SendPost(req, url));
- var cmp = cpRes.list[0];
- // update status
- ParamUpdateReq updateReq = new ParamUpdateReq(cmp);
- updateReq.values = value;
- updateReq.note = note;
- updateReq.users = account;
- string result = SendPost(updateReq, GetParameter(CommonUtils.WsType.ParamUpdate));
- CommonRes res = CommonRes.Parse(result);
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- public IActionResult Reload()
- {
- return View();
- }
- [HttpPost]
- public JsonResult ReloadConfig(ReloadReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- request.users = account;
- // check update or add
- string url = GetParameter(CommonUtils.WsType.ParamReload);
- var res = ParamUpdateRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- // SERVICE UNDER
- public IActionResult ServiceUnder()
- {
- // init
- try
- {
- var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
- if (listService == null)
- {
- PreLoadService();
- }
- }
- catch (Exception ex)
- {
- PreLoadService();
- }
- return View();
- }
- public IActionResult ServiceUnderSearch(ServiceUnderGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- String url = GetParameter(CommonUtils.WsType.SvGetList);
- ServiceGetListRes res = ServiceGetListRes.Parse(SendPost(req, url));
- return PartialView("../Partial/_ServicesUnder", res.list);
- }
- [HttpPost]
- public JsonResult ServiceUnderLoadInfo(ServiceUnderGetListReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = GetParameter(CommonUtils.WsType.SvUnderGetList);
- var res = ServiceUnderGetListRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage,
- data = res.list[0]
- });
- }
- [HttpPost]
- public JsonResult ServiceUnderAddUpdate(ServiceUnderUpdateReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = "";
- if (request.id != null)
- {
- url = GetParameter(CommonUtils.WsType.SvUnderUpdate);
- }
- else
- {
- // add
- url = GetParameter(CommonUtils.WsType.SvUnderInsert);
- }
- request.users = account;
- var res = ServiceUnderUpdateRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- [HttpPost]
- public JsonResult ServiceUnderDelete(ServiceUnderUpdateReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- // check update or add
- string url = GetParameter(CommonUtils.WsType.SvUnderUpdate);
- request.users = account;
- request.type = "1";// delete
- var res = ServiceUnderUpdateRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- [HttpPost]
- public IActionResult ServiceUnderExport(ServiceUnderGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- string url = GetParameter(CommonUtils.WsType.SvGetList);
- string result = SendPost(req, url);
- ServiceUnderGetListRes res = ServiceUnderGetListRes.Parse(result);
- var list = res.list;
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "service_ngam.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- //<th scope="col" class="text-center" style="vertical-align:middle">ID</th>
- //<th scope = "col" class="text-center" style="vertical-align:middle">Service Name</th>
- //<th scope = "col" class="text-center" style="vertical-align:middle">From Date</th>
- //<th scope = "col" class="text-center" style="vertical-align:middle">To Date</th>
- //<th scope = "col" class="text-center" style="vertical-align:middle">Percent</th>
- //<th scope = "col" class="text-center" style="vertical-align:middle">Message</th>
- //<th scope = "col" class="text-center" style="vertical-align:middle">Type</th>
- //<th scope = "col" class="text-center" style="vertical-align:middle">Action</th>
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Service Under");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Name";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "From Date";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "To Date";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Percent";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Content Type";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Message";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).Value = obj.name;
- worksheet.Cell(index + 1, i++).Value = obj.fromDate;
- worksheet.Cell(index + 1, i++).Value = obj.toDate;
- worksheet.Cell(index + 1, i++).Value = obj.percent;
- worksheet.Cell(index + 1, i++).Value = obj.addType == "1" ? "Text" : "Register";
- worksheet.Cell(index + 1, i++).Value = obj.message;
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- // USER MANAGEMENT
- public IActionResult UserManagement()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public IActionResult UserSearch(UserWebCmsGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- if (req.rowsOnPage == null)
- {
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- }
- String url = GetParameter(CommonUtils.WsType.UserWebCmsGetList);
- UserWebCmsGetListRes res = UserWebCmsGetListRes.Parse(SendPost(req, url));
- return PartialView("../Partial/_Users", res.list);
- }
- [HttpPost]
- public JsonResult UserLoadInfo(UserWebCmsGetListReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- String url = GetParameter(CommonUtils.WsType.UserWebCmsGetList);
- var res = UserWebCmsGetListRes.Parse(SendPost(request, url));
- if (res.list != null && res.list.Count > 0)
- {
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage,
- data = res.list[0]
- });
- }
- return Json(new
- {
- error = "-1",
- content = "Not found"
- });
- }
- [HttpPost]
- public JsonResult UserAddUpdate(UserWebCmsUpdateReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- string url = "";
- if (request.id != null && request.id != "")
- {
- url = GetParameter(CommonUtils.WsType.UserWebCmsUpdate);
- }
- else
- {
- url = GetParameter(CommonUtils.WsType.UserWebCmsInsert);
- }
- request.users = account;
-
- var res = UserWebCmsUpdateRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- // REPORT COUNT DAILY
- public IActionResult ReportCountDaily()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
-
- // Load campaign list if not in session
- try
- {
- var listCampaign = HttpContext.Session.GetComplexData<List<Campaign>>("listCampaign");
- if (listCampaign == null)
- {
- CampaignGetListReq req = new CampaignGetListReq();
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
- HttpContext.Session.SetComplexData("listCampaign", res.list);
- }
- }
- catch (Exception ex)
- {
- log.Error("Error load campaign: ", ex);
- }
-
- return View();
- }
- [HttpPost]
- public IActionResult ReportCountDailySearch(ReportCountDailyReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.ReportCountDailyGetList);
- ReportCountDailyRes res = ReportCountDailyRes.Parse(SendPost(req, url));
- return PartialView("../Partial/_ReportCountDaily", res.list);
- }
- [HttpPost]
- public IActionResult ReportCountDailyExport(ReportCountDailyReq req)
- {
- if (!CheckAuthToken())
- {
- return null;
- }
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.ReportCountDailyGetList);
- ReportCountDailyRes res = ReportCountDailyRes.Parse(SendPost(req, url));
- var list = res.list;
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "report_count_daily.xlsx";
- try
- {
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Report Count Daily");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "#";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Report Date";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Campaign ID";
- worksheet.Column(i).Width = 30;
- worksheet.Cell(1, i++).Value = "Campaign Name";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Priority";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Campaign Type";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Service Type";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Partner";
- worksheet.Column(i).Width = 30;
- worksheet.Cell(1, i++).Value = "Service Name";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "USSD out success";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var obj = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).SetValue(obj.reportDate);
- worksheet.Cell(index + 1, i++).Value = obj.campaignId;
- worksheet.Cell(index + 1, i++).Value = obj.campaignName;
- worksheet.Cell(index + 1, i++).Value = obj.priority;
- worksheet.Cell(index + 1, i++).Value = obj.isDefault == "0" ? "Normal" : obj.isDefault == "1" ? "Default" : obj.isDefault;
- worksheet.Cell(index + 1, i++).Value = obj.addType == "1" ? "Text" : obj.addType == "2" ? "1-Verification" : obj.addType == "3" ? "2-Verification" : obj.addType;
- worksheet.Cell(index + 1, i++).Value = obj.isMyService == "0" ? "Metfone" : obj.isMyService == "1" ? "Khmernet" : obj.isMyService;
- worksheet.Cell(index + 1, i++).Value = obj.serviceName;
- worksheet.Cell(index + 1, i++).Value = obj.countSend1;
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- log.Error("Error exporting report count daily: ", ex);
- return StatusCode(StatusCodes.Status500InternalServerError, "Unable to export report count daily.");
- }
- }
- // FUNCTION MANAGEMENT
- public IActionResult FunctionManagement()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- [HttpPost]
- public IActionResult FunctionSearch(FunctionWebCmsGetListReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- if (req.rowsOnPage == null)
- {
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- }
- String url = GetParameter(CommonUtils.WsType.FunctionWebCmsGetList);
- FunctionWebCmsGetListRes res = FunctionWebCmsGetListRes.Parse(SendPost(req, url));
- return PartialView("../Partial/_Functions", res.list);
- }
- [HttpPost]
- public JsonResult FunctionLoadInfo(FunctionWebCmsGetListReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- String url = GetParameter(CommonUtils.WsType.FunctionWebCmsGetList);
- var res = FunctionWebCmsGetListRes.Parse(SendPost(request, url));
- if (res.list != null && res.list.Count > 0)
- {
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage,
- data = res.list[0]
- });
- }
- return Json(new
- {
- error = "-1",
- content = "Not found"
- });
- }
- [HttpPost]
- public JsonResult FunctionAddUpdate(FunctionWebCmsUpdateReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- string url = "";
- if (request.id != null && request.id != "")
- {
- url = GetParameter(CommonUtils.WsType.FunctionWebCmsUpdate);
- }
- else
- {
- url = GetParameter(CommonUtils.WsType.FunctionWebCmsInsert);
- }
- request.users = account;
-
- var res = FunctionWebCmsUpdateRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- [HttpPost]
- public JsonResult FunctionDelete(FunctionWebCmsUpdateReq request)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- string url = GetParameter(CommonUtils.WsType.FunctionWebCmsDelete);
- request.users = account;
-
- var res = FunctionWebCmsUpdateRes.Parse(SendPost(request, url));
- return Json(new
- {
- error = res.responseCode,
- content = res.responseMessage
- });
- }
- [HttpPost]
- public IActionResult ReportErrorDailyDetail(ReportErrorDailyReq req)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- if (string.IsNullOrEmpty(account))
- {
- account = "-1";
- }
- req.users = account;
- String url = GetParameter(CommonUtils.WsType.ReportErrorDailyGetList);
- if (string.IsNullOrEmpty(url))
- {
- return Json(new
- {
- error = "-1",
- content = "API URL not configured"
- });
- }
- try
- {
- ReportErrorDailyRes res = ReportErrorDailyRes.Parse(SendPost(req, url));
- if (res == null || res.responseCode != "0")
- {
- return Json(new
- {
- error = res?.responseCode ?? "-1",
- content = res?.responseMessage ?? "Error occurred"
- });
- }
- return PartialView("../Partial/_ReportErrorDaily", res.list ?? new List<ReportErrorDaily>());
- }
- catch (Exception ex)
- {
- log.Error("Error in ReportErrorDailyDetail: ", ex);
- return Json(new
- {
- error = "-1",
- content = "Error occurred: " + ex.Message
- });
- }
- }
- public IActionResult DashboardReport()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
-
- // Load campaign list if not in session
- try
- {
- var listCampaign = HttpContext.Session.GetComplexData<List<Campaign>>("listCampaign");
- if (listCampaign == null)
- {
- CampaignGetListReq req = new CampaignGetListReq();
- req.rowsOnPage = "1000000";
- req.seqPage = "1";
- req.order = "desc";
- String url = GetParameter(CommonUtils.WsType.CamGetList);
- CampaignGetListRes res = CampaignGetListRes.Parse(SendPost(req, url));
- HttpContext.Session.SetComplexData("listCampaign", res.list);
- }
-
- var listService = HttpContext.Session.GetComplexData<List<Service>>("listService");
- if (listService == null)
- {
- PreLoadService();
- }
- }
- catch (Exception ex)
- {
- log.Error("Error load campaign/service: ", ex);
- }
-
- return View();
- }
- [HttpPost]
- public JsonResult DashboardReportGetData(string campaignId, string serviceId, string hours, string quickJump)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- if (string.IsNullOrEmpty(account))
- {
- account = "-1";
- }
- try
- {
- HourlyImpressionsGetListReq req = new HourlyImpressionsGetListReq();
- req.users = account;
- req.campaignId = campaignId ?? "-1";
- req.serviceId = serviceId ?? "-1";
- req.hours = hours ?? "72h";
- req.quickJump = quickJump ?? "-1";
- req.language = "vi";
- String url = GetParameter(CommonUtils.WsType.HourlyImpressionsGetList);
- if (string.IsNullOrEmpty(url))
- {
- return Json(new
- {
- error = "-1",
- content = "API URL not configured"
- });
- }
- HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(req, url));
-
- if (res == null || res.responseCode != "0")
- {
- return Json(new
- {
- error = res?.responseCode ?? "-1",
- content = res?.responseMessage ?? "Error occurred"
- });
- }
- return Json(new
- {
- error = "0",
- data = JsonConvert.SerializeObject(res)
- });
- }
- catch (Exception ex)
- {
- log.Error("Error in DashboardReportGetData: ", ex);
- return Json(new
- {
- error = "-1",
- content = "Error occurred: " + ex.Message
- });
- }
- }
- [HttpPost]
- public JsonResult DashboardReportGetDailyData(string campaignId, string fromDate, string toDate)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- if (string.IsNullOrEmpty(account))
- {
- account = "-1";
- }
- try
- {
- HourlyImpressionsGetListReq req = new HourlyImpressionsGetListReq();
- req.users = account;
- req.campaignId = campaignId ?? "-1";
- req.hours = "-1"; // Not used for daily
- req.quickJump = "-1"; // Not used for daily
- req.language = "vi";
- String url = GetParameter(CommonUtils.WsType.DailyImpressionsGetList);
- if (string.IsNullOrEmpty(url))
- {
- return Json(new
- {
- error = "-1",
- content = "API URL not configured"
- });
- }
- // Create custom request object for daily (with fromDate and toDate)
- DailyImpressionsGetListReq dailyReq = new DailyImpressionsGetListReq();
- dailyReq.users = account;
- dailyReq.campaignId = campaignId ?? "-1";
- dailyReq.fromDate = fromDate ?? "-1";
- dailyReq.toDate = toDate ?? "-1";
- dailyReq.language = "vi";
- dailyReq.channel = "WEB";
- dailyReq.token = HttpContext.Session.GetString("token") ?? "";
- HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(dailyReq, url));
-
- if (res == null || res.responseCode != "0")
- {
- return Json(new
- {
- error = res?.responseCode ?? "-1",
- content = res?.responseMessage ?? "Error occurred"
- });
- }
- return Json(new
- {
- error = "0",
- data = JsonConvert.SerializeObject(res)
- });
- }
- catch (Exception ex)
- {
- log.Error("Error in DashboardReportGetDailyData: ", ex);
- return Json(new
- {
- error = "-1",
- content = "Error occurred: " + ex.Message
- });
- }
- }
- [HttpPost]
- public JsonResult DashboardReportGetDailyUniqueData(string campaignId, string serviceId, string fromDate, string toDate)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- if (string.IsNullOrEmpty(account))
- {
- account = "-1";
- }
- try
- {
- DailyImpressionsGetListReq req = new DailyImpressionsGetListReq();
- req.users = account;
- req.campaignId = campaignId ?? "-1";
- req.serviceId = serviceId ?? "-1";
- req.fromDate = fromDate ?? "-1";
- req.toDate = toDate ?? "-1";
- req.language = "vi";
- req.channel = "WEB";
- req.token = HttpContext.Session.GetString("token") ?? "";
- String url = GetParameter(CommonUtils.WsType.DailyUniqueImpressionsGetList);
- if (string.IsNullOrEmpty(url))
- {
- return Json(new
- {
- error = "-1",
- content = "API URL not configured"
- });
- }
- HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(req, url));
- if (res == null || res.responseCode != "0")
- {
- return Json(new
- {
- error = res?.responseCode ?? "-1",
- content = res?.responseMessage ?? "Error occurred"
- });
- }
- return Json(new
- {
- error = "0",
- data = JsonConvert.SerializeObject(res)
- });
- }
- catch (Exception ex)
- {
- log.Error("Error in DashboardReportGetDailyUniqueData: ", ex);
- return Json(new
- {
- error = "-1",
- content = "Error occurred: " + ex.Message
- });
- }
- }
- [HttpPost]
- public JsonResult DashboardReportGetDailyEngagedData(string campaignId, string fromDate, string toDate)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Login first"
- });
- }
- string account = HttpContext.Session.GetString("account");
- if (string.IsNullOrEmpty(account))
- {
- account = "-1";
- }
- try
- {
- DailyImpressionsGetListReq req = new DailyImpressionsGetListReq();
- req.users = account;
- req.campaignId = campaignId ?? "-1";
- req.serviceId = "-1";
- req.fromDate = fromDate ?? "-1";
- req.toDate = toDate ?? "-1";
- req.language = "vi";
- req.channel = "WEB";
- req.token = HttpContext.Session.GetString("token") ?? "";
- String url = GetParameter(CommonUtils.WsType.DailyEngagedGetList);
- if (string.IsNullOrEmpty(url))
- {
- return Json(new
- {
- error = "-1",
- content = "API URL not configured"
- });
- }
- HourlyImpressionsGetListRes res = HourlyImpressionsGetListRes.Parse(SendPost(req, url));
- if (res == null || res.responseCode != "0")
- {
- return Json(new
- {
- error = res?.responseCode ?? "-1",
- content = res?.responseMessage ?? "Error occurred"
- });
- }
- return Json(new
- {
- error = "0",
- data = JsonConvert.SerializeObject(res)
- });
- }
- catch (Exception ex)
- {
- log.Error("Error in DashboardReportGetDailyEngagedData: ", ex);
- return Json(new
- {
- error = "-1",
- content = "Error occurred: " + ex.Message
- });
- }
- }
- }
- }
|