| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913 |
- using System;
- using System.Collections.Generic;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using SuperCms.Extensions;
- using SuperAdmin.Source;
- using Microsoft.AspNetCore.Http;
- using System.IO;
- using ReportWeb.Models;
- using ReportWeb;
- using System.Data;
- using Newtonsoft.Json;
- using ReportWeb.Source;
- using OfficeOpenXml;
- using ClosedXML.Excel;
- namespace SuperAdmin.Controllers
- {
- public class AdminController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- DbConnector db = new DbConnector();
- List<Services> listService;
- String sdf = "dd/MM/yyyy HH:mm";
- String df = "dd/MM/yyyy";
- public static int counter = 0;
- public static bool counterStart = false;
- public AdminController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
- {
- // init
- subDomain = _configuration["subDomain"];
- }
- public ActionResult Index(String nameSearch)
- {
- // get list service
- if (HttpContext.Session.GetComplexData<List<Services>>("listService") == null)
- {
- listService = db.LoadListServices();
- HttpContext.Session.SetComplexData("listService", listService);
- }
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role == Common.UserRole.Agent)
- {
- return View("SearchHistory");
- }
- ReportWeb.Models.DashboardModel model = new ReportWeb.Models.DashboardModel();
- model.listDailyReport = db.GetCommonReport(DateTime.Now.AddDays(-11), DateTime.Now.AddDays(-1));
- model.listDailyReportTotal = db.GetTotalReport(DateTime.Now.AddDays(-11), DateTime.Now.AddDays(-1));
- model.listHourlyReportTotal = db.GetTotalHourlyReport(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
- //model.todayReport = db.GetCommonReport(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
- //model.yesterdayReport = db.GetCommonReport(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-2));
- model.todayReport = new List<DailyReport>();
- model.yesterdayReport = new List<DailyReport>();
- String today = DateTime.Now.AddDays(-1).ToString(df);
- String yesterday = DateTime.Now.AddDays(-2).ToString(df);
- if (model.listDailyReport != null)
- {
- foreach (DailyReport dailyReport in model.listDailyReport)
- {
- if (dailyReport.report_date == today)
- {
- model.todayReport.Add(dailyReport);
- }
- if (dailyReport.report_date == yesterday)
- {
- model.yesterdayReport.Add(dailyReport);
- }
- model.avg7NewSubs += dailyReport.count_reg;
- model.avg7TotalSubs += dailyReport.count_active;
- model.avg7TotalRevenue += dailyReport.revenue;
- }
- }
- model.avg7NewSubs = model.avg7NewSubs / 10;
- model.avg7TotalSubs = model.avg7TotalSubs / 10;
- model.avg7TotalRevenue = model.avg7TotalRevenue / 10;
- // total
- foreach (DailyReport dailyReport in model.todayReport)
- {
- model.totalSubs += dailyReport.count_active;
- model.newSubs += dailyReport.count_reg;
- model.totalRevenue += dailyReport.revenue;
- }
- model.totalSubs = model.totalSubs;
- model.newSubs = model.newSubs;
- model.totalRevenue = model.totalRevenue;
- return View(model);
- }
- public ActionResult SearchHistory()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- else
- {
- return View();
- }
- }
- [HttpPost]
- public JsonResult SearchHistoryAction(String msisdn, String service_id, 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"
- });
- }
- msisdn = validateMsisdn(msisdn);
- if (msisdn == null || msisdn == "")
- {
- return Json(new
- {
- error = "1",
- content = "Enter msisdn"
- });
- }
- Services sv = GetServiceById(int.Parse(service_id));
- if (sv == null)
- {
- return Json(new
- {
- error = "2",
- content = "Not found service"
- });
- }
- DateTime startTime = DateTime.ParseExact(fromDate, df, null);
- DateTime endTime = DateTime.ParseExact(toDate, df, null);
- sv = db.GetServiceRpBySvCode(sv.sv_code);
- List<RegInfo> listRegInfo = db.GetRegisterInfo(sv, msisdn, startTime, endTime);
- List<ChargeLog> listChargeLog = db.GetChargeLog(sv, msisdn, startTime, endTime);
- return Json(new
- {
- error = "0",
- listRegInfo = listRegInfo,
- listChargeLog = listChargeLog
- });
- }
- // SPIN
- public ActionResult SearchSpin()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- else
- {
- return View();
- }
- }
- [HttpPost]
- public JsonResult SearchSpinAction(String msisdn, 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"
- });
- }
- msisdn = validateMsisdn(msisdn);
- if (msisdn == null || msisdn == "")
- {
- return Json(new
- {
- error = "1",
- content = "Enter msisdn"
- });
- }
- DateTime startTime = DateTime.ParseExact(fromDate, df, null);
- DateTime endTime = DateTime.ParseExact(toDate, df, null);
- List<SpinLog> listSpin = db.GetLuckySpin(msisdn, startTime, endTime);
- SearchModel model = new SearchModel();
- model.listSpin = listSpin;
- model.remainSpin = db.CountLuckySpin(msisdn);
- return Json(new
- {
- error = "0",
- model = model
- });
- }
- [HttpPost]
- public IActionResult HistorySpinExport(String msisdn, String fromDate, String toDate)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Not allow"
- });
- }
- return ExportSpin(msisdn, fromDate, toDate);
- }
- private FileContentResult ExportSpin(String msisdn, String fromDate, String toDate)
- {
- try
- {
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- msisdn = validateMsisdn(msisdn);
- DateTime startTime = DateTime.ParseExact(fromDate, df, null);
- DateTime endTime = DateTime.ParseExact(toDate, df, null);
- List<SpinLog> list = db.GetLuckySpin(msisdn, startTime, endTime);
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "report_spin.xlsx";
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Report Spin");
- 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 = 25;
- worksheet.Cell(1, i++).Value = "Receive Time";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Quantity";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Used";
- worksheet.Column(i).Width = 25;
- worksheet.Cell(1, i++).Value = "Expire Time";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Status";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Note";
- // 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 news = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).SetValue(news.msisdn);
- worksheet.Cell(index + 1, i++).SetValue(news.insert_time.Value.ToString("dd/MM/yyyy HH:mm:ss"));
- worksheet.Cell(index + 1, i++).SetValue(news.added);
- worksheet.Cell(index + 1, i++).SetValue(news.used);
- worksheet.Cell(index + 1, i++).SetValue(news.expire_time.Value.ToString("dd/MM/yyyy HH:mm:ss"));
- worksheet.Cell(index + 1, i++).SetValue(news.expire_time.Value > DateTime.Now ? "Valid" : "Expired");
- worksheet.Cell(index + 1, i++).SetValue(news.channel_add);
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- // REPORT
- public ActionResult Report(String serviceId)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- else
- {
- ViewBag.ServiceId = serviceId;
- return View();
- }
- }
- public ActionResult ReportHourly()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- else
- {
- return View();
- }
- }
- public ActionResult ReportRevenue()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- else
- {
- return View();
- }
- }
- public List<DailyReport> GetReportData(String fromDate, String toDate, String service_id)
- {
- DateTime startTime = DateTime.ParseExact(fromDate, df, null);
- DateTime endTime = DateTime.ParseExact(toDate, df, null);
- Services sv = GetServiceById(int.Parse(service_id));
- List<DailyReport> res = db.GetDailyReport(sv.sv_code, startTime, endTime);
- return res;
- }
- [HttpPost]
- public JsonResult GetReport(String fromDate, String toDate, String service_id)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || user.role <= 0)
- {
- ViewBag.username = "Welcome!";
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- Services sv = GetServiceById(int.Parse(service_id));
- if (sv == null)
- {
- return Json(new
- {
- error = "2",
- content = "Not found service"
- });
- }
- List<DailyReport> res = GetReportData(fromDate, toDate, service_id);
- return Json(new
- {
- error = "0",
- dailyReport = res
- });
- }
- [HttpPost]
- public IActionResult ReportExport(String fromDate, String toDate, String service_id)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || user.role <= 0)
- {
- ViewBag.username = "Welcome!";
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- Services sv = GetServiceById(int.Parse(service_id));
- if (sv == null)
- {
- return Json(new
- {
- error = "2",
- content = "Not found service"
- });
- }
- return ExportReport(fromDate, toDate, service_id);
- }
- private FileContentResult ExportReport(String fromDate, String toDate, String service_id)
- {
- try
- {
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- List<DailyReport> list = GetReportData(fromDate, toDate, service_id);
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "report_total.xlsx";
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Report Spin");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Report date";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Revenue";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Revenue Buy";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Paid money";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Count sub";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Register new";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Deactive";
- // 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 news = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).SetValue(news.report_date);
- worksheet.Cell(index + 1, i++).SetValue(news.revenue);
- worksheet.Cell(index + 1, i++).SetValue(news.revenue_buy);
- worksheet.Cell(index + 1, i++).SetValue(news.paid_money);
- worksheet.Cell(index + 1, i++).SetValue(news.count_active);
- worksheet.Cell(index + 1, i++).SetValue(news.count_reg);
- worksheet.Cell(index + 1, i++).SetValue(news.count_deactive);
- }
- }
- 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 GetReportHourly(String fromDate, String toDate, String service_id)
- {
- 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);
- Services sv = GetServiceById(int.Parse(service_id));
- if (sv == null)
- {
- return Json(new
- {
- error = "2",
- content = "Not found service"
- });
- }
- List<DailyReport> res = db.GetHourlyReport(sv.sv_code, startTime, endTime);
- return Json(new
- {
- error = "0",
- dailyReport = res
- });
- }
- [HttpPost]
- public JsonResult GetRevenueHourly(String fromDate, String toDate, String service_id)
- {
- 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);
- Services sv = GetServiceById(int.Parse(service_id));
- if (sv == null)
- {
- return Json(new
- {
- error = "2",
- content = "Not found service"
- });
- }
- DataTable dt = db.GetRevenueHourly(sv.sv_code, startTime, endTime);
- return Json(new
- {
- data = JsonConvert.SerializeObject(dt),
- error = "0"
- });
- }
- public ActionResult ServiceManagement()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- HttpContext.Session.Clear();
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- List<Services> listService = db.LoadListServices();
- return View(listService);
- }
- public ActionResult ServiceRpManagement()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- HttpContext.Session.Clear();
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- List<Services> listService = db.LoadListServicesReport();
- return View(listService);
- }
- public ActionResult ServiceAdvManagement()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- HttpContext.Session.Clear();
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- List<Services> listService = db.LoadListServicesAdv(-1);
- return View(listService);
- }
- [HttpPost]
- public JsonResult SearchService()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<Services> listService = db.LoadListServices();
- return Json(new
- {
- error = "0",
- content = "Success",
- listService = listService
- });
- }
- [HttpPost]
- public JsonResult SearchServiceRp()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<Services> listService = db.LoadListServicesReport();
- return Json(new
- {
- error = "0",
- content = "Success",
- listService = listService
- });
- }
- [HttpPost]
- public JsonResult SearchServiceAdv(string status)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- int st = status == null ? -1 : int.Parse(status);
- List<Services> listService = db.LoadListServicesAdv(st);
- return Json(new
- {
- error = "0",
- content = "Success",
- listService = listService
- });
- }
- [HttpPost]
- public JsonResult GetServiceRpBySvCode(String svCode)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- Services service = db.GetServiceRpBySvCode(svCode);
- return Json(new
- {
- error = "0",
- content = "Success",
- service = service
- });
- }
- [HttpPost]
- public JsonResult GetServiceAdvById(String advId)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- Services service = db.GetServiceAdvById(advId);
- return Json(new
- {
- error = "0",
- content = "Success",
- service = service
- });
- }
- [HttpPost]
- public JsonResult GetServiceById(String serviceId)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- Services service = db.GetServiceById(serviceId);
- return Json(new
- {
- error = "0",
- content = "Success",
- service = service
- });
- }
- [HttpPost]
- public ActionResult AddService()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String serviceName = Request.Form["serviceName"];
- String serviceCode = Request.Form["serviceCode"];
- // call ws
- db.InsertService(serviceCode, serviceName);
- // Returns message that successfully uploaded
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult AddServiceRp()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- //formData.append('dbName', $("#dbName").val());
- //formData.append('svCode', $("#serviceCode").val());
- //formData.append('connectionString', $("#connectionString").val());
- //formData.append('dbUserName', $("#dbUserName").val());
- //formData.append('dbPassword', $("#dbPassword").val());
- //formData.append('sqlReportDaily', $("#sqlReportDaily").val());
- //formData.append('sqlReportWeekly', $("#sqlReportWeekly").val());
- String svCode = Request.Form["svCode"];
- String dbName = Request.Form["dbName"];
- String connectionString = Request.Form["connectionString"];
- String dbUserName = Request.Form["dbUserName"];
- String dbPassword = Request.Form["dbPassword"];
- String sqlReportDaily = Request.Form["sqlReportDaily"];
- String sqlReportHourly = Request.Form["sqlReportHourly"];
- // call ws
- db.InsertSvReport(svCode, dbName, connectionString, dbUserName, dbPassword, sqlReportDaily, sqlReportHourly);
- // Returns message that successfully uploaded
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult AddServiceAdv()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- //formData.append('svCode', $("#serviceCode").val());
- //formData.append('advName', $("#advName").val());
- //formData.append('msgAdv', $("#msgAdv").val());
- //formData.append('channelAdv', $("#channelAdv").val());
- //formData.append('messageType', $("#messageType").val());
- //formData.append('fromMoney', $("#fromMoney").val());
- String svCode = Request.Form["svCode"];
- String advName = Request.Form["advName"];
- String msgAdv = Request.Form["msgAdv"];
- String channelAdv = Request.Form["channelAdv"];
- String messageType = Request.Form["messageType"];
- String activeHour = Request.Form["activeHour"];
- String maxNumberMsg = Request.Form["maxNumberMsg"];
- if (activeHour != null)
- {
- activeHour = activeHour.Replace(" ", "");
- }
- String fromMoney = Request.Form["fromMoney"];
- // call ws
- bool isSuccess = db.InsertSvAdv(svCode, msgAdv, advName, channelAdv, messageType, activeHour, maxNumberMsg, fromMoney);
- //db.InsertSvAdvHistory(svCode, messageType);
- // Returns message that successfully uploaded
- if (isSuccess)
- {
- return Json(new { error_code = "0", content = "Add service adv success" });
- }
- else
- {
- return Json(new { error_code = "2", content = "Add service adv failed! DB error." });
- }
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateServiceInfo()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String serviceId = Request.Form["serviceId"];
- String serviceName = Request.Form["serviceName"];
- String serviceCode = Request.Form["serviceCode"];
- // call ws
- db.UpdateServiceInfo(serviceId, serviceCode, serviceName);
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateServiceStatus()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String serviceId = Request.Form["serviceId"];
- String status = Request.Form["status"];
- // call ws
- db.UpdateServiceStatus(serviceId, status);
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateServiceRp()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String svCode = Request.Form["svCode"];
- String dbName = Request.Form["dbName"];
- String connectionString = Request.Form["connectionString"];
- String dbUserName = Request.Form["dbUserName"];
- String dbPassword = Request.Form["dbPassword"];
- String sqlReportDaily = Request.Form["sqlReportDaily"];
- String sqlReportHourly = Request.Form["sqlReportHourly"];
- db.UpdateServiceRpInfo(svCode, dbName, connectionString, dbUserName, dbPassword, sqlReportDaily, sqlReportHourly);
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateServiceRpStatus(String svCode, String status)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- db.UpdateServiceRpStatus(svCode, status);
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateServiceAdv()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String advId = Request.Form["advId"];
- String svCode = Request.Form["svCode"];
- String advName = Request.Form["advName"];
- String msgAdv = Request.Form["msgAdv"];
- String channelAdv = Request.Form["channelAdv"];
- String messageType = Request.Form["messageType"];
- String activeHour = Request.Form["activeHour"];
- String maxNumberMsg = Request.Form["maxNumberMsg"];
- if (activeHour != null)
- {
- activeHour = activeHour.Replace(" ", "");
- }
- String fromMoney = Request.Form["fromMoney"];
- bool isSuccess = db.UpdateServiceAdvInfo(svCode, msgAdv, advName, channelAdv, messageType, activeHour, maxNumberMsg, fromMoney, advId);
- if (isSuccess)
- {
- return Json(new { error_code = "0", content = "Update service adv success" });
- }
- else
- {
- return Json(new { error_code = "2", content = "Update service adv failed! DB error." });
- }
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateServiceAdvStatus(String advId, String status)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- // get adv info
- Services sv = db.GetServiceAdvById(advId);
- if (status == "0")
- {
- // update end time adv
- //db.UpdateServiceAdvEndTime(sv.sv_code);
- }
- else
- {
- // insert new adv
- //db.InsertSvAdvHistory(sv.sv_code, sv.message_type);
- }
- db.UpdateServiceAdvStatus(advId, status);
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- //
- // BROADCAST
- //
- [HttpPost]
- public JsonResult SearchBroadcast(String fromDate, String toDate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<Broadcast> listBroadcast = GetBroadcast(fromDate, toDate);
- return Json(new
- {
- error = "0",
- listBroadcast = listBroadcast
- });
- }
- private List<Broadcast> GetBroadcast(String fromdate, String todate)
- {
- DateTime? fr = null;
- if (fromdate != null) fr = DateTime.ParseExact(fromdate, "dd/MM/yyyy", null);
- DateTime? td = null;
- if (todate != null) DateTime.ParseExact(todate, "dd/MM/yyyy", null);
- return db.LoadListBroadcast(fr, td);
- }
- public ActionResult Broadcast()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- HttpContext.Session.Clear();
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- List<Broadcast> res = GetBroadcast(DateTime.Now.AddDays(-30).ToString("dd/MM/yyyy"), DateTime.Now.ToString("dd/MM/yyyy"));
- return View(res);
- }
- //-------------
- // SMSGW
- //--------------
- public ActionResult Smsgw()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- HttpContext.Session.Clear();
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- List<WebserviceObj> res = GetSmsgw();
- return View(res);
- }
- [HttpPost]
- public JsonResult SearchSmsgw()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<WebserviceObj> listSmsgw = GetSmsgw();
- return Json(new
- {
- error = "0",
- listSmsgw = listSmsgw
- });
- }
- private List<WebserviceObj> GetSmsgw()
- {
- return db.LoadListWebserivce("sendmt");
- }
- [HttpPost]
- public ActionResult AddSmsgw(IFormFile msgTemplate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- //int countSub = 0;
- //string importFile = "";
- String wsCode = Request.Form["wsCode"];
- String wsName = Request.Form["wsName"];
- String wsdl = Request.Form["wsdl"];
- String msgTemplateStr = "";// Request.Form["msgTemplate"];
- // insert DB
- WebserviceObj wsObj = new WebserviceObj();
- wsObj.ws_code = wsCode;
- wsObj.ws_name = wsName;
- wsObj.wsdl = wsdl;
- // Get all files from Request object
- if (msgTemplate != null)
- {
- using (StreamReader inputStreamReader = new StreamReader(msgTemplate.OpenReadStream()))
- {
- msgTemplateStr = inputStreamReader.ReadToEnd();
- }
- }
- wsObj.msg_template = msgTemplateStr;
- db.InsertWebservice(wsObj);
- // Returns message that successfully uploaded
- return Json(new
- {
- error = "0",
- id = wsObj.ws_id
- });
- }
- catch (Exception ex)
- {
- return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateSmsgw(IFormFile msgTemplate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String wsCode = Request.Form["wsCode"];
- String wsName = Request.Form["wsName"];
- String wsdl = Request.Form["wsdl"];
- String msgTemplateStr = "";// Request.Form["msgTemplate"];
- String id = Request.Form["id"];
- // insert DB
- WebserviceObj wsObj = new WebserviceObj();
- wsObj.ws_code = wsCode;
- wsObj.ws_name = wsName;
- wsObj.wsdl = wsdl;
- // Get all files from Request object
- if (msgTemplate != null)
- {
- using (StreamReader inputStreamReader = new StreamReader(msgTemplate.OpenReadStream()))
- {
- msgTemplateStr = inputStreamReader.ReadToEnd();
- }
- }
- wsObj.msg_template = msgTemplateStr;
- wsObj.ws_id = int.Parse(id);
- db.UpdateWebservice(wsObj);
- return Json(new
- {
- error = "0",
- content = "Success"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateSmsgwStatus()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- 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"]);
- //WebserviceObj wsObj = db.GetWebserviceById(id)[0];
- db.UpdateWebserviceStatus(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 GetSmsgwById(String id)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- WebserviceObj wsObj = db.GetWebserviceById(int.Parse(id))[0];
- return Json(new
- {
- error = "0",
- smsgw = wsObj
- });
- }
- //----------------
- // SERVICE ADV SHCEDULE
- //----------------
- public ActionResult ServiceAdvScheduler(int? month, int? year, int? codeType)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- HttpContext.Session.Clear();
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (month == null)
- {
- month = DateTime.Now.Month;
- }
- if (year == null)
- {
- year = DateTime.Now.Year;
- }
- List<SvAdvSchedule> listService = db.LoadListSvAdvSchedule(month.Value, year.Value, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
- ViewBag.codeType = codeType;
- return View(listService);
- }
- [HttpPost]
- public JsonResult SearchSvAdvSchedule(int month, int year, int? codeType)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<SvAdvSchedule> listService = db.LoadListSvAdvSchedule(month, year, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
- return Json(new
- {
- error = "0",
- content = "Success",
- listService = listService
- });
- }
- [HttpPost]
- public JsonResult GetSvAdvScheduleById(String scheduleId, int? codeType)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- SvAdvSchedule service = db.GetSvAdvScheduleById(scheduleId, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
- return Json(new
- {
- error = "0",
- content = "Success",
- service = service
- });
- }
- [HttpPost]
- public ActionResult AddSvAdvSchedule()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String scheduleName = Request.Form["scheduleName"];
- String maxTotalMsg = Request.Form["maxTotalMsg"];
- String fromDate = Request.Form["fromDate"];
- String toDate = Request.Form["toDate"];
- String listAdv = Request.Form["listAdv"];
- String codeType = Request.Form["codeType"];
- Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(listAdv);
- SvAdvSchedule advSchedule = new SvAdvSchedule();
- advSchedule.from_date = DateTime.ParseExact(fromDate, "dd/MM/yyyy HH:mm:ss", null);
- advSchedule.to_date = DateTime.ParseExact(toDate, "dd/MM/yyyy HH:mm:ss", null);
- advSchedule.schedule_name = scheduleName;
- if (maxTotalMsg != null)
- {
- advSchedule.max_total_msg = int.Parse(maxTotalMsg);
- }
- else
- {
- advSchedule.max_total_msg = 0;
- }
- advSchedule.list_adv = new List<SvAdv>();
- foreach (ListAdv adv in myDeserializedClass.listAdv)
- {
- SvAdv svAdv = new SvAdv();
- svAdv.id = int.Parse(adv.id);
- svAdv.percent = int.Parse(adv.percent);
- if (svAdv.percent > 0)
- {
- advSchedule.list_adv.Add(svAdv);
- }
- }
- // insert
- if (db.InsertSvAdvSchedule(advSchedule, int.Parse(codeType)))
- {
- // Returns message that successfully uploaded
- return Json(new
- {
- error_code = "0"
- });
- }
- else
- {
- // Returns message that successfully uploaded
- return Json(new
- {
- error_code = "1",
- error_content = "Error database"
- });
- }
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateSvAdvSchedule()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- String scheduleId = Request.Form["scheduleId"];
- String scheduleName = Request.Form["scheduleName"];
- String maxTotalMsg = Request.Form["maxTotalMsg"];
- String fromDate = Request.Form["fromDate"];
- String toDate = Request.Form["toDate"];
- String listAdv = Request.Form["listAdv"];
- String codeType = Request.Form["codeType"];
- //JavaScriptSerializer json_serializer = new JavaScriptSerializer();
- //SvAdvJson[] svAdvs = (SvAdvJson[])json_serializer.DeserializeObject(listAdv);
- Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(listAdv);
- SvAdvSchedule advSchedule = new SvAdvSchedule();
- advSchedule.from_date = DateTime.ParseExact(fromDate, "dd/MM/yyyy HH:mm:ss", null);
- advSchedule.to_date = DateTime.ParseExact(toDate, "dd/MM/yyyy HH:mm:ss", null);
- advSchedule.schedule_name = scheduleName;
- if (maxTotalMsg != null)
- {
- advSchedule.max_total_msg = int.Parse(maxTotalMsg);
- }
- else
- {
- advSchedule.max_total_msg = 0;
- }
- advSchedule.id = int.Parse(scheduleId);
- advSchedule.list_adv = new List<SvAdv>();
- foreach (ListAdv adv in myDeserializedClass.listAdv)
- {
- SvAdv svAdv = new SvAdv();
- svAdv.id = int.Parse(adv.id);
- svAdv.percent = int.Parse(adv.percent);
- if (svAdv.percent > 0)
- {
- advSchedule.list_adv.Add(svAdv);
- }
- }
- // insert
- if (db.UpdateSvAdvScheduleInfo(advSchedule, int.Parse(codeType)))
- {
- return Json(new
- {
- error_code = "0"
- });
- }
- else
- {
- return Json(new
- {
- error_code = "1",
- error_content = "Error database"
- });
- }
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- [HttpPost]
- public ActionResult UpdateSvAdvScheduleStatus(String scheduleid, String status, String codeType)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- try
- {
- db.UpdateSvAdvScheduleStatus(scheduleid, status, int.Parse(codeType));
- return Json(new
- {
- error_code = "0"
- });
- }
- catch (Exception ex)
- {
- return Json(new { error_code = "2", content = "Error occurred. Error details: " + ex.Message });
- }
- }
- public ActionResult GetServiceAdvPartial(String scheduleId, int? codeType)
- {
- ViewBag.codeType = codeType;
- if (scheduleId == null)
- {
- List<SvAdv> listAdv = db.LoadListServicesAdv();
- SvAdvSchedule scheduler = new SvAdvSchedule();
- scheduler.list_adv = listAdv;
- return PartialView("_ScheduleDetail", scheduler);
- }
- else
- {
- SvAdvSchedule scheduler = db.GetSvAdvScheduleById(scheduleId, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
- return PartialView("_ScheduleDetail", scheduler);
- }
- }
- // counter
- public ActionResult ServiceAdvCounter(int? month, int? year, int? codeType)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (user.role != Common.UserRole.Admin)
- {
- HttpContext.Session.Clear();
- ViewBag.username = "Welcome!";
- return Redirect(subDomain + "/Home/Login");
- }
- if (month == null)
- {
- month = DateTime.Now.Month;
- }
- if (year == null)
- {
- year = DateTime.Now.Year;
- }
- List<SvAdv> listService = db.LoadListSvAdvCounter(month.Value, year.Value, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
- ViewBag.codeType = codeType;
- return View(listService);
- }
- [HttpPost]
- public JsonResult SearchSvAdvCounter(int month, int year, int? codeType)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- if (user.role != Common.UserRole.Admin)
- {
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- List<SvAdv> listService = db.LoadListSvAdvCounter(month, year, codeType ?? LuckyCardUtils.CodeType.LUCKY_CARD);
- return Json(new
- {
- error = "0",
- content = "Success",
- listService = listService
- });
- }
- }
- }
|