using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Threading; using System.Threading.Tasks; using LotteryWebApp.Common; using LotteryWebApp.Extensions; using LotteryWebApp.Languages; using LotteryWebApp.Models; using LotteryWebApp.Service; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using LotteryWebApp.Controllers; namespace LotteryWebApp.Areas.Millions.Controllers { [Area("Millions")] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public class HomeController : BaseController { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program)); IConfiguration configuration; private readonly IWebHostEnvironment webHostEnvironment; APIFunctions api = new APIFunctions(); public HomeController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) { configuration = _configuration; webHostEnvironment = hostEnvironment; } public String GetParameter(String key) { return configuration.GetSection(key).Value; } public async Task Index( string termType, String uuid, String mcuid, String phonenumber, String token ) { HomeIndex_ViewModel model = new HomeIndex_ViewModel(); try { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; String lang = currentCulture.Name; String msisdnAuto = null; if (!CheckAuthToken()) { if (token != null) { AutoLoginRequest autoLoginRequest = new AutoLoginRequest { token = token }; AutoLoginResponse autoLoginResponse = await api.AutoLoginApiAsync(configuration, autoLoginRequest); if (autoLoginResponse.code == Code.SUCCESS_CODE) { string msisdnReal = validateMsisdn(autoLoginResponse.data.msisdn.Substring(1)); if (msisdnReal == "") return RedirectToAction("Login", "Account", new { area = "" }); CheckAccountRequest checkAccountRequest = new CheckAccountRequest { msisdn = msisdnReal, channel = Constants.WEB_CHANNEL, language = lang == "en" ? "0" : "1" }; CheckAccountResponse checkAccountResponse = api.CheckAccountApi(configuration, checkAccountRequest); if (checkAccountResponse.status == Code.SUCCESS) { string tokenGetReal = checkAccountResponse.token; HttpContext.Session.SetComplexData("msisdn", msisdnReal); CreateAuthToken(); HttpContext.Session.SetComplexData("token", tokenGetReal); UserGetProfileRequest userGetProfileRequest = new UserGetProfileRequest { users = msisdnReal, token = tokenGetReal }; Profile profileGet = api.UserLoadProfileApi(configuration, userGetProfileRequest); HttpContext.Session.SetComplexData("profile", profileGet); UserStatusRequest userStatusRequest = new UserStatusRequest { users = msisdnReal, token = tokenGetReal }; UserStatus userStatusGet = api.GetUserStatusApi(configuration, userStatusRequest); HttpContext.Session.SetComplexData("userStatus", userStatusGet); } else { return RedirectToAction("Login", "Account", new { area = "" }); } } } else if (uuid != null) { String res = await CheckAutoLogin(log, uuid); if (res != null) { dynamic json = JsonConvert.DeserializeObject(res); if (json["code"] == "200" && json["errorCode"] == "200") { msisdnAuto = json["data"]["msisdn"]; } } String msisdnDetect = validateMsisdn(msisdnAuto.Substring(1)); if (msisdnDetect != "") { RegisterRequest request = new RegisterRequest { Msisdn = msisdnDetect }; RegisterResponse reset = api.UserForgotPasswordApi(configuration, request); if (reset.status == Code.SUCCESS) { HttpContext.Session.Remove("regInfos"); HttpContext.Session.SetComplexData("msisdn", msisdnDetect); return RedirectToAction("Login", "Account", new { area = "", step = 2 }); } } return RedirectToAction("Login", "Account", new { area = "" }); } else if (phonenumber != null) { // simplified or same logic as original return RedirectToAction("Login", "Account", new { area = "" }); } else { // If no token/uuid and not auth, verify existing session token var savedToken = HttpContext.Session.GetString("token"); if (string.IsNullOrEmpty(savedToken)) { return RedirectToAction("Login", "Account", new { area = "" }); } } } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.termType = termType != null ? termType : Constants.Millions_CODE; model.userStatus = userStatus; model.profile = profile; model.listTerm = new List(); String tokenGet = HttpContext.Session.GetComplexData("token"); String fromDate = DateTime.Now.AddDays(-2).ToString("dd/MM/yyyy"); String toDate = DateTime.Now.ToString("dd/MM/yyyy"); // Get Top Winner GetTopWinnerRequest getTopWinnerRequest = new GetTopWinnerRequest { type = lang == "en" ? "0" : "1", token = tokenGet }; GetTopWininerResponse getTopWininerResponse = api.GetTopWinnerApi(configuration, getTopWinnerRequest); if (getTopWininerResponse.responseCode == Code.SUCCESS) { model.topWinner = getTopWininerResponse.list; HttpContext.Session.SetComplexData("topWinner", model.topWinner); } // Get Term Results //ResultOfTermRequest resultOfTermRequest = new ResultOfTermRequest //{ // gameId = model.termType, // token = tokenGet, // type = Constants.TERM_HAS_NOT_RESULT_TYPE, // order = Constants.DECS, // fromDate = fromDate, // toDate = toDate, // rowsOnPage = Constants.ROW_ON_PAGE, // seqPage = "1", // id = Constants.ALL_DATA //}; //ResultOfTermResponse result = api.GetResultOfTermApi(configuration, resultOfTermRequest); //if (result.responseCode == Code.SESSION_EXPIRED) //{ // return RedirectToAction("Login", "Account", new { area = "" }); //} //else if (result.responseCode == Code.SUCCESS) //{ // model.listTerm = result.listTerm; //} if (!string.IsNullOrEmpty(termType)) { HttpContext.Session.SetString("termType", termType); } } catch (Exception ex) { log.Error(ex); return RedirectToAction("Login", "Account", new { area = "" }); } return View(model); } public async Task GameHome(string termType) { HomeIndex_ViewModel model = new HomeIndex_ViewModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.termType = termType != null ? termType : Constants.Millions_CODE; model.userStatus = userStatus; model.profile = profile; model.listTerm = new List(); if (!string.IsNullOrEmpty(termType)) { HttpContext.Session.SetString("termType", termType); } } catch (Exception ex) { log.Error(ex); } return View(model); } public async Task FAQ() { HomeIndex_ViewModel model = new HomeIndex_ViewModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.userStatus = userStatus; model.profile = profile; } catch (Exception ex) { log.Error(ex); } return View(model); } public IActionResult More() { HomeIndex_ViewModel model = new HomeIndex_ViewModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.userStatus = userStatus; model.profile = profile; } catch (Exception ex) { log.Error(ex); } return View(model); } public IActionResult Profile() { HomeIndex_ViewModel model = new HomeIndex_ViewModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.userStatus = userStatus; model.profile = profile; } catch (Exception ex) { log.Error(ex); } return View(model); } [HttpPost] public IActionResult UserUpdateProfile(string fullName, string birthday) { try { string msisdn = HttpContext.Session.GetComplexData("msisdn"); string token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(msisdn) || string.IsNullOrEmpty(token)) { return Json(new { status = Code.ERROR, message = "Session expired" }); } string birthdayFormat = birthday; if (!string.IsNullOrEmpty(birthday) && birthday.Contains("-")) { try { birthdayFormat = DateTime.ParseExact(birthday, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"); } catch { } } UserUpdateProfileRequest request = new UserUpdateProfileRequest { users = msisdn, token = token, fullName = fullName, birthday = birthdayFormat }; UserUpdateProfileResponse response = api.UserUpdateProfileApi(configuration, request); if (response.status == Code.SUCCESS) { // Update session profile Profile profile = HttpContext.Session.GetComplexData("profile"); if (profile != null) { profile.fullName = fullName; profile.birthday = birthdayFormat; HttpContext.Session.SetComplexData("profile", profile); } } return Json(response); } catch (Exception ex) { log.Error(ex); return Json(new { status = Code.ERROR, message = ex.Message }); } } public IActionResult Rule() { HomeIndex_ViewModel model = new HomeIndex_ViewModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.userStatus = userStatus; model.profile = profile; } catch (Exception ex) { log.Error(ex); } return View(model); } public IActionResult HowToPlay() { HomeIndex_ViewModel model = new HomeIndex_ViewModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.userStatus = userStatus; model.profile = profile; } catch (Exception ex) { log.Error(ex); } return View(model); } public IActionResult Results(string termType, string fromDate, string toDate) { TermResultHistoryModel model = new TermResultHistoryModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.termType = termType != null ? termType : (HttpContext.Session.GetString("termType") ?? Constants.Millions_CODE); // Set default dates if not provided (same as root implementation) string fromFormatted = fromDate != null ? fromDate : DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"); string toFormatted = toDate != null ? toDate : DateTime.Now.ToString("yyyy-MM-dd"); model.fromDate = fromFormatted; model.toDate = toFormatted; // Load initial results ResultOfTermRequest resultOfTermRequest = new ResultOfTermRequest { gameId = model.termType, token = token, type = Constants.TERM_HAS_RESULT_TYPE, order = Constants.DECS, fromDate = DateTime.ParseExact(fromFormatted, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"), toDate = DateTime.ParseExact(toFormatted, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"), rowsOnPage = Constants.ROW_ON_PAGE, seqPage = "1", id = Constants.ALL_DATA }; ResultOfTermResponse result = api.GetResultOfTermApi(configuration, resultOfTermRequest); if (result.responseCode == Code.SUCCESS) { model.listTerm = result.listTerm ?? new List(); } else { model.listTerm = new List(); } } catch (Exception ex) { log.Error(ex); model.listTerm = new List(); } return View(model); } public IActionResult TermResultHistory(string termType, string fromDate, string toDate) { TermResultHistoryModel model = new TermResultHistoryModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token)) return Json(new { status = "error", message = "Session expired" }); string fromFormatted = fromDate != null ? fromDate : DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"); string toFormatted = toDate != null ? toDate : DateTime.Now.ToString("yyyy-MM-dd"); model.termType = termType; model.fromDate = fromFormatted; model.toDate = toFormatted; ResultOfTermRequest request = new ResultOfTermRequest { gameId = termType, token = token, type = Constants.TERM_HAS_RESULT_TYPE, order = Constants.DECS, fromDate = DateTime.ParseExact(fromFormatted, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"), toDate = DateTime.ParseExact(toFormatted, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"), rowsOnPage = Constants.ROW_ON_PAGE, seqPage = "1", id = Constants.ALL_DATA }; ResultOfTermResponse result = api.GetResultOfTermApi(configuration, request); if (result.responseCode == Code.SUCCESS) { model.listTerm = result.listTerm ?? new List(); } else { model.listTerm = new List(); } } catch (Exception ex) { log.Error(ex); model.listTerm = new List(); } return PartialView("_TermResultHistoryV2", model); } public IActionResult TermResultHistoryGrouped(string fromDate, string toDate) { try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token)) return Json(new { status = "error", message = "Session expired" }); string fromFormatted = fromDate != null ? fromDate : DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"); string toFormatted = toDate != null ? toDate : DateTime.Now.ToString("yyyy-MM-dd"); string[] gameIds = { Constants.Millions_CODE }; var allTerms = new List(); foreach (var gid in gameIds) { ResultOfTermRequest request = new ResultOfTermRequest { gameId = gid, token = token, type = Constants.TERM_HAS_RESULT_TYPE, order = Constants.DECS, fromDate = DateTime.ParseExact(fromFormatted, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"), toDate = DateTime.ParseExact(toFormatted, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"), rowsOnPage = "50", seqPage = "1", id = Constants.ALL_DATA }; ResultOfTermResponse result = api.GetResultOfTermApi(configuration, request); if (result.responseCode == Code.SUCCESS && result.listTerm != null) { allTerms.AddRange(result.listTerm); } } // Group by date part of date_random var grouped = allTerms.GroupBy(x => { DateTime dt; if (DateTime.TryParse(x.date_random, out dt)) return dt.Date; return DateTime.MinValue; }) .Where(g => g.Key != DateTime.MinValue) .OrderByDescending(g => g.Key) .ToList(); return PartialView("_TermResultHistoryGrouped", grouped); } catch (Exception ex) { log.Error(ex); return PartialView("_TermResultHistoryGrouped", new List>()); } } public IActionResult History(string termType, string status, string seqPage) { UserTicketHistoryModel model = new UserTicketHistoryModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } string msisdn = HttpContext.Session.GetComplexData("msisdn"); model.termType = termType ?? Constants.Millions_CODE; model.status = status ?? Constants.ALL_DATA; // -1 for all, or 0, 1, 2 model.seqPage = seqPage ?? "1"; UserTicketRequest request = new UserTicketRequest { gameId = model.termType, msisdn = msisdn, token = token, type = model.status, order = Constants.DECS, rowsOnPage = Constants.ROW_ON_PAGE, seqPage = model.seqPage }; UserTicketResponse result = api.GetUserTicketApi(configuration, request); if (result.responseCode == Code.SUCCESS) { model.listTicket = result.listTicket ?? new List(); model.totalPage = result.totalPage; } else { model.listTicket = new List(); model.totalPage = "0"; } } catch (Exception ex) { log.Error(ex); model.listTicket = new List(); } return View(model); } public IActionResult TermUserTicketHistory(string termType, string status, string seqPage) { UserTicketHistoryModel model = new UserTicketHistoryModel(); try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token)) return Json(new { status = "error", message = "Session expired" }); string msisdn = HttpContext.Session.GetComplexData("msisdn"); model.termType = termType; model.status = status; model.seqPage = seqPage ?? "1"; UserTicketRequest request = new UserTicketRequest { gameId = termType, msisdn = msisdn, token = token, type = status, order = Constants.DECS, rowsOnPage = Constants.ROW_ON_PAGE, seqPage = model.seqPage }; UserTicketResponse result = api.GetUserTicketApi(configuration, request); if (result.responseCode == Code.SUCCESS) { model.listTicket = result.listTicket ?? new List(); model.totalPage = result.totalPage; } else { model.listTicket = new List(); model.totalPage = "0"; } } catch (Exception ex) { log.Error(ex); model.listTicket = new List(); } return PartialView("_TermUserTicketHistory", model); } [HttpPost] [ValidateAntiForgeryToken] public IActionResult TermResult(string termType) { try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token)) return Json(new { responseCode = Code.SESSION_EXPIRED, responseMessage = "Session expired" }); string lang = CultureInfo.CurrentCulture.Name; string langValue = (lang.StartsWith("en") || lang.StartsWith("fr")) ? "0" : "1"; ResultOfTermRequest request = new ResultOfTermRequest { gameId = termType, language = langValue, token = token, type = Constants.TERM_HAS_NOT_RESULT_TYPE, order = Constants.DECS, rowsOnPage = "5", seqPage = "1", id = Constants.ALL_DATA }; ResultOfTermResponse result = api.GetResultOfTermApi(configuration, request); return Json(result); } catch (Exception ex) { log.Error(ex); return Json(new { responseCode = Code.ERROR, responseMessage = ex.Message }); } } [HttpPost] public IActionResult ConfirmTicketData([FromBody] ConfirmTicketDataRequest request) { try { var token = HttpContext.Session.GetComplexData("token"); var msisdn = HttpContext.Session.GetComplexData("msisdn"); if (string.IsNullOrEmpty(token)) return Json(new { responseCode = Code.SESSION_EXPIRED, responseMessage = "Session expired" }); request.token = token; request.msisdn = msisdn; request.language = CultureInfo.CurrentCulture.Name.StartsWith("en") ? "0" : "1"; request.requestId = Guid.NewGuid().ToString(); // DEBUG: Log request data var ticketDebug = request.ticket != null ? string.Join("; ", request.ticket.Select(t => $"code={t.code}, money={t.money}")) : "NULL"; log.Info($"[ConfirmTicketData] gameId={request.gameId}, msisdn={request.msisdn}, tickets=[{ticketDebug}]"); ConfirmTicketDataResponse response = api.ConfirmTicketDataApi(configuration, request); // DEBUG: Log response log.Info($"[ConfirmTicketData] Response: code={response.responseCode}, msg={response.responseMessage}, transId={response.transId}"); return Json(response); } catch (Exception ex) { log.Error(ex); return Json(new { responseCode = Code.ERROR, responseMessage = ex.Message }); } } [HttpPost] public IActionResult ConfirmOTP([FromBody] ConfirmOTPRequest request) { try { var token = HttpContext.Session.GetComplexData("token"); var msisdn = HttpContext.Session.GetComplexData("msisdn"); if (string.IsNullOrEmpty(token)) return Json(new { responseCode = Code.SESSION_EXPIRED, responseMessage = "Session expired" }); request.token = token; request.msisdn = msisdn; ConfirmOTPResponse response = api.ConfirmOTPApi(configuration, request); return Json(response); } catch (Exception ex) { log.Error(ex); return Json(new { responseCode = Code.ERROR, responseMessage = ex.Message }); } } [HttpPost] public IActionResult SendOTP() { try { var token = HttpContext.Session.GetComplexData("token"); var msisdn = HttpContext.Session.GetComplexData("msisdn"); if (string.IsNullOrEmpty(token)) return Json(new { responseCode = Code.SESSION_EXPIRED, responseMessage = "Session expired" }); SendOTPRequest request = new SendOTPRequest { msisdn = msisdn, token = token, language = CultureInfo.CurrentCulture.Name.StartsWith("en") ? "0" : "1", channel = configuration.GetSection("channel").Value }; SendOTPResponse response = api.SendOTPApi(configuration, request); return Json(response); } catch (Exception ex) { log.Error(ex); return Json(new { responseCode = Code.ERROR, responseMessage = ex.Message }); } } [HttpPost] public IActionResult ConfirmBuyingTicketV2([FromBody] ConfirmBuyingTicketRequest request) { try { var token = HttpContext.Session.GetComplexData("token"); var msisdn = HttpContext.Session.GetComplexData("msisdn"); if (string.IsNullOrEmpty(token)) return Json(new { responseCode = Code.SESSION_EXPIRED, responseMessage = "Session expired" }); // Step 1: Verify OTP first ConfirmOTPRequest otpRequest = new ConfirmOTPRequest { otp = request.paymentCode, msisdn = msisdn, token = token, language = CultureInfo.CurrentCulture.Name.StartsWith("en") ? "0" : "1", channel = configuration.GetSection("channel").Value }; ConfirmOTPResponse otpResponse = api.ConfirmOTPApi(configuration, otpRequest); if (otpResponse.responseCode != Code.SUCCESS) { return Json(new { responseCode = otpResponse.responseCode, responseMessage = otpResponse.responseMessage }); } // Step 2: Proceed to Confirm buying request.token = token; request.msisdn = msisdn; request.requestId = Guid.NewGuid().ToString(); request.language = CultureInfo.CurrentCulture.Name.StartsWith("en") ? "0" : "1"; request.channel = configuration.GetSection("channel").Value; ConfirmBuyingTicketResponse response = api.ConfirmBuyingTicketApi(configuration, request); if (response.responseCode == Code.SUCCESS) { UpdateUserStatus(msisdn, token); } return Json(response); } catch (Exception ex) { log.Error(ex); return Json(new { responseCode = Code.ERROR, responseMessage = ex.Message }); } } [HttpPost] public IActionResult ConfirmBuyingTicket([FromBody] ConfirmBuyingTicketRequest request) { try { var token = HttpContext.Session.GetComplexData("token"); var msisdn = HttpContext.Session.GetComplexData("msisdn"); if (string.IsNullOrEmpty(token)) return Json(new { responseCode = Code.SESSION_EXPIRED, responseMessage = "Session expired" }); request.token = token; request.msisdn = msisdn; request.requestId = Guid.NewGuid().ToString(); request.language = CultureInfo.CurrentCulture.Name.StartsWith("en") ? "0" : "1"; request.channel = configuration.GetSection("channel").Value; ConfirmBuyingTicketResponse response = api.ConfirmBuyingTicketApi(configuration, request); if (response.responseCode == Code.SUCCESS) { UpdateUserStatus(msisdn, token); } return Json(new { responseCode = response.responseCode, responseMessage = response.responseMessage, transId = response.transId, orderId = response.orderId, userStatus = HttpContext.Session.GetComplexData("userStatus") }); } catch (Exception ex) { log.Error(ex); return Json(new { responseCode = Code.ERROR, responseMessage = ex.Message }); } } public IActionResult BuyTicket(string termType) { try { var token = HttpContext.Session.GetComplexData("token"); if (string.IsNullOrEmpty(token) && !User.Identity.IsAuthenticated) { return RedirectToAction("Login", "Account", new { area = "" }); } HomeIndex_ViewModel model = new HomeIndex_ViewModel(); model.termType = termType ?? Constants.Millions_CODE; Profile profile = HttpContext.Session.GetComplexData("profile"); UserStatus userStatus = HttpContext.Session.GetComplexData("userStatus"); model.userStatus = userStatus; model.profile = profile; // Get active term ResultOfTermRequest request = new ResultOfTermRequest { gameId = model.termType, token = token, type = Constants.TERM_HAS_NOT_RESULT_TYPE, order = Constants.DECS, rowsOnPage = "1", seqPage = "1", id = Constants.ALL_DATA }; ResultOfTermResponse result = api.GetResultOfTermApi(configuration, request); if (result.responseCode == Code.SUCCESS && result.listTerm != null && result.listTerm.Count > 0) { model.listTerm = result.listTerm; } else { model.listTerm = new List(); } if (model.termType == Constants.PIC10_BIGSMALL_CODE || model.termType == Constants.PIC10_ODDEVEN_CODE) { ResultOfTermRequest pastRequest = new ResultOfTermRequest { gameId = model.termType, token = token, type = Constants.TERM_HAS_RESULT_TYPE, order = Constants.DECS, fromDate = DateTime.Now.AddDays(-10).ToString("dd/MM/yyyy"), toDate = DateTime.Now.ToString("dd/MM/yyyy"), rowsOnPage = "5", seqPage = "1", id = Constants.ALL_DATA }; ResultOfTermResponse pastResult = api.GetResultOfTermApi(configuration, pastRequest); if (pastResult.responseCode == Code.SUCCESS && pastResult.listTerm != null) { var pastTerms = pastResult.listTerm.Take(5).ToList(); pastTerms.Reverse(); // Display chronological order ViewBag.PastTerms = pastTerms; } else { ViewBag.PastTerms = new List(); } } return View(model); } catch (Exception ex) { log.Error(ex); return RedirectToAction("GameHome", new { termType = termType }); } } public IActionResult TransferWinMoney() { if (!CheckAuthToken()) { return RedirectToAction("Login", "Account", new { area = "" }); } HomeIndex_ViewModel model = new HomeIndex_ViewModel(); model.profile = HttpContext.Session.GetComplexData("profile"); model.userStatus = HttpContext.Session.GetComplexData("userStatus"); return View(model); } [HttpPost] public IActionResult ConfirmTransfer(string otp, string phone, string amount) { try { var token = HttpContext.Session.GetComplexData("token"); var msisdn = HttpContext.Session.GetComplexData("msisdn"); if (string.IsNullOrEmpty(token)) return Json(new { status = Code.SESSION_EXPIRED, message = "Session expired" }); // Step 1: Verify OTP ConfirmOTPRequest otpRequest = new ConfirmOTPRequest { otp = otp, msisdn = msisdn, token = token, language = CultureInfo.CurrentCulture.Name.StartsWith("en") ? "0" : "1", channel = configuration.GetSection("channel").Value }; ConfirmOTPResponse otpResponse = api.ConfirmOTPApi(configuration, otpRequest); if (otpResponse.responseCode != Code.SUCCESS) { return Json(new { status = otpResponse.responseCode, message = otpResponse.responseMessage }); } // Step 2: If OTP success, call Transfer Money Api TransferMoneyRequest xferRequest = new TransferMoneyRequest { msisdn = msisdn, msisdnReceive = phone, money = amount, otp = otp, token = token, channelPayment = Constants.BASIC_WALLET_TRANSFER, language = CultureInfo.CurrentCulture.Name.StartsWith("en") ? "0" : "1", channel = configuration.GetSection("channel").Value }; TransferMoneyResponse xferResponse = api.TransferMoneyApi(configuration, xferRequest); if (xferResponse.responseCode == Code.SUCCESS) { UpdateUserStatus(msisdn, token); } return Json(new { status = xferResponse.responseCode, message = xferResponse.responseMessage, paymentCode = xferResponse.paymentCode, responseCode = xferResponse.responseCode, userStatus = HttpContext.Session.GetComplexData("userStatus") }); } catch (Exception ex) { log.Error(ex); return Json(new { status = Code.ERROR, message = ex.Message }); } } private void UpdateUserStatus(string msisdn, string token) { try { UserStatusRequest userStatusRequest = new UserStatusRequest { users = msisdn, token = token }; UserStatus userStatusGet = api.GetUserStatusApi(configuration, userStatusRequest); if (userStatusGet != null) { HttpContext.Session.SetComplexData("userStatus", userStatusGet); } } catch (Exception ex) { log.Error("UpdateUserStatus Error: " + ex.Message); } } public IActionResult Logout() { ClearCache(); return Redirect(GetParameter(Constants.SUB_DOMAIN) + "/Account/Login"); } } }