public async Task <ActionResult <SuccessResponse> > LostInfoEmail(EmailLostInfoSenderRequest model) { BaseResponse response = null; int sCode = 200; int userId = _authService.GetCurrentUserId(); string orgEmail = null; try { List <UserOrganization> userOrgs = _organizationService.GetForStolenInfo(userId, model.AccountNumber); if (userOrgs == null && !model.IsActive) { sCode = 404; response = new ErrorResponse("Payment account already deactivated"); } else if (userOrgs == null && model.IsActive) { _paymentAccountService.UpdateActiveStatus(userId, model.AccountNumber, model.PaymentTypeId); response = new SuccessResponse(); } else { foreach (var userOrg in userOrgs) { int indexOfSiteStart = userOrg.SiteUrl.IndexOf("w."); string orgSite = userOrg.SiteUrl.Substring(indexOfSiteStart + 2); //orgEmail = $"support@{orgSite}"; orgEmail = "*****@*****.**"; if (userOrg.PaymentAccountIsActive && model.IsActive && model.AccountNumber == userOrg.AccountNumber && model.PaymentTypeId == userOrg.PaymentTypeId) { _paymentAccountService.UpdateActiveStatus(userId, model.AccountNumber, model.PaymentTypeId); await _emailService.LostInfoEmail(model, orgEmail); response = new SuccessResponse(); } else { sCode = 404; response = new ErrorResponse("Payment account already deactivated or Not linked to organization"); }; } } } catch (Exception ex) { base.Logger.LogError(ex.ToString()); response = new ErrorResponse(ex.Message); sCode = 500; }; return(StatusCode(sCode, response)); }
public async Task LostInfoEmail(EmailLostInfoSenderRequest model, string toEmail) { string accountNumber = model.AccountNumber; string accountLastFour = null; if (model.AccountNumber.Length == 16) { accountLastFour = model.AccountNumber.Substring(12); } else if (model.AccountNumber.Length == 15) { accountLastFour = model.AccountNumber.Substring(11); } else if (model.AccountNumber.Length == 14) { accountLastFour = model.AccountNumber.Substring(10); } else if (model.AccountNumber.Length == 12) { accountLastFour = model.AccountNumber.Substring(8); } string templateLocation = "EmailTemplates\\LostInformation.html"; string currDir = Directory.GetCurrentDirectory(); string path = Path.Combine(currDir, templateLocation); string htmlContent = System.IO.File.ReadAllText(path); htmlContent = htmlContent.Replace("{@SenderFirstName}", model.SenderFirstName); htmlContent = htmlContent.Replace("{@SenderLastName}", model.SenderLastName); htmlContent = htmlContent.Replace("{@AccountLastFour}", accountLastFour); htmlContent = htmlContent.Replace("{@CardType}", model.CardType); htmlContent = htmlContent.Replace("{@PhoneNumber}", model.PhoneNumber); htmlContent = htmlContent.Replace("{@Email}", model.FromEmail); var msg = new SendGridMessage() { From = new EmailAddress(model.FromEmail, model.SenderFirstName), Subject = "Request for new information", HtmlContent = htmlContent }; msg.AddTo(new EmailAddress(toEmail)); await SendEmail(msg); }