|
|
@@ -36,780 +36,6 @@ namespace Esim.Apis.Business
|
|
|
return configuration.GetSection(key).Value ?? "";
|
|
|
}
|
|
|
|
|
|
- //public async Task<IActionResult> DetectMsisdn(
|
|
|
- // HttpRequest httpRequest,
|
|
|
- // DetectMsisdnReq request
|
|
|
- //)
|
|
|
- //{
|
|
|
- // var url = httpRequest.Path;
|
|
|
- // var json = JsonConvert.SerializeObject(request);
|
|
|
- // log.Debug("URL: " + url + " => Request: " + json);
|
|
|
- // try
|
|
|
- // {
|
|
|
- // //// add prize to user
|
|
|
- // //var addPrizeResult = await QuestLogic.AddPrizeForUser(
|
|
|
- // // dbContext,
|
|
|
- // // "67075723423",
|
|
|
- // // 101
|
|
|
- // //);
|
|
|
-
|
|
|
-
|
|
|
- // var msisdn = DotnetLib.Logic.ReuseLogic.TelemorValidateMsisdn(GetParameter("CountryCode"), request.msisdn);
|
|
|
- // if (msisdn == null)
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("MSISDN_INVALID"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // Account? account = null;
|
|
|
- // if (request.accessToken != null)
|
|
|
- // {
|
|
|
- // // check access token
|
|
|
- // account = dbContext
|
|
|
- // .Accounts.Where(x => x.Msisdn == msisdn)
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (account == null)
|
|
|
- // {
|
|
|
- // // create account
|
|
|
- // Account accountCreate = new Account
|
|
|
- // {
|
|
|
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "ACCOUNT_SEQ"),
|
|
|
- // Msisdn = msisdn,
|
|
|
- // Password = CommonLogic.GenPassword(6),
|
|
|
- // RefreshToken = request.accessToken,
|
|
|
- // Username = msisdn,
|
|
|
- // Birthday = DateTime.Now,
|
|
|
- // CreatedDate = DateTime.Now,
|
|
|
- // };
|
|
|
- // dbContext.Accounts.Add(accountCreate);
|
|
|
- // await dbContext.SaveChangesAsync();
|
|
|
- // account = accountCreate;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else if (request.msisdn != null && request.password != null)
|
|
|
- // {
|
|
|
- // // after checking access token
|
|
|
- // // check user
|
|
|
- // account = dbContext
|
|
|
- // .Accounts.Where(x => x.Msisdn == msisdn && x.Password == request.password)
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (account == null)
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "Invalid msisdn or password",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "Invalid msisdn or password",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // // gen token
|
|
|
- // string token = CommonLogic.GenToken(configuration, account.Msisdn, account.Id.ToString());
|
|
|
- // string refreshToken = CommonLogic.GenRefreshToken(configuration, account.Msisdn);
|
|
|
-
|
|
|
- // // update token
|
|
|
- // account.RefreshToken = token;
|
|
|
- // dbContext.Accounts.Update(account);
|
|
|
- // await dbContext.SaveChangesAsync();
|
|
|
-
|
|
|
- // // get inviting mission
|
|
|
- // var mission = dbContext
|
|
|
- // .Missions.Where(x =>
|
|
|
- // x.Type == CommonConstant.TypeInviting
|
|
|
- // && x.Status == CommonConstant.StatusActive
|
|
|
- // && x.FromTime <= DateTime.Now
|
|
|
- // && x.ToTime >= DateTime.Now
|
|
|
- // ).FirstOrDefault();
|
|
|
-
|
|
|
- // if (mission != null)
|
|
|
- // {
|
|
|
- // // check user inviting
|
|
|
- // var inviting = dbContext.InvitingHistories.Where(
|
|
|
- // x => x.Receiver == account.Msisdn && x.Status == CommonConstant.StatusSuccess && x.InvitedTime >= mission.FromTime && x.InvitedTime <= mission.ToTime
|
|
|
- // ).FirstOrDefault();
|
|
|
- // if (inviting != null)
|
|
|
- // {
|
|
|
- // inviting.Status = CommonConstant.StatusClaimed;
|
|
|
- // dbContext.InvitingHistories.Update(inviting);
|
|
|
- // await dbContext.SaveChangesAsync();
|
|
|
- // // check time required
|
|
|
- // var invitingClaimed = dbContext.InvitingHistories.Where(x => x.Msisdn == inviting.Msisdn && x.Status == CommonConstant.StatusClaimed && x.InvitedTime >= mission.FromTime && x.InvitedTime <= mission.ToTime).Count();
|
|
|
- // if (invitingClaimed >= mission.RequiredTime)
|
|
|
- // {
|
|
|
- // log.Debug("User invited, add prize for user");
|
|
|
-
|
|
|
- // var accountInviting = dbContext.Accounts.Where(x => x.Msisdn == inviting.Msisdn).FirstOrDefault();
|
|
|
- // if (accountInviting == null)
|
|
|
- // {
|
|
|
- // log.Error("Not found account for inviting msisdn: " + inviting.Msisdn);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // // update mission completed status to claimed
|
|
|
- // await QuestLogic.SetCompletedMissionForUserAsync(dbContext, accountInviting.Msisdn, accountInviting.Id, mission);
|
|
|
-
|
|
|
- // // add prize for user
|
|
|
- // var addPrizeRes = await QuestLogic.AddPrizeForUser(
|
|
|
- // dbContext,
|
|
|
- // accountInviting.Msisdn,
|
|
|
- // mission.Id
|
|
|
- // );
|
|
|
-
|
|
|
- // // send mt to owner
|
|
|
- // await MtLogic.SendMt(
|
|
|
- // dbContext,
|
|
|
- // accountInviting.Msisdn,
|
|
|
- // ConfigManager.Instance.GetConfigSmsValue("OWNER_INVITE_SUCCESS")
|
|
|
- // );
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // log.Debug($"No inviting mission implement for {account.Msisdn}");
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // bool canPlay = true;
|
|
|
- // decimal? vendorPackageId = null;
|
|
|
-
|
|
|
- // // check if user completed vendor package
|
|
|
- // var campaignOpening = dbContext
|
|
|
- // .Campaigns.Where(
|
|
|
- // x =>
|
|
|
- // x.Status == CommonConstant.StatusActive
|
|
|
- // && x.FromTime <= DateTime.Now
|
|
|
- // && x.ToTime >= DateTime.Now
|
|
|
- // )
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (campaignOpening != null)
|
|
|
- // {
|
|
|
- // // check login history
|
|
|
- // var now = DateTime.Now;
|
|
|
- // // get config
|
|
|
- // var timeDiff = ConfigManager.Instance.GetConfigAppValue("LOGIN_TIME_DIFF") ?? "1440";
|
|
|
-
|
|
|
-
|
|
|
- // var missionLogin = dbContext
|
|
|
- // .Missions.Where(x => x.Type == CommonConstant.TypeLogin && x.CampaignId == campaignOpening.Id)
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (missionLogin != null)
|
|
|
- // {
|
|
|
- // // kiểm tra mission đã được set completed chưa
|
|
|
- // var checkCompleted = dbContext
|
|
|
- // .MissionCompleteds.Where(
|
|
|
- // x =>
|
|
|
- // x.Msisdn == account.Msisdn
|
|
|
- // && x.AccountId == account.Id
|
|
|
- // && x.MissionId == missionLogin.Id
|
|
|
- // )
|
|
|
- // .Count();
|
|
|
-
|
|
|
- // if (checkCompleted > 0)
|
|
|
- // {
|
|
|
- // // mission completed rồi, không cần check login nữa
|
|
|
- // log.Debug($"Misson login {missionLogin.Id} has completed for {msisdn}");
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // log.Debug($"Checking login mission {missionLogin.Id} for {msisdn}");
|
|
|
-
|
|
|
- // // check time required
|
|
|
- // var start = DateTime.Now.AddMinutes(-(int)missionLogin.RequiredTime * int.Parse(timeDiff));
|
|
|
-
|
|
|
- // var completedLogin = dbContext
|
|
|
- // .MissionHistories.Where(
|
|
|
- // x =>
|
|
|
- // x.Msisdn == account.Msisdn
|
|
|
- // && x.AccountId == account.Id
|
|
|
- // && x.MissionId == missionLogin.Id
|
|
|
- // && x.ExecutedTime >= start
|
|
|
- // && x.ExecutedTime <= DateTime.Now
|
|
|
- // )
|
|
|
- // .Count();
|
|
|
-
|
|
|
- // // lần login này đc tính vào completed login
|
|
|
- // if (completedLogin >= missionLogin.RequiredTime - 1)
|
|
|
- // {
|
|
|
- // // save history for this login
|
|
|
- // var missionHistory = new MissionHistory
|
|
|
- // {
|
|
|
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "MISSION_HISTORY_SEQ"),
|
|
|
- // Msisdn = account.Msisdn,
|
|
|
- // MissionId = missionLogin.Id,
|
|
|
- // ExecutedTime = DateTime.Now,
|
|
|
- // Status = CommonConstant.StatusSuccess,
|
|
|
- // AccountId = account.Id
|
|
|
- // };
|
|
|
- // dbContext.MissionHistories.Add(missionHistory);
|
|
|
- // await dbContext.SaveChangesAsync();
|
|
|
-
|
|
|
- // // set completed mission
|
|
|
- // var completedMission = await QuestLogic.SetCompletedMissionForUserAsync(
|
|
|
- // dbContext,
|
|
|
- // account.Msisdn,
|
|
|
- // account.Id,
|
|
|
- // missionLogin
|
|
|
- // );
|
|
|
- // if (completedMission != CommonErrorCode.Success)
|
|
|
- // {
|
|
|
- // log.Error("Set completed mission error: " + completedMission);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // log.Debug("Set completed mission successfully");
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // // check time diff to save history
|
|
|
- // var startDay = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
|
|
|
- // var endDay = startDay.AddMinutes(int.Parse(timeDiff));
|
|
|
- // var loginHistory = dbContext
|
|
|
- // .MissionHistories.Where(
|
|
|
- // x =>
|
|
|
- // x.Msisdn == account.Msisdn
|
|
|
- // && x.AccountId == account.Id
|
|
|
- // && x.ExecutedTime >= startDay
|
|
|
- // && x.ExecutedTime <= endDay
|
|
|
- // && x.MissionId == missionLogin.Id
|
|
|
- // )
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (loginHistory == null)
|
|
|
- // {
|
|
|
- // // add history
|
|
|
- // var missionHistory = new MissionHistory
|
|
|
- // {
|
|
|
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "MISSION_HISTORY_SEQ"),
|
|
|
- // Msisdn = account.Msisdn,
|
|
|
- // MissionId = missionLogin.Id,
|
|
|
- // ExecutedTime = DateTime.Now,
|
|
|
- // Status = CommonConstant.StatusSuccess,
|
|
|
- // AccountId = account.Id
|
|
|
- // };
|
|
|
- // dbContext.MissionHistories.Add(missionHistory);
|
|
|
- // await dbContext.SaveChangesAsync();
|
|
|
-
|
|
|
- // // add prize for user
|
|
|
- // if (missionLogin.PrizeIdEachTime != null && missionLogin.PrizeIdEachTime > 0)
|
|
|
- // {
|
|
|
- // var addPrizeRes = await QuestLogic.AddPrizeForUser(
|
|
|
- // dbContext,
|
|
|
- // account.Msisdn,
|
|
|
- // missionLogin.Id,
|
|
|
- // missionLogin.PrizeIdEachTime
|
|
|
- // );
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // log.Debug($"User already login in {timeDiff}");
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // // check vendor package
|
|
|
- // var vendorPackage = dbContext
|
|
|
- // .VendorPackages.Where(
|
|
|
- // x =>
|
|
|
- // (x.Id == campaignOpening.VendorPackageId)
|
|
|
- // && x.Status == CommonConstant.StatusActive
|
|
|
- // )
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (vendorPackage == null)
|
|
|
- // {
|
|
|
- // log.Error("Not found vendor package");
|
|
|
- // canPlay = true;
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // vendorPackageId = vendorPackage.Id;
|
|
|
- // // check history
|
|
|
- // var vendorPackageHistory = dbContext
|
|
|
- // .VendorPackageHistories.Where(
|
|
|
- // x =>
|
|
|
- // x.Msisdn == account.Msisdn
|
|
|
- // && x.VendorPackageId == vendorPackage.Id
|
|
|
- // && x.Status == CommonConstant.StatusSuccess
|
|
|
- // // && x.CompletedTime >= startDay
|
|
|
- // // && x.CompletedTime <= endDay
|
|
|
- // )
|
|
|
- // .OrderByDescending(x => x.CompletedTime)
|
|
|
- // .FirstOrDefault();
|
|
|
-
|
|
|
- // bool canCheckRegister = false;
|
|
|
- // if (vendorPackageHistory != null)
|
|
|
- // {
|
|
|
- // // check if completed today
|
|
|
- // var endTime = vendorPackage.Period == "DAILY"
|
|
|
- // ? vendorPackageHistory.CompletedTime.AddDays(1)
|
|
|
- // : vendorPackage.Period == "WEEKLY"
|
|
|
- // ? vendorPackageHistory.CompletedTime.AddDays(7)
|
|
|
- // : vendorPackage.Period == "MONTHLY"
|
|
|
- // ? vendorPackageHistory.CompletedTime.AddMonths(1)
|
|
|
- // : vendorPackage.Period == "YEARLY"
|
|
|
- // ? vendorPackageHistory.CompletedTime.AddYears(1)
|
|
|
- // : vendorPackageHistory.CompletedTime;
|
|
|
-
|
|
|
- // if (DateTime.Now <= endTime)
|
|
|
- // {
|
|
|
- // log.Debug($"User {account.Msisdn} has completed vendor package {vendorPackage.Code} today");
|
|
|
- // canPlay = true;
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // canCheckRegister = true;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // canCheckRegister = true;
|
|
|
- // }
|
|
|
- // if (canCheckRegister)
|
|
|
- // {
|
|
|
- // // check user registered service
|
|
|
- // int checkRegistered = await QuestLogic.CheckRegisterServiceForUserAsync(dbContext, account.Msisdn, vendorPackage.Code);
|
|
|
- // if (checkRegistered == CommonConstant.UserRegistered)
|
|
|
- // {
|
|
|
- // log.Debug($"User {account.Msisdn} registered vendor package {vendorPackage.Code}");
|
|
|
- // canPlay = true;
|
|
|
- // // save vendor package history
|
|
|
- // var vendorPackageHistoryNew = new VendorPackageHistory
|
|
|
- // {
|
|
|
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "VENDOR_PACKAGE_HISTORY_SEQ"),
|
|
|
- // Msisdn = account.Msisdn,
|
|
|
- // VendorPackageId = vendorPackage.Id,
|
|
|
- // Status = CommonConstant.StatusSuccess,
|
|
|
- // CompletedTime = DateTime.Now,
|
|
|
- // AccountId = account.Id
|
|
|
- // };
|
|
|
- // dbContext.VendorPackageHistories.Add(vendorPackageHistoryNew);
|
|
|
- // await dbContext.SaveChangesAsync();
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // log.Debug($"User {account.Msisdn} not registered vendor package {vendorPackage.Code}");
|
|
|
- // canPlay = false;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Success,
|
|
|
- // canPlay ? ConfigManager.Instance.GetConfigWebValue("NEED_BUY_VENDOR") : "Success",
|
|
|
- // new
|
|
|
- // {
|
|
|
- // token,
|
|
|
- // refreshToken,
|
|
|
- // account = new
|
|
|
- // {
|
|
|
- // account.Msisdn,
|
|
|
- // account.Username,
|
|
|
- // account.Birthday
|
|
|
- // },
|
|
|
- // canPlay,
|
|
|
- // vendorPackageId
|
|
|
- // }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // catch (Exception exception)
|
|
|
- // {
|
|
|
- // log.Error("Exception: ", exception);
|
|
|
- // }
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("SYSTEM_FAILURE"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- //}
|
|
|
-
|
|
|
- //public async Task<IActionResult> UserInvite(HttpRequest httpRequest, UserInviteReq request)
|
|
|
- //{
|
|
|
- // var url = httpRequest.Path;
|
|
|
- // var json = JsonConvert.SerializeObject(request);
|
|
|
- // log.Debug("URL: " + url + " => Request: " + json);
|
|
|
- // try
|
|
|
- // {
|
|
|
- // var msisdn = CommonLogic.GetDataFromToken(configuration, httpRequest, "Msisdn");
|
|
|
- // var msisdnInvited = DotnetLib.Logic.ReuseLogic.TelemorValidateMsisdn(GetParameter("CountryCode"), request.receiver);
|
|
|
- // if (msisdnInvited == null)
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "Invalid msisdn",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // log.Debug("msisdn: " + msisdn);
|
|
|
- // log.Debug("msisdnInvited: " + msisdnInvited);
|
|
|
- // // check time inviting
|
|
|
- // var inviting = dbContext
|
|
|
- // .InvitingHistories.Where(x => x.Receiver == msisdnInvited)
|
|
|
- // .OrderByDescending(x => x.InvitedTime)
|
|
|
- // .ToList();
|
|
|
- // if (inviting.Count > 0)
|
|
|
- // {
|
|
|
- // if (inviting.Any(x => x.Status == CommonConstant.StatusClaimed))
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("INVITE_BEFORE"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // else if (inviting.Any(x => x.InvitedTime.AddHours(24) >= DateTime.Now))
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("INVITE_BEFORE"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // // this user is valid for inviting
|
|
|
- // var getInvitingHis = inviting.FindAll(
|
|
|
- // x => x.Msisdn == msisdn && x.Receiver == msisdnInvited
|
|
|
- // );
|
|
|
- // if (getInvitingHis.Count() > 0)
|
|
|
- // {
|
|
|
- // getInvitingHis[0].InvitedTime = DateTime.Now;
|
|
|
- // getInvitingHis[0].Status = CommonConstant.StatusSuccess;
|
|
|
-
|
|
|
- // dbContext.InvitingHistories.Update(getInvitingHis[0]);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // var invitingCreate = new InvitingHistory
|
|
|
- // {
|
|
|
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "INVITING_HISTORY_SEQ"),
|
|
|
- // Msisdn = msisdn!,
|
|
|
- // Receiver = msisdnInvited,
|
|
|
- // InvitedTime = DateTime.Now,
|
|
|
- // Status = CommonConstant.StatusSuccess,
|
|
|
- // AccountId = decimal.Parse(CommonLogic.GetDataFromToken(configuration, httpRequest, "AccountId")!)
|
|
|
- // };
|
|
|
- // dbContext.InvitingHistories.Add(invitingCreate);
|
|
|
-
|
|
|
- // // send mt to owner
|
|
|
- // await MtLogic.SendMt(
|
|
|
- // dbContext,
|
|
|
- // msisdnInvited,
|
|
|
- // ConfigManager.Instance.GetConfigSmsValue("PARTNER_INVITE_SUCCESS")
|
|
|
- // );
|
|
|
- // }
|
|
|
- // await dbContext.SaveChangesAsync();
|
|
|
-
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Success,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("INVITE_SUCCESS"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // catch (Exception exception)
|
|
|
- // {
|
|
|
- // log.Error("Exception: ", exception);
|
|
|
- // }
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("SYSTEM_FAILURE"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- //}
|
|
|
-
|
|
|
- //public async Task<IActionResult> VendorPackageRegister(
|
|
|
- // HttpRequest httpRequest,
|
|
|
- // VendorPackageRegisterReq request
|
|
|
- //)
|
|
|
- //{
|
|
|
- // var url = httpRequest.Path;
|
|
|
- // var json = JsonConvert.SerializeObject(request);
|
|
|
- // log.Debug("URL: " + url + " => Request: " + json);
|
|
|
- // try
|
|
|
- // {
|
|
|
- // var msisdn = CommonLogic.GetDataFromToken(configuration, httpRequest, "Msisdn");
|
|
|
-
|
|
|
- // if (msisdn == null)
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("MSISDN_INVALID"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // log.Debug("msisdn: " + msisdn);
|
|
|
- // // call soap to register
|
|
|
- // var webService = dbContext
|
|
|
- // .Webservices.Where(x => x.WsCode == "SUBSCRIBE")
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (webService == null)
|
|
|
- // {
|
|
|
- // log.Error("Not found webservice SUBSCRIBE");
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "Not found webservice SUBSCRIBE",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
-
|
|
|
- // // check vendor package
|
|
|
- // var vendorPackage = dbContext
|
|
|
- // .VendorPackages.Where(
|
|
|
- // x =>
|
|
|
- // x.Id == request.vendorPackageId
|
|
|
- // && x.Status == CommonConstant.StatusActive
|
|
|
- // )
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (vendorPackage == null)
|
|
|
- // {
|
|
|
- // log.Error("Not found vendor package");
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "Not found vendor package",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
-
|
|
|
- // // check payment channel
|
|
|
- // var paymentChannel = dbContext
|
|
|
- // .PaymentChannels.Where(
|
|
|
- // x =>
|
|
|
- // x.Id == request.paymentChannelId
|
|
|
- // && x.Status == CommonConstant.StatusActive
|
|
|
- // )
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (paymentChannel == null)
|
|
|
- // {
|
|
|
- // log.Error("Not found payment channel");
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "Not found payment channel",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
-
|
|
|
- // string transactionId = DotnetLib.Logic.ReuseLogic.GenerateUniqueNumber();
|
|
|
- // string body = webService
|
|
|
- // .MsgTemplate!.Replace("#MSISDN#", msisdn)
|
|
|
- // .Replace("#SERVICE_ID#", vendorPackage.Code)
|
|
|
- // .Replace("#PARAM#", "0")
|
|
|
- // .Replace("#TRANS_ID#", transactionId);
|
|
|
-
|
|
|
- // var (errorCode, envelope) = await QuestLogic.RegisterServiceForUserAsync(
|
|
|
- // dbContext,
|
|
|
- // webService.Wsdl!,
|
|
|
- // msisdn,
|
|
|
- // body,
|
|
|
- // vendorPackage.Code,
|
|
|
- // transactionId
|
|
|
- // );
|
|
|
-
|
|
|
- // if (errorCode != CommonErrorCode.Success || envelope == null)
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("REGISTER_FAILED"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // // Lấy danh sách gói:
|
|
|
- // var subscriberResponse = envelope.Body!.SubscriberResponse;
|
|
|
-
|
|
|
- // if (subscriberResponse != null && subscriberResponse.ResponseCode == "0")
|
|
|
- // {
|
|
|
- // log.Debug("Register vendor package successfully");
|
|
|
- // // save vendor package register to db
|
|
|
- // var vendorPackageHistory = new VendorPackageHistory
|
|
|
- // {
|
|
|
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "VENDOR_PACKAGE_HISTORY_SEQ"),
|
|
|
- // Msisdn = msisdn!,
|
|
|
- // VendorPackageId = vendorPackage.Id,
|
|
|
- // Status = CommonConstant.StatusSuccess,
|
|
|
- // CompletedTime = DateTime.Now,
|
|
|
- // AccountId = decimal.Parse(CommonLogic.GetDataFromToken(configuration, httpRequest, "AccountId")!)
|
|
|
- // };
|
|
|
-
|
|
|
- // // send mt
|
|
|
- // await MtLogic.SendMt(
|
|
|
- // dbContext,
|
|
|
- // msisdn!,
|
|
|
- // ConfigManager.Instance.GetConfigSmsValue("VENDOR_BUYING_SUCCESS").Replace("%MONEY%", vendorPackage.Price.ToString())
|
|
|
- // );
|
|
|
-
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Success,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("REGISTER_SUCCESS").Replace("%SERVICE%", vendorPackage.Code),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // log.Error("Register vendor package failed");
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("REGISTER_FAILED"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // }
|
|
|
- // catch (Exception exception)
|
|
|
- // {
|
|
|
- // log.Error("Exception: ", exception);
|
|
|
- // }
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("SYSTEM_FAILURE"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- //}
|
|
|
-
|
|
|
- //public async Task<IActionResult> LoadVendorPackage(HttpRequest httpRequest, LoadVendorPackageReq request)
|
|
|
- //{
|
|
|
- // var url = httpRequest.Path;
|
|
|
- // var json = JsonConvert.SerializeObject(request);
|
|
|
- // log.Debug("URL: " + url + " => Request: " + json);
|
|
|
- // try
|
|
|
- // {
|
|
|
- // // check if user completed vendor package
|
|
|
- // var campaignOpening = dbContext
|
|
|
- // .Campaigns.Where(
|
|
|
- // x =>
|
|
|
- // x.Status == CommonConstant.StatusActive
|
|
|
- // && x.FromTime <= DateTime.Now
|
|
|
- // && x.ToTime >= DateTime.Now
|
|
|
- // )
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (campaignOpening == null)
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "No active campaign",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // // load vendor package
|
|
|
- // var vendorPackage = dbContext
|
|
|
- // .VendorPackages
|
|
|
- // .Where(x => x.Status == CommonConstant.StatusActive && x.Id == campaignOpening.VendorPackageId)
|
|
|
- // .Select(x => new
|
|
|
- // {
|
|
|
- // x.Id,
|
|
|
- // x.Name,
|
|
|
- // x.Code,
|
|
|
- // x.Description,
|
|
|
- // x.Price,
|
|
|
- // x.Type,
|
|
|
- // x.Period,
|
|
|
- // x.MoneyType,
|
|
|
- // x.Introduction,
|
|
|
- // })
|
|
|
- // .FirstOrDefault();
|
|
|
- // if (vendorPackage == null)
|
|
|
- // {
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // "No vendor package found",
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Success,
|
|
|
- // "Load vendor package successfully",
|
|
|
- // new
|
|
|
- // {
|
|
|
- // vendorPackage
|
|
|
- // }
|
|
|
- // );
|
|
|
- // }
|
|
|
- // catch (Exception exception)
|
|
|
- // {
|
|
|
- // log.Error("Exception: ", exception);
|
|
|
- // }
|
|
|
- // return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
- // log,
|
|
|
- // url,
|
|
|
- // json,
|
|
|
- // CommonErrorCode.Error,
|
|
|
- // ConfigManager.Instance.GetConfigWebValue("SYSTEM_FAILURE"),
|
|
|
- // new { }
|
|
|
- // );
|
|
|
- //}
|
|
|
-
|
|
|
- #region Auth Methods - OTP Login
|
|
|
|
|
|
/// <summary>
|
|
|
/// Request OTP to be sent to email
|
|
|
@@ -828,7 +54,7 @@ namespace Esim.Apis.Business
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.RequiredFieldMissing,
|
|
|
- "Email is required",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("EMAIL_REQUIRED"),
|
|
|
new { }
|
|
|
);
|
|
|
}
|
|
|
@@ -841,12 +67,12 @@ namespace Esim.Apis.Business
|
|
|
.Where(c => c.Email == request.email)
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
- int? customerId = customer?.Id;
|
|
|
+ decimal? customerId = customer?.Id;
|
|
|
|
|
|
if (customer == null)
|
|
|
{
|
|
|
- // Create new customer record
|
|
|
- var newCustomerId = (int)await Database.DbLogic.GenIdAsync(dbContext, "CUSTOMER_INFO_SEQ");
|
|
|
+ // Create new customer record - manually get ID from Oracle sequence
|
|
|
+ var newCustomerId = await Database.DbLogic.GenIdAsync(dbContext, "CUSTOMER_INFO_SEQ");
|
|
|
var newCustomer = new CustomerInfo
|
|
|
{
|
|
|
Id = newCustomerId,
|
|
|
@@ -873,10 +99,10 @@ namespace Esim.Apis.Business
|
|
|
|
|
|
// Create new OTP record
|
|
|
int otpExpireMinutes = 5;
|
|
|
- var otpId = (int)await Database.DbLogic.GenIdAsync(dbContext, "OTP_VERIFICATION_SEQ");
|
|
|
+ //var otpId = (int)await Database.DbLogic.GenIdAsync(dbContext, "OTP_VERIFICATION_SEQ");
|
|
|
var otpVerification = new OtpVerification
|
|
|
{
|
|
|
- Id = otpId,
|
|
|
+ //Id = otpId,
|
|
|
CustomerId = customerId,
|
|
|
UserEmail = request.email,
|
|
|
OtpCode = otpCode,
|
|
|
@@ -890,33 +116,47 @@ namespace Esim.Apis.Business
|
|
|
dbContext.OtpVerifications.Add(otpVerification);
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
|
- // Add to MESSAGE_QUEUE for background email sending using template
|
|
|
- var messageId = (int)await Database.DbLogic.GenIdAsync(dbContext, "MESSAGE_QUEUE_SEQ");
|
|
|
-
|
|
|
- // Determine template code based on language
|
|
|
- // TemplateCode format: OTP_LOGIN (default Vietnamese), OTP_LOGIN_EN, OTP_LOGIN_LO
|
|
|
- string lang = (request.lang ?? "vi").ToLower();
|
|
|
- string templateCode = lang switch
|
|
|
- {
|
|
|
- "en" => "OTP_LOGIN_EN",
|
|
|
- "lo" => "OTP_LOGIN_LO",
|
|
|
- _ => "OTP_LOGIN" // Default Vietnamese
|
|
|
- };
|
|
|
+ // Add to MESSAGE_QUEUE for background email sending
|
|
|
+ // Resolve template content now so Worker only needs to send email
|
|
|
+ string lang = (request.lang ?? "lo").ToLower();
|
|
|
+ string templateCode = "OTP_LOGIN";
|
|
|
+
|
|
|
+ // Query template and get language-specific content
|
|
|
+ var template = dbContext.MessageTemplates
|
|
|
+ .FirstOrDefault(t => t.TemplateCode == templateCode && t.Status == true);
|
|
|
|
|
|
- // Prepare template data as JSON
|
|
|
- var templateData = System.Text.Json.JsonSerializer.Serialize(new
|
|
|
+ if (template == null)
|
|
|
{
|
|
|
- OTP_CODE = otpCode,
|
|
|
- EXPIRE_MINUTES = otpExpireMinutes.ToString()
|
|
|
- });
|
|
|
+ log.Error($"Template '{templateCode}' not found in MESSAGE_TEMPLATE");
|
|
|
+ throw new Exception($"Email template '{templateCode}' not found");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get subject based on language (fallback to default column if _LO/_EN is null)
|
|
|
+ string emailSubject = lang == "en"
|
|
|
+ ? (template.SubjectEn ?? template.Subject ?? "")
|
|
|
+ : (template.SubjectLo ?? template.Subject ?? "");
|
|
|
+
|
|
|
+ // Get content based on language (fallback to default column if _LO/_EN is null)
|
|
|
+ string emailContent = lang == "en"
|
|
|
+ ? (template.ContentEn ?? template.Content ?? "")
|
|
|
+ : (template.ContentLo ?? template.Content ?? "");
|
|
|
+
|
|
|
+ // Replace placeholders in content
|
|
|
+ emailContent = emailContent
|
|
|
+ .Replace("{{OTP_CODE}}", otpCode)
|
|
|
+ .Replace("{{EXPIRE_MINUTES}}", otpExpireMinutes.ToString());
|
|
|
+
|
|
|
+ // Replace placeholders in subject (if any)
|
|
|
+ emailSubject = emailSubject
|
|
|
+ .Replace("{{OTP_CODE}}", otpCode)
|
|
|
+ .Replace("{{EXPIRE_MINUTES}}", otpExpireMinutes.ToString());
|
|
|
|
|
|
var emailMessage = new MessageQueue
|
|
|
{
|
|
|
- Id = messageId,
|
|
|
MessageType = 1, // Email
|
|
|
Recipient = request.email,
|
|
|
- TemplateCode = templateCode, // Use template based on language
|
|
|
- TemplateData = templateData,
|
|
|
+ Subject = emailSubject, // Pre-resolved subject
|
|
|
+ Content = emailContent, // Pre-resolved content
|
|
|
Priority = true, // High priority
|
|
|
Status = 0, // Pending
|
|
|
ScheduledAt = DateTime.Now,
|
|
|
@@ -936,7 +176,7 @@ namespace Esim.Apis.Business
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.Success,
|
|
|
- "OTP sent successfully",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("OTP_SENT_SUCCESS"),
|
|
|
new
|
|
|
{
|
|
|
email = request.email,
|
|
|
@@ -970,16 +210,20 @@ namespace Esim.Apis.Business
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(request.email) || string.IsNullOrEmpty(request.otpCode))
|
|
|
{
|
|
|
+ string lang = (request.lang ?? "lo").ToLower();
|
|
|
return DotnetLib.Http.HttpResponse.BuildResponse(
|
|
|
log,
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.RequiredFieldMissing,
|
|
|
- "Email and OTP are required",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("EMAIL_OTP_REQUIRED", lang),
|
|
|
new { }
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ // Get language for response messages
|
|
|
+ string responseLang = (request.lang ?? "lo").ToLower();
|
|
|
+
|
|
|
// Find valid OTP
|
|
|
var otpRecord = dbContext.OtpVerifications
|
|
|
.Where(o => o.UserEmail == request.email
|
|
|
@@ -1005,7 +249,7 @@ namespace Esim.Apis.Business
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.OtpAlreadyUsed,
|
|
|
- "OTP has already been used",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("OTP_ALREADY_USED", responseLang),
|
|
|
new { }
|
|
|
);
|
|
|
}
|
|
|
@@ -1016,7 +260,7 @@ namespace Esim.Apis.Business
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.OtpExpired,
|
|
|
- "OTP has expired",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("OTP_EXPIRED", responseLang),
|
|
|
new { }
|
|
|
);
|
|
|
}
|
|
|
@@ -1027,7 +271,7 @@ namespace Esim.Apis.Business
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.OtpInvalid,
|
|
|
- "Invalid OTP",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("OTP_INVALID", responseLang),
|
|
|
new { }
|
|
|
);
|
|
|
}
|
|
|
@@ -1047,7 +291,7 @@ namespace Esim.Apis.Business
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.UserNotFound,
|
|
|
- "Customer not found",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("USER_NOT_FOUND", responseLang),
|
|
|
new { }
|
|
|
);
|
|
|
}
|
|
|
@@ -1081,7 +325,7 @@ namespace Esim.Apis.Business
|
|
|
var userToken = new UserToken
|
|
|
{
|
|
|
Id = tokenId,
|
|
|
- CustomerId = customer.Id.Value,
|
|
|
+ CustomerId = customer.Id,
|
|
|
AccessToken = accessToken,
|
|
|
RefreshToken = refreshToken,
|
|
|
TokenType = "Bearer",
|
|
|
@@ -1102,10 +346,10 @@ namespace Esim.Apis.Business
|
|
|
url,
|
|
|
json,
|
|
|
CommonErrorCode.Success,
|
|
|
- "Login successful",
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("LOGIN_SUCCESS", responseLang),
|
|
|
new
|
|
|
{
|
|
|
- userId = customer.Id.Value,
|
|
|
+ userId = customer.Id,
|
|
|
email = customer.Email ?? "",
|
|
|
fullName = $"{customer.SurName} {customer.LastName}".Trim(),
|
|
|
avatarUrl = customer.AvatarUrl,
|