Files
WintersBestWebForm/Components/Pages/Home.razor.cs
T
2026-09-02 13:48:27 -04:00

414 lines
18 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using Telerik.Blazor;
using Telerik.Blazor.Components;
using Telerik.SvgIcons;
using kmCommonLibsCore;
using System.Net.Http;
using System.Text.Json;
using Microsoft.Extensions.Options;
using WinterBestCustomerWebForm.AppState;
using WinterBestCustomerWebForm.ClassObj;
namespace WinterBestCustomerWebForm.Components.Pages;
public partial class Home
{
[CascadingParameter]
public CascadingAppState appState { get; set; } = default!;
[Inject]
public IJSRuntime JS { get; set; } = default!;
public async Task OnWizardValueChanged(int newValue)
{
Value = newValue;
await JS.InvokeVoidAsync("resetWizardScroll");
}
async Task OnFinishHandler()
//private void SaveIt()
{
if (!int.TryParse(requestedQuantity, out int parsedQuantity) || parsedQuantity <= 0)
{
await Dialogs.AlertAsync("Please enter a valid Requested Quantity before submitting.", "You cannot proceed");
return;
}
using (var em = new kmCommonLibsCore.Emails() { HandleOptOuts = false, SendMethod = enuSendMethod.OnsiteServer })
{
// Parsing the submitted form to pull the relevant information
var cardType = isPostcard ? "Postcard" : "Greeting Card";
var cardDesign = string.Empty;
if (designOne)
cardDesign = isGreetingCard ? "A" : "E";
else if (designTwo)
cardDesign = isGreetingCard ? "B" : "F";
else if (designThree)
cardDesign = isGreetingCard ? "C" : "G";
else if (designFour)
cardDesign = isGreetingCard ? "D" : "H";
else if (designCustom)
cardDesign = "CUSTOM";
// Customizations
var greetingChoice = string.Empty;
var verseChoice = string.Empty;
var sigChoice = string.Empty;
if (greetingOne)
greetingChoice = "Happy Holidays";
else if (greetingTwo)
greetingChoice = "Merry Christmas";
else if (greetingThree)
greetingChoice = "Season's Greetings";
if (verseOne)
verseChoice = "1";
else if (verseTwo)
verseChoice = "2";
else if (verseThree)
verseChoice = "3";
if (sigOne)
sigChoice = string.Format("Option D - From Your Friends At:<br />{0}<br />{1}", locationInfo.LocationName, locationInfo.PhoneNumber);
else if (sigTwo)
sigChoice = string.Format("Option E - Name: {0}<br />Title: {1}<br />Phone: {2}", customName, customTitle, customPhone);
else if (sigThree)
sigChoice = string.Format("Option F - {0}", customSignature);
// combine these into customizationInfo
var customizationInfo = string.Format("<tr><td>Greeting:</td><td>{0}</td></tr><tr><td>Verse:</td><td>{1}</td></tr><tr><td>Signature:</td><td>{2}</td></tr>", greetingChoice, verseChoice, sigChoice);
// Logo info
var logos = new List<string>();
if (logoOnCard)
logos.Add("Logo on Card");
if (isGreetingCard && logoOnEnvelope)
logos.Add("Logo on Envelope");
if (logos.Count == 0)
logos.Add("NONE");
// Payment info
string paymentMethod = string.Empty;
if (ccOnFile)
paymentMethod = "Credit Card on File";
else if (callWithInfo)
paymentMethod = "Call With Payment Info";
else if (check)
paymentMethod = "Check";
// Formulating the email to send
em.Subject = "WBC Order Form Submission";
em.AddAddress(enuAddressType.From, "support@keymotive.us", "Winter Program Enrollment");
em.AddAddress(enuAddressType.To, "support@keymotive.net", "KeyMotive Support");
em.AddAddress(enuAddressType.To, "jondeck@keymotive.net", "Jon Deck");
em.AddAddress(enuAddressType.To, "amijat@keymotive.net", "Andrea Mijat");
var locInfoString = string.Format("<tr style='padding-top:14px'><td>Location Name:</td><td>{0}</td></tr>" +
"<tr><td>Manager:</td><td>{1}</td></tr>" +
"<tr><td>Address:</td><td>{2}</td></tr>" +
"<tr><td>City:</td><td>{3}</td></tr>" +
"<tr><td>State:</td><td>{4}</td></tr>" +
"<tr><td>Zip:</td><td>{5}</td></tr>" +
"<tr style='padding-top:14px'><td>Phone Number:</td><td>{6}</td></tr>" +
"<tr><td>Contact Name:</td><td>{7}</td></tr>" +
"<tr><td>Contact Phone:</td><td>{8}</td></tr>" +
"<tr><td>Contact Email:</td><td>{9}</td></tr>",
locationInfo.LocationName, locationInfo.Manager, locationInfo.Address, locationInfo.City, locationInfo.State,
locationInfo.Zip, locationInfo.PhoneNumber, locationInfo.ContactName,
locationInfo.ContactPhone, locationInfo.ContactEmail);
var cardInfoString = string.Format("<tr><td>Card type:</td><td>{0}, Design {1}</td></tr>" +
"<tr style='padding-top:14px'><td colspan='2'>Customization Options:</td></tr>" +
"{2}" +
"<tr><td>Logos:</td><td>{3}</td></tr>",
cardType, cardDesign, customizationInfo, string.Join(", ", logos));
if (int.TryParse(requestedQuantity, out _))
requestedQuantity = string.Format("{0:#,##0}", int.Parse(requestedQuantity));
var paymentString = string.Format("<tr><td>Payment Method:</td><td>{0}</td></tr>" +
"<tr style='padding-top:14px'><td>Requested Quantity:</td><td>{1}</td></tr>" +
"<tr><td>Additional Comments:</td><td>{2}</td></tr>", paymentMethod, requestedQuantity, additionalComments);
var ipString = string.Format("<tr style='padding-top:20px'><td>IP Address</td><td>{0}</td></tr>",
string.IsNullOrWhiteSpace(IpAddressService.RemoteIpAddress.ToString()) ? "NONE" : IpAddressService.RemoteIpAddress.ToString());
em.HtmlBody = "<div style='font-size:1.05em'><b>You have a new enrollment:</b><br /><br /><table style='font-size:1.05em;display:block;font-family: monospace;'>" +
locInfoString + cardInfoString + paymentString + ipString + "</table></div>";
try
{
em.Send();
await Console.Out.WriteLineAsync("Done sending");
}
catch (Exception e)
{
await Console.Out.WriteLineAsync("ERROR: " + e.Message);
}
ShowWizard = false;
await Dialogs.AlertAsync("The Registration was submitted successfully", "Done");
}
}
#region "User Selections - Model"
public bool? IsAudienceChoiceValid { get; set; } = true;
public bool? IsCardChoiceValid { get; set; } = false;
public bool? IsDesignChoiceValid { get; set; } = false;
[CascadingParameter]
public DialogFactory Dialogs { get; set; } = default!;
public bool ProgramClosed { get; set; } = false;
public bool ShowWizard { get; set; } = true;
public int Value { get; set; } = 0;
//public TelerikForm RegisterForm { get; set; }
public User UserModel { get; set; } = new User();
public TelerikForm IntroForm { get; set; } = new();
// Variables for selecting between plastic and post
public TelerikForm cardTypeForm { get; set; } = new();
public CardType cardType { get; set; } = new CardType();
public bool isGreetingCard { get; set; } = true;
public bool isPostcard { get; set; } = false;
// Variables for selecting specific design
public TelerikForm customizationForm { get; set; } = new();
public CustomizationOptions custOptions { get; set; } = new CustomizationOptions();
public bool designOne = true;
public bool designTwo = false;
public bool designThree = false;
public bool designFour = false;
public bool designCustom = false;
// Variables for selecting messaging (postcards only)
public TelerikForm messagingForm { get; set; } = new();
public MessagingOptions messagingOptions { get; set; } = new MessagingOptions();
public bool greetingOne = true;
public bool greetingTwo = false;
public bool greetingThree = false;
public bool verseOne = true;
public bool verseTwo = false;
public bool verseThree = false;
public bool sigOne = true;
public bool sigTwo = false;
public bool sigThree = false;
public string customName = string.Empty; // For sig two
public string customTitle = string.Empty;
public string customPhone = string.Empty;
public string customSignature = string.Empty; // For sig three
public bool isMessagingValid = false;
// Variables for logo selection
public TelerikForm logoForm { get; set; } = new();
public LogoOptions logoOptions { get; set; } = new LogoOptions();
public bool logoOnCard = true;
public bool logoOnEnvelope = true;
public bool isLogoValid = true;
// Location information
public TelerikForm locationForm { get; set; } = new();
public LocationInfo locationInfo { get; set; } = new LocationInfo();
public bool isLocationInfoValid { get; set; } = false;
public static readonly List<string> UsStates = new()
{
"AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA",
"ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR",
"PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"
};
// Payment information
public TelerikForm paymentForm { get; set; } = new();
public PaymentInfo paymentInfo { get; set; } = new PaymentInfo();
public string requestedQuantity = string.Empty;
public string additionalComments = string.Empty;
public bool ccOnFile = true;
public bool callWithInfo = false;
public bool check = false;
#endregion
public void ToggleCardType()
{
isGreetingCard = !isGreetingCard;
isPostcard = !isPostcard;
}
public void OnCardChoiceStepChange(WizardStepChangeEventArgs args)
{
IsCardChoiceValid = true; // This is forced to be true but required nonetheless
}
public void OnDesignStepChange(WizardStepChangeEventArgs args)
{
IsDesignChoiceValid = true; // Same as card choice
}
public void OnMessagingStepChange(WizardStepChangeEventArgs args)
{
isMessagingValid = true;
}
public void OnLogoStepChange(WizardStepChangeEventArgs arg)
{
isLogoValid = true;
}
public async void OnLocationStepChange(WizardStepChangeEventArgs args)
{
var missingFields = new List<string>();
if (string.IsNullOrWhiteSpace(locationInfo.LocationName)) missingFields.Add("Location Name");
if (string.IsNullOrWhiteSpace(locationInfo.Manager)) missingFields.Add("Store Manager");
if (string.IsNullOrWhiteSpace(locationInfo.Address)) missingFields.Add("Address");
if (string.IsNullOrWhiteSpace(locationInfo.City)) missingFields.Add("City");
if (string.IsNullOrWhiteSpace(locationInfo.State)) missingFields.Add("State");
if (string.IsNullOrWhiteSpace(locationInfo.Zip)) missingFields.Add("Zip");
if (string.IsNullOrWhiteSpace(locationInfo.PhoneNumber)) missingFields.Add("Phone Number");
if (string.IsNullOrWhiteSpace(locationInfo.ContactName)) missingFields.Add("Contact Name");
if (string.IsNullOrWhiteSpace(locationInfo.ContactPhone)) missingFields.Add("Contact Phone");
if (string.IsNullOrWhiteSpace(locationInfo.ContactEmail)) missingFields.Add("Your Email Address");
var formatErrors = new List<string>();
if (!string.IsNullOrWhiteSpace(locationInfo.Zip) && !Regex.IsMatch(locationInfo.Zip, @"^\d{5}(-\d{4})?$"))
formatErrors.Add("Zip must be a valid 5-digit ZIP code.");
if (!string.IsNullOrWhiteSpace(locationInfo.ContactEmail) && !Regex.IsMatch(locationInfo.ContactEmail, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
formatErrors.Add("Your Email Address doesn't look like a valid email.");
if (!string.IsNullOrWhiteSpace(locationInfo.PhoneNumber) && Regex.Replace(locationInfo.PhoneNumber, @"\D", "").Length < 10)
formatErrors.Add("Phone Number should include an area code (10 digits).");
if (!string.IsNullOrWhiteSpace(locationInfo.ContactPhone) && Regex.Replace(locationInfo.ContactPhone, @"\D", "").Length < 10)
formatErrors.Add("Contact Phone should include an area code (10 digits).");
isLocationInfoValid = missingFields.Count == 0 && formatErrors.Count == 0;
if (!isLocationInfoValid)
{
args.IsCancelled = true;
var messageParts = new List<string>();
if (missingFields.Count > 0)
messageParts.Add("Please fill out: " + string.Join(", ", missingFields) + ".");
messageParts.AddRange(formatErrors);
await Dialogs.AlertAsync(string.Join("\n", messageParts), "You cannot proceed");
}
}
#region "Order Review Summary (Payment step)"
public string SummaryCardType => isPostcard ? "Postcard" : "Greeting Card";
public string SummaryDesign
{
get
{
if (designCustom) return "Custom design (our team will follow up with you)";
var number = designOne ? "1" : designTwo ? "2" : designThree ? "3" : designFour ? "4" : "-";
return $"{SummaryCardType} - Design {number}";
}
}
public string SummaryGreeting =>
greetingOne ? "Happy Holidays" :
greetingTwo ? "Merry Christmas" :
greetingThree ? "Season's Greetings" : "-";
public string SummaryVerse =>
verseOne ? "\"Your support means so much to us. Thank you for choosing our team to keep you on the road. Wishing you a wonderful holiday season and a happy New Year!\"" :
verseTwo ? "\"Warmest wishes this holiday season from all of us! Thank you for your continued trust and support. May 2027 bring you happiness, good health, and many safe miles ahead.\"" :
verseThree ? "\"Its been our pleasure serving you throughout the year. Were grateful for your business and look forward to seeing you in 2027. Merry Christmas and Happy New Year!\"" : "";
public string SummarySignature
{
get
{
if (sigOne) return "From Your Friends";
if (sigTwo)
{
var parts = new List<string>();
if (!string.IsNullOrWhiteSpace(customName)) parts.Add(customName);
if (!string.IsNullOrWhiteSpace(customTitle)) parts.Add(customTitle);
if (!string.IsNullOrWhiteSpace(customPhone)) parts.Add(customPhone);
return parts.Count > 0 ? string.Join(", ", parts) : "Name, Title, Phone Number (not yet entered)";
}
if (sigThree) return string.IsNullOrWhiteSpace(customSignature) ? "Custom message (not yet entered)" : customSignature;
return "-";
}
}
public string SummaryLogos
{
get
{
var items = new List<string>();
if (logoOnCard) items.Add("On Card");
if (isGreetingCard && logoOnEnvelope) items.Add("On Envelope");
return items.Count == 0 ? "None" : string.Join(", ", items);
}
}
#endregion
#region "Models and Such"
public class CardType
{
[Required]
public string cardChoice { get; set; } = string.Empty;
}
public class CustomizationOptions
{
[Required]
public string custOption { get; set; } = string.Empty;
}
public class MessagingOptions
{
public string verse { get; set; } = string.Empty;
public string signature { get; set; } = string.Empty;
}
public class LogoOptions
{
public string option { get; set; } = string.Empty;
}
public class LocationInfo
{
[Required, Display(Name = "Location Name")]
public string LocationName { get; set; } = string.Empty;
[Required, Display(Name = "Store Manager")]
public string Manager { get; set; } = string.Empty;
[Required]
public string Address { get; set; } = string.Empty;
[Required]
public string City { get; set; } = string.Empty;
[Required]
public string State { get; set; } = string.Empty;
[Required]
public string Zip { get; set; } = string.Empty;
[Required, Display(Name = "Phone Number")]
public string PhoneNumber { get; set; } = string.Empty;
[Required, Display(Name = "Contact Name")]
public string ContactName { get; set; } = string.Empty;
[Required, Display(Name = "Contact Phone")]
public string ContactPhone { get; set; } = string.Empty;
[Required, Display(Name = "Your Email Address")]
public string ContactEmail { get; set; } = string.Empty;
}
public class PaymentInfo
{
public string info { get; set; } = string.Empty;
}
#endregion
}