private async Task GeneralSettingValuesForJpos(string keyGroup) { var jposSettings = (await _generalSettingService.GetGeneratSettingValueByKeyGroup(keyGroup)).ToList(); if (jposSettings.Count > 0) { foreach (var item in jposSettings) { switch (item.KeyName) { case Constants.JPOSConstants.JPOS_Version: version = item.Value; break; case Constants.JPOSConstants.JPOS_ConsumerId: consumerId = item.Value; break; case Constants.JPOSConstants.JPOS_HostURL: url = item.Value; break; case Constants.JPOSConstants.JPOS_N: n = item.Value; break; default: break; } } } }
/// <summary> /// This method will return all the active connections as well as invitees of the user which exists in the system. /// </summary> /// <param name="userId"></param> /// <param name="programId"></param> /// <returns></returns> public async Task <List <BenefactorDto> > GetUserConnections(int userId, int programId) { using (var sqlConnection = await _databaseConnectionFactory.CreateConnectionAsync()) { try { var reloadSetting = (await _setting.GetGeneratSettingValueByKeyGroup(GeneralSettingsConstants.Reload)).FirstOrDefault().Value; object obj = new { UserId = userId, ProgramId = programId, Minutes = reloadSetting }; var result = (await sqlConnection.QueryAsync <BenefactorDto>(SQLQueryConstants.GetUserConnectionsQuery, obj)).ToList(); if (result.Count > 0) { for (int i = 0; i < result.Count; i++) { result[i].BenefactorImage = await _photos.GetAWSBucketFilUrl(result[i].BenefactorImage, string.Concat(_configuration["ServiceAPIURL"], ImagesDefault.UserDefaultImage)); } } List <BenefactorDto> asList = result.OrderByDescending(x => x.CreationDate).ToList(); return(asList); } catch (Exception) { throw; } finally { sqlConnection.Close(); sqlConnection.Dispose(); } } }
private async Task <FirebaseDynamicLinkResponseModel> SendShortLinkInMailRefactor(string webApiKey, FirebaseDynamicLinkResponseModel response, UserDto userObj, FirebaseDynamicLinkModel fbModel, HttpClient client) { HttpResponseMessage resp = client.PostAsJsonAsync("shortLinks?key=" + webApiKey, fbModel).Result; switch (resp.StatusCode) { case System.Net.HttpStatusCode.OK: response = resp.Content.ReadAsAsync <FirebaseDynamicLinkResponseModel>().Result; var emailSMSSettings = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.SMTPConstants.SMSEmail)).FirstOrDefault(); if (emailSMSSettings != null) { if (emailSMSSettings.Value == "1") { var template = await _emailService.GetEmailTemplateByName(EmailTemplates.MagicLink); template.Body = template.Body.Replace("{LogoImage}", string.Concat(_configuration["ServiceAPIURL"], "Images", "/email-logo.png").ToString()) .Replace("{Name}", string.Concat(userObj.FirstName, " ", userObj.LastName)) .Replace("{link}", response.shortLink).Replace("{UserCode}", userObj.UserCode); await _emailService.SendEmail(userObj.EmailAddress, template.Subject, template.Body, template.CCEmail, template.BCCEmail); } else { try { var smstemplate = await _sMSService.GetSMSTemplateByName(SMSTemplates.MagicLink); smstemplate.body = smstemplate.body.Replace("{Name}", string.Concat(userObj.FirstName, " ", userObj.LastName)).Replace("{link}", response.shortLink); await _sMSService.SendSMS(_configuration["accountSID"], _configuration["authToken"], userObj.PhoneNumber, smstemplate.body); } catch (Exception ex) { HttpContext.RiseError(new Exception(string.Concat("API := (ImportUser := SendShortLinkinMail)", ex.Message, " Stack Trace : ", ex.StackTrace, " Inner Exception : ", ex.InnerException))); } } } var userData = await _userRepository.GetDataByIdAsync(new { id = userObj.Id }); if (userData != null) { userData.InvitationStatus = 2; await _userRepository.AddUpdateUserInvitationStatus(userData); } break; default: break; } return(response); }
private async Task <List <Domain.Dto.UserDeviceDto> > NewRewardScheduleRefactorInside(List <Domain.Dto.RewardsOnDate> userRewards, Domain.Dto.ProgramInfoDto prg, List <Domain.Dto.UserDeviceDto> userDeviceIds) { if (userDeviceIds.Count > 0) { var serverApiKey = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.FireBaseConstants.FireBaseServerKey)).FirstOrDefault(); PushNotifications push = new PushNotifications(); var usrNotify = await _userNotificationSettingsService.GetUserNotificationSettingByNotificaction(userDeviceIds.Select(m => m.Id).ToList(), (int)NotificationSettingsEnum.Awards); if (usrNotify.Count > 0) { notificationMessage = MessagesConstants.NewRewardNotificationMessage; notificationTitle = MessagesConstants.NewRewardNotificationTitle; userDeviceIds = userDeviceIds.Where(x => usrNotify.Contains(x.Id)).ToList(); if (userDeviceIds.Count > 0) { await NewRewardScheduleRefactorInsideAgain(userRewards, prg, userDeviceIds, serverApiKey, push); } } } return(userDeviceIds); }
public async Task <bool> SendSMS(string sid, string authToken, string toPhone, string body) { try { var fromPhone = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.GeneralSettingsConstants.SMS)) .ToList().Where(x => x.KeyName == "FromPhone").Select(x => x.Value).FirstOrDefault(); TwilioClient.Init(sid, authToken); await MessageResource.CreateAsync(to : toPhone, from : fromPhone, body : body); return(true); } catch (Exception) { throw; } }
public async Task <EmailSMTP> GetSMTPHost() { try { var emailSettings = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.SMTPConstants.SMTP)).ToList(); EmailSMTP smtp = new EmailSMTP(); foreach (var item in emailSettings) { switch (item.KeyName) { case Constants.SMTPConstants.SMTP_Host: smtp.SMPTHost = item.Value; break; case Constants.SMTPConstants.SMTP_Port: smtp.SMTPPort = Convert.ToInt32(item.Value); break; case Constants.SMTPConstants.SMTP_UserName: smtp.SMTPUsername = item.Value; break; case Constants.SMTPConstants.SMTP_Password: smtp.SMTPPassword = item.Value; break; case Constants.SMTPConstants.SMTP_EnableSSL: smtp.SMTPEnableSSL = item.Value == "1" ? true : false; break; case Constants.SMTPConstants.EmailFrom: smtp.SMTPEmailFrom = item.Value; break; default: break; } } return(smtp); } catch (Exception) { throw; } }
public async Task <IActionResult> AddUserTransaction(FiservMainTransactionModel model) { try { if (!ModelState.IsValid) { return(Ok(new ApiBadRequestResponse(ModelState, MessagesConstants.BadRequest))); //400 } var userIdClaim = Convert.ToInt32(User.Claims.FirstOrDefault(x => x.Type.ToLower(CultureInfo.InvariantCulture).Trim() == "userId".ToLower(CultureInfo.InvariantCulture).Trim()).Value); if (model.ProgramAccountIdSelected > 0) { var planProgram = await _programAccount.GetUserProgramPlanNOrgByProgramAccountId(model.ProgramAccountIdSelected, model.CreditUserId); model.PlanId = planProgram?.planId; model.ProgramId = planProgram?.programId; model.OrganizationId = planProgram?.OrganizationId; model.AccountTypeId = planProgram?.AccountTypeId; model.OrganizationId = planProgram.OrganizationId; } var objUserTransaction = new UserTransactionInfo() { accountTypeId = 3, //accountTypeId = model.AccountTypeId, createdBy = userIdClaim, createdDate = DateTime.UtcNow, CreditTransactionUserType = TransactionUserEnityType.User, creditUserId = model.CreditUserId, debitUserId = userIdClaim, DebitTransactionUserType = TransactionUserEnityType.Benefactor, isActive = true, isDeleted = false, modifiedBy = userIdClaim, modifiedDate = DateTime.UtcNow, organisationId = model.OrganizationId, transactionAmount = model.approvedAmount.total, transactionDate = model.TransactionDateTime, TransactionId = model.ipgTransactionId, transactionStatus = 1, TransactionPaymentGateway = model.TransactionPaymentGateway, // programAccountId = model.ProgramAccountIdSelected, programAccountId = model.ProgramId.Value, programId = model.ProgramId.Value, planId = model.PlanId, }; var transactionUserAdd = await _userTransactionService.AddAsync(objUserTransaction); if (model.AccountTypeId == 3) { var userCardAccountBalance = await _i2cAccountDetail.FindAsync(new { UserId = model.CreditUserId }); if (userCardAccountBalance != null) {// That will work only for discretionary for i2c later userCardAccountBalance.Balance = userCardAccountBalance.Balance + objUserTransaction.transactionAmount; await _i2cAccountDetail.UpdateAsync(userCardAccountBalance, new { Id = userCardAccountBalance.Id }); } } var creditUserDetail = await _userRepository.FindAsync(new { Id = model.CreditUserId }); var debitUserDetail = await _userRepository.FindAsync(new { Id = userIdClaim }); /* Notification */ var balanceContent = string.Empty; if (model.AccountTypeId == 1) { balanceContent = string.Concat(objUserTransaction.transactionAmount, " meal passes"); } else if (model.AccountTypeId == 2) { balanceContent = string.Concat(objUserTransaction.transactionAmount, " flex points"); } else if (model.AccountTypeId == 3) { balanceContent = string.Concat("$", objUserTransaction.transactionAmount); } string notificationMessage = MessagesConstants.BalanceAddedNotificationMessage.Replace("{Benefactor}", string.Concat(debitUserDetail?.FirstName, " ", debitUserDetail?.LastName)).Replace("{Balance}", balanceContent), notificationTitle = MessagesConstants.BalanceAddedNotifyTitle; var programNotificationSetCheck = await _program.FindAsync(new { id = creditUserDetail?.ProgramId }); if (programNotificationSetCheck != null && programNotificationSetCheck.IsAllNotificationShow.Value) { var serverApiKey = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.FireBaseConstants.FireBaseServerKey)).FirstOrDefault(); PushNotifications push = new PushNotifications(); var usrNotify = await _userNotificationSettingsService.GetUserNotificationSettingByNotificaction(new List <int> { creditUserDetail.Id }, (int)NotificationSettingsEnum.Transaction); if (usrNotify.Count > 0) { await push.SendPushBulk(new List <string> { creditUserDetail?.UserDeviceId }, notificationTitle, notificationMessage, "", userIdClaim.ToString(), "transaction", "icon", "transaction", 1, (serverApiKey != null ? serverApiKey.Value : ""), false, "AddBalance", 0); } } await _userPushedNotificationService.AddAsync(new UserPushedNotifications() { notificationMessage = notificationMessage, notificationTitle = notificationTitle, notificationType = (int)NotificationSettingsEnum.Transaction, referenceId = 1, createdBy = userIdClaim, modifiedBy = userIdClaim, ProgramId = creditUserDetail?.ProgramId, userId = creditUserDetail.Id, IsRedirect = true, NotificationSubType = "AddBalance", CustomReferenceId = 0 }); return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, true, MessagesConstants.DataSuccessfullyReturned, transactionUserAdd))); } catch (Exception ex) { HttpContext.RiseError(new Exception(string.Concat("API := (UserTransactions := AddUserTransaction)", ex.Message, " Stack Trace : ", ex.StackTrace, " Inner Exception : ", ex.InnerException))); return(Ok(new ApiResponse(StatusCodes.Status200OK, false, MessagesConstants.SomeIssueInProcessing))); } }
public async Task <IActionResult> GetQRCode() { try { var userIdClaimForQRCode = Convert.ToInt32(User.Claims.FirstOrDefault(x => x.Type.ToLower(CultureInfo.InvariantCulture).Trim() == "userId".ToLower(CultureInfo.InvariantCulture).Trim()).Value); var sessionIdClaimForQRCode = User.Claims.FirstOrDefault(x => x.Type.ToLower(CultureInfo.InvariantCulture).Trim() == "sessionMobileId".ToLower(CultureInfo.InvariantCulture).Trim()).Value; var jposAccountIdForQRCode = User.Claims.FirstOrDefault(x => x.Type.ToLower(CultureInfo.InvariantCulture).Trim() == "jposAccountHolderId".ToLower(CultureInfo.InvariantCulture).Trim()).Value; /* Checks the session of the user against its Id. */ if (string.IsNullOrEmpty(await _userRepository.CheckSessionId(userIdClaimForQRCode, sessionIdClaimForQRCode))) { return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, false, MessagesConstants.NoSessionMatchExist, null, 0, "", true))); } using (var client = new HttpClient()) { var jposSettingsForQR = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.GeneralSettingsKeyGroup.JPOS_Version0)).ToList(); if (jposSettingsForQR.Count > 0) { foreach (var singleitem in jposSettingsForQR) { switch (singleitem.KeyName) { case Constants.JPOSConstants.JPOS_Version: version = singleitem.Value; break; case Constants.JPOSConstants.JPOS_ConsumerId: consumerId = singleitem.Value; break; case Constants.JPOSConstants.JPOS_HostURL: url = singleitem.Value; break; case Constants.JPOSConstants.JPOS_N: n = singleitem.Value; break; default: break; } } } if (!string.IsNullOrEmpty(consumerId) && !string.IsNullOrEmpty(url)) { client.DefaultRequestHeaders.Add("version", version); client.DefaultRequestHeaders.Add("consumer-id", consumerId); client.DefaultRequestHeaders.Add("nonce", n); var hostURLForQRCode = new Uri($"" + url + "wallets/" + jposAccountIdForQRCode + "/token"); var response = await client.GetAsync(hostURLForQRCode); string jsonForQRCode; using (var content = response.Content) { jsonForQRCode = await content.ReadAsStringAsync(); dynamic response1 = JsonConvert.DeserializeObject(jsonForQRCode.ToString()); return(Ok(new ApiResponse(StatusCodes.Status200OK, true, MessagesConstants.JPOSQRCodeCreatedSuccessfully, response1))); } } return(Ok(new ApiResponse(StatusCodes.Status200OK, false, MessagesConstants.JPOSQRCodeUnsuccessfulCreation, null))); } } catch (Exception ex) { HttpContext.RiseError(new Exception(string.Concat("API := (JPOS := GetQRCode)", ex.Message, " Stack Trace : ", ex.StackTrace, " Inner Exception : ", ex.InnerException))); return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, false, MessagesConstants.SomeIssueInProcessing))); } }