protected void btnUnderwritingComplete_Click(object sender, EventArgs e) { MerchantModel editMerchant = new MerchantModel(); UnderwritingResultModel underwritingResult = new UnderwritingResultModel(); UnderwritingResultModel oldUnderwritingResult = new UnderwritingResultModel(); Int32 merchantRecordId; String adminId; try { merchantRecordId = Convert.ToInt32(hMerchantRecordId.Value); adminId = Context.User.Identity.GetUserId(); using (ApplicationDbContext ctx = new ApplicationDbContext()) { editMerchant = ctx.Merchants.First(m => m.RecordId == merchantRecordId); underwritingResult = ctx.UnderwritingResults.Where(ur => ur.Merchant.RecordId == merchantRecordId && ur.Active == true).First(); underwritingResult.CorpInfoResult = Convert.ToInt16(rblUWCorpInfoVerifiedResult.SelectedValue); underwritingResult.CorpInfoNotes = txtUWCorpInfoVerifiedNotes.Text; underwritingResult.BusLicStatusResult = Convert.ToInt16(rblUWBusLicStatusResult.SelectedValue); underwritingResult.BusLicStatusNotes = txtUWBUsLicStatusVerifiedNotes.Text; underwritingResult.EINResult = Convert.ToInt16(rblUWEINVerifiedResult.SelectedValue); underwritingResult.EINNotes = txtUWEINVerifiedNotes.Text; underwritingResult.PrincipalResult = Convert.ToInt16(rblUWPrincipalVerifiedResult.SelectedValue); underwritingResult.PrincipalNotes = txtUWPrincipalVerifiedNotes.Text; underwritingResult.CardSalesIndicatorResult = Convert.ToInt16(rblUWCardSalesIndicatorsVerifiedResult.SelectedValue); underwritingResult.CardSalesIndicatorNotes = txtUWCardSalesIndicatorsVerifiedNotes.Text; underwritingResult.BankingInfoResult = Convert.ToInt16(rblUWBankingInfoVerifiedResult.SelectedValue); underwritingResult.BankingInfoNotes = txtUWBankingInfoVerifiedNotes.Text; underwritingResult.MCCResult = Convert.ToInt16(rblUWMCCVerifiedResult.SelectedValue); underwritingResult.MCCNotes = txtUWMCCVerifiedNotes.Text; underwritingResult.BVIResult = Convert.ToInt16(rblUWBVIVerifiedResult.SelectedValue); underwritingResult.BVINotes = txtUWBVIVerifiedNotes.Text; underwritingResult.TaxLiensResult = Convert.ToInt16(rblUWTaxLiensVerifiedResult.SelectedValue); underwritingResult.TaxLiensNotes = txtUWTaxLiensVerifiedNotes.Text; underwritingResult.RiskIndicatorResult = Convert.ToInt16(rblUWRiskIndicatorVerifiedResult.SelectedValue); underwritingResult.RiskIndicatorNotes = txtUWRiskIndicatorVerifiedNotes.Text; underwritingResult.OFACMatchResult = Convert.ToInt16(rblUWOFACMatchVerifiedResult.SelectedValue); underwritingResult.OFACMatchNotes = txtUWOFACMatchVerifiedNotes.Text; if (underwritingResult.CorpInfoResult == 1 && underwritingResult.BusLicStatusResult == 1 && underwritingResult.EINResult == 1 && underwritingResult.PrincipalResult == 1 && underwritingResult.CardSalesIndicatorResult == 1 && underwritingResult.BankingInfoResult == 1 && underwritingResult.MCCResult == 1 && underwritingResult.BVIResult == 1 && underwritingResult.TaxLiensResult == 1 && underwritingResult.RiskIndicatorResult == 1 && underwritingResult.OFACMatchResult == 1 ) { underwritingResult.UnderwritingDecision = "Pass"; editMerchant.UnderwritingStatus = ctx.UnderwritingStatuses.First(us => us.StatusDescription == "Approved"); } else { underwritingResult.UnderwritingDecision = "Fail"; editMerchant.UnderwritingStatus = ctx.UnderwritingStatuses.First(us => us.StatusDescription == "Denied"); if (editMerchant.MerchantStatus.StatusDescription == "Enrolled") { editMerchant.MerchantStatus = ctx.MerchantStatuses.First(ms => ms.StatusDescription == "Denied"); editMerchant.DenialNotes = "Underwriting Decline. See Underwriting Results for more information."; editMerchant.DeniedBy = ctx.Users.First(u => u.Id == adminId); editMerchant.DeniedDate = DateTime.UtcNow; editMerchant.ApprovedAdvanceAmount = 0; editMerchant.AvailableAdvanceAmount = 0; //Send Email Logic.Messaging messaging = new Logic.Messaging(); Boolean emailSent = false; var template = messaging.GetTemplate("DeniedEnrollment"); if (template != null) { String html = messaging.GetTemplateHtml(template); foreach (EmailTemplateVariableModel variable in messaging.GetRequiredVariables(template)) { if (editMerchant.MerchantPrincipal != null && editMerchant.MerchantPrincipal.Contact != null) { if (variable.VariableName == "MERCHANT_FIRST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.FirstName); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.FirstName); } if (variable.VariableName == "MERCHANT_LAST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.LastName); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.LastName); } } else { if (variable.VariableName == "MERCHANT_FIRST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_LAST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } if (variable.VariableName == "MERCHANT_NAME") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.CorpName); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.CorpName); } if (editMerchant.Business.Address != null) { if (variable.VariableName == "MERCHANT_ADDRESS") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Address ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Address ?? ""); } if (variable.VariableName == "MERCHANT_CITY") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.City ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.City ?? ""); } if (variable.VariableName == "MERCHANT_ZIP") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Zip ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Zip ?? ""); } if (editMerchant.Business.Address.State != null) { if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.State.Name ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.State.Name ?? ""); } } else { if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } } else { if (variable.VariableName == "MERCHANT_ADDRESS") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_CITY") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_ZIP") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } if (variable.VariableName == "DENY_NOTES") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.DenialNotes); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.DenialNotes); } } if (ctx.Users.Any(u => u.Merchant.RecordId == editMerchant.RecordId)) { IQueryable<ApplicationUser> userList = ctx.Users.Where(u => u.Merchant.RecordId == editMerchant.RecordId); if (userList != null) { foreach (ApplicationUser thisUser in userList) { if (html != null) { emailSent = messaging.SendEmail(thisUser.Email, template.EmailSubject, html, template, editMerchant, thisUser); } } } } } } else { editMerchant.MerchantStatus = ctx.MerchantStatuses.First(ms => ms.StatusDescription == "Suspended"); MerchantSuspensionModel suspension = new MerchantSuspensionModel(); suspension.Merchant = ctx.Merchants.First(m => m.RecordId == editMerchant.RecordId); suspension.OtherReasonNotes = "Failed Underwriting. See Undewriting Results for more information."; suspension.SuspendedBy = ctx.Users.First(u => u.Id == adminId); suspension.SuspensionReason = ctx.MerchantSuspensionReasons.First(msr => msr.ReasonName == "Failed Underwriting Result"); suspension.Timestamp = DateTime.UtcNow; ctx.MerchantSuspensions.Add(suspension); //Send Email Logic.Messaging messaging = new Logic.Messaging(); Boolean emailSent = false; var template = messaging.GetTemplate("MerchantSuspended"); String suspendNotes = "Failed Underwriting. Contact Customer Service for more information."; if (template != null) { String html = messaging.GetTemplateHtml(template); foreach (EmailTemplateVariableModel variable in messaging.GetRequiredVariables(template)) { if (editMerchant.MerchantPrincipal != null && editMerchant.MerchantPrincipal.Contact != null) { if (variable.VariableName == "MERCHANT_FIRST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.FirstName); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.FirstName); } if (variable.VariableName == "MERCHANT_LAST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.LastName); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.MerchantPrincipal.Contact.LastName); } } else { if (variable.VariableName == "MERCHANT_FIRST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_LAST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } if (variable.VariableName == "MERCHANT_NAME") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.CorpName); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.CorpName); } if (editMerchant.Business.Address != null) { if (variable.VariableName == "MERCHANT_ADDRESS") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Address ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Address ?? ""); } if (variable.VariableName == "MERCHANT_CITY") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.City ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.City ?? ""); } if (variable.VariableName == "MERCHANT_ZIP") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Zip ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.Zip ?? ""); } if (editMerchant.Business.Address.State != null) { if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.State.Name ?? ""); html = html.Replace("<$" + variable.VariableName + ">", editMerchant.Business.Address.State.Name ?? ""); } } else { if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } } else { if (variable.VariableName == "MERCHANT_ADDRESS") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_CITY") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_ZIP") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } if (variable.VariableName == "SUSPEND_NOTES") { html = html.Replace("<$" + variable.VariableName + ">", suspendNotes); html = html.Replace("<$" + variable.VariableName + ">", suspendNotes); } } if (ctx.Users.Any(u => u.Merchant.RecordId == editMerchant.RecordId)) { IQueryable<ApplicationUser> userList = ctx.Users.Where(u => u.Merchant.RecordId == editMerchant.RecordId); if (userList != null) { foreach (ApplicationUser thisUser in userList) { if (html != null) { emailSent = messaging.SendEmail(thisUser.Email, template.EmailSubject, html, template, editMerchant, thisUser); } } } } } } ctx.SaveChanges(); } ctx.SaveChanges(); UpdateStatusLabel(); gridUnderwritingHistory.Rebind(); } pnlNewUnderwriting.Visible = false; pnlNewUnderwriting2.Visible = false; pnlUnderwritingHistory.Visible = true; pnlUnderwritingButtons.Visible = true; pnlUnderwritingAdvancedButtons.Visible = false; btnUnderwritingCancel.Visible = false; btnUnderwritingCancel2.Visible = false; btnUnderwritingTryAgain.Visible = false; btnUnderwritingComplete.Visible = false; btnUnderwritingSave.Visible = false; btnAddNewUnderwriting.Visible = true; btnUnderwritingContinue.Visible = false; } catch (System.Exception ex) { _newLogic.WriteExceptionToDB(ex, "btnUnderwritingComplete_Click"); } }
protected void btnSuspendMerchant_Click(object sender, EventArgs e) { try { using (ApplicationDbContext ctx = new ApplicationDbContext()) { int merchantId; Int32.TryParse(hMerchantRecordId.Value, out merchantId); string adminId = Context.User.Identity.GetUserId(); RadTextBox txtMerchantSuspensionNotes = (RadTextBox)StatusView.FindControl("txtMerchantSuspensionNotes"); if (ctx.Merchants.Any(m => m.RecordId == merchantId)) { MerchantModel merchant = ctx.Merchants.First(m => m.RecordId == merchantId); MerchantSuspensionModel suspension = new MerchantSuspensionModel(); Int32 reasonId = 0; Int32.TryParse(ddlSuspendReasons.SelectedValue, out reasonId); merchant.MerchantStatus = ctx.MerchantStatuses.First(ms => ms.StatusDescription == "Suspended"); suspension.Merchant = merchant; suspension.OtherReasonNotes = txtMerchantSuspensionNotes.Text; suspension.SuspendedBy = ctx.Users.First(u => u.Id == adminId); suspension.SuspensionReason = ctx.MerchantSuspensionReasons.First(msr => msr.RecordId == reasonId); suspension.Timestamp = DateTime.UtcNow; ctx.MerchantSuspensions.Add(suspension); ctx.SaveChanges(); StatusChangeModel statusChange = new StatusChangeModel { AdminUser = ctx.Users.First(u => u.Id == adminId), Merchant = merchant, MerchantStatus = merchant.MerchantStatus, UnderwritingStatus = merchant.UnderwritingStatus, Notes = suspension.SuspensionReason.ReasonName, Timestamp = DateTime.UtcNow }; ctx.StatusChanges.Add(statusChange); ctx.SaveChanges(); //Send Email Logic.Messaging messaging = new Logic.Messaging(); Boolean emailSent = false; var template = messaging.GetTemplate("MerchantSuspended"); String suspendNotes = ddlSuspendReasons.SelectedText + ": " + txtMerchantSuspensionNotes.Text; if (template != null) { String html = messaging.GetTemplateHtml(template); foreach (EmailTemplateVariableModel variable in messaging.GetRequiredVariables(template)) { if (merchant.MerchantPrincipal != null && merchant.MerchantPrincipal.Contact != null) { if (variable.VariableName == "MERCHANT_FIRST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", merchant.MerchantPrincipal.Contact.FirstName); html = html.Replace("<$" + variable.VariableName + ">", merchant.MerchantPrincipal.Contact.FirstName); } if (variable.VariableName == "MERCHANT_LAST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", merchant.MerchantPrincipal.Contact.LastName); html = html.Replace("<$" + variable.VariableName + ">", merchant.MerchantPrincipal.Contact.LastName); } } else { if (variable.VariableName == "MERCHANT_FIRST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_LAST_NAME") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } if (variable.VariableName == "MERCHANT_NAME") { html = html.Replace("<$" + variable.VariableName + ">", merchant.CorpName); html = html.Replace("<$" + variable.VariableName + ">", merchant.CorpName); } if (merchant.Business.Address != null) { if (variable.VariableName == "MERCHANT_ADDRESS") { html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.Address ?? ""); html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.Address ?? ""); } if (variable.VariableName == "MERCHANT_CITY") { html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.City ?? ""); html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.City ?? ""); } if (variable.VariableName == "MERCHANT_ZIP") { html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.Zip ?? ""); html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.Zip ?? ""); } if (merchant.Business.Address.State != null) { if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.State.Name ?? ""); html = html.Replace("<$" + variable.VariableName + ">", merchant.Business.Address.State.Name ?? ""); } } else { if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } } else { if (variable.VariableName == "MERCHANT_ADDRESS") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_CITY") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_STATE") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } if (variable.VariableName == "MERCHANT_ZIP") { html = html.Replace("<$" + variable.VariableName + ">", ""); html = html.Replace("<$" + variable.VariableName + ">", ""); } } if (variable.VariableName == "SUSPEND_NOTES") { html = html.Replace("<$" + variable.VariableName + ">", suspendNotes); html = html.Replace("<$" + variable.VariableName + ">", suspendNotes); } } if (ctx.Users.Any(u => u.Merchant.RecordId == merchant.RecordId)) { IQueryable<ApplicationUser> userList = ctx.Users.Where(u => u.Merchant.RecordId == merchant.RecordId); if (userList != null) { foreach (ApplicationUser thisUser in userList) { if (html != null) { emailSent = messaging.SendEmail(thisUser.Email, template.EmailSubject, html, template, merchant, thisUser); } } } } } } lblMerchantActionMessage.Text = "Merchant Suspended Successfully."; UpdateStatusLabel(); txtMerchantSuspensionNotes.Text = ""; ddlSuspendReasons.SelectedIndex = -1; } } catch (System.Exception ex) { lblMerchantActionMessage.Text = "Merchant was unable to be Suspeded. Please contact your system administrator for more information."; _newLogic.WriteExceptionToDB(ex, "btnSuspendMerchant_Click"); } }