SummerBestWebForm2/Components/Pages/Home.razor.cs

404 lines
14 KiB
C#
Raw Normal View History

2025-05-29 09:59:21 -04:00
using Microsoft.AspNetCore.Components;
2025-05-15 06:40:41 -04:00
using System.ComponentModel.DataAnnotations;
using Telerik.Blazor;
2025-05-29 09:59:21 -04:00
using Telerik.Blazor.Components;
2025-05-15 06:40:41 -04:00
using Telerik.SvgIcons;
2025-05-29 09:59:21 -04:00
using kmCommonLibsCore;
2025-05-29 13:33:02 -04:00
using System.Net.Http;
using System.Text.Json;
using Microsoft.Extensions.Options;
2025-05-29 14:04:36 -04:00
using SummerBestWebForm2.AppState;
2025-05-30 03:58:16 -04:00
using SummerBestWebForm2.ClassObj;
2025-05-15 06:40:41 -04:00
namespace SummerBestWebForm2.Components.Pages;
public partial class Home
{
2025-05-29 14:04:36 -04:00
[CascadingParameter]
2025-05-30 03:58:16 -04:00
public CascadingAppState appState { get; set; } = default!;
//[Inject] IPAddressService IpAddressService { get; set; } = default!;
2025-05-29 14:04:36 -04:00
2025-05-15 06:40:41 -04:00
async Task OnFinishHandler()
2025-05-22 06:09:57 -04:00
//private void SaveIt()
2025-05-15 06:40:41 -04:00
{
2025-05-29 13:33:02 -04:00
using (var em = new kmCommonLibsCore.Emails() { HandleOptOuts = false, SendMethod = enuSendMethod.OnsiteServer })
2025-05-15 06:40:41 -04:00
{
// Parsing the submitted form to pull the relevant information
2025-05-29 13:33:02 -04:00
var cardType = isPostcard ? "Postcard" : "Plastic Card";
var cardDesign = string.Empty;
2025-05-15 06:40:41 -04:00
if (designOne)
cardDesign = "A";
else if (designTwo)
cardDesign = "B";
else if (designThree)
cardDesign = "C";
2025-05-29 13:33:02 -04:00
else if (designCustom)
cardDesign = "CUSTOM";
2025-05-15 06:40:41 -04:00
// Postcard or Plastic specific options
2025-05-29 13:33:02 -04:00
var customizationInfo = string.Empty;
2025-05-15 06:40:41 -04:00
if (isPostcard)
{
2025-05-29 13:33:02 -04:00
var verseChoice = string.Empty;
var sigChoice = string.Empty;
2025-05-15 06:40:41 -04:00
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
2025-05-29 13:33:02 -04:00
customizationInfo = string.Format("<tr><td>Verse:</td><td>{0}</td></tr><tr><td>Signature:</td><td>{1}</td></tr>", verseChoice, sigChoice);
2025-05-15 06:40:41 -04:00
}
else // isPlasticCard
{
2025-05-29 13:33:02 -04:00
var smallOfferList = new List<string>();
var bigOfferList = new List<string>();
2025-05-15 06:40:41 -04:00
for (int index = 0; index < smallOffers.Length; index++)
{
if (smallOffers[index])
2025-05-29 13:33:02 -04:00
smallOfferList.Add(string.Format("B{0}", index));
2025-05-15 06:40:41 -04:00
}
for (int index = 0; index < bigOffers.Length; index++)
{
if (bigOffers[index])
2025-05-29 13:33:02 -04:00
bigOfferList.Add(string.Format("A{0}", index + 1));
2025-05-15 06:40:41 -04:00
}
2025-05-29 13:33:02 -04:00
customizationInfo = string.Format("<tr><td>BIG Offers:</td><td>{0}</td></tr><tr><td>SMALL Offers:</td><td>{1}</td></tr>",
string.Join(", ", bigOfferList), string.Join(", ", smallOfferList));
2025-05-15 06:40:41 -04:00
}
// Logo info
2025-05-29 13:33:02 -04:00
var logos = new List<string>();
if (goodyear)
logos.Add("Goodyear");
if (michelin)
logos.Add("Michelin");
if (custom)
logos.Add("Custom");
if (logos.Count == 0)
logos.Add("NONE");
2025-05-15 06:40:41 -04:00
// 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 = "SBC Order Form Submission";
em.AddAddress(enuAddressType.From, "support@keymotive.us", "Summer Growth Enrollment");
em.AddAddress(enuAddressType.To, "support@keymotive.us", "KeyMotive Support");
2025-05-29 13:33:02 -04:00
var targetAudience = string.Format("<tr><td>Audience:</td><td>{0}</td></tr>", string.IsNullOrWhiteSpace(audienceType) ? "NOTHING!" : audienceType);
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>",
2025-05-15 06:40:41 -04:00
locationInfo.LocationName, locationInfo.Manager, locationInfo.Address, locationInfo.City, locationInfo.State,
locationInfo.Zip, locationInfo.PhoneNumber, locationInfo.ContactName,
locationInfo.ContactPhone, locationInfo.ContactEmail);
2025-05-29 13:33:02 -04:00
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));
2025-05-15 06:40:41 -04:00
2025-05-29 13:33:02 -04:00
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);
2025-05-29 14:04:36 -04:00
var ipString = string.Format("<tr style='padding-top:20px'><td>IP Address</td><td>{0}</td></tr>",
string.IsNullOrWhiteSpace(appState.myIpAddress) ? "NONE" : appState.myIpAddress);
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;'>" +
targetAudience + locInfoString + cardInfoString + paymentString + ipString + "</table></div>";
2025-05-15 06:40:41 -04:00
try
{
em.Send();
await Console.Out.WriteLineAsync("Done sending");
}
catch (Exception e)
{
await Console.Out.WriteLineAsync("ERROR: " + e.Message);
}
ShowWizard = false;
2025-05-29 09:59:21 -04:00
await Dialogs.AlertAsync("The Registration was submitted successfully", "Done");
2025-05-15 06:40:41 -04:00
}
}
2025-05-29 09:59:21 -04:00
#region "User Selections - Model"
2025-05-29 13:33:02 -04:00
2025-05-22 06:09:57 -04:00
public bool? IsAudienceChoiceValid { get; set; } = false;
public bool? IsCardChoiceValid { get; set; } = false;
2025-05-15 06:40:41 -04:00
2025-05-22 06:09:57 -04:00
public bool? IsDesignChoiceValid { get; set; } = false;
2025-05-15 06:40:41 -04:00
[CascadingParameter]
2025-05-30 03:58:16 -04:00
public DialogFactory Dialogs { get; set; } = default!;
2025-05-15 06:40:41 -04:00
public bool ShowWizard { get; set; } = true;
2025-05-22 06:09:57 -04:00
public int Value { get; set; } = 0;
2025-05-15 06:40:41 -04:00
2025-05-22 06:09:57 -04:00
//public TelerikForm RegisterForm { get; set; }
2025-05-15 06:40:41 -04:00
public User UserModel { get; set; } = new User();
2025-05-22 06:09:57 -04:00
public TelerikForm IntroForm { get; set; } = new();
2025-05-15 06:40:41 -04:00
// Variables for selecting between plastic and post
public TelerikForm cardTypeForm { get; set; } = new();
public CardType cardType { get; set; } = new CardType();
2025-05-22 06:09:57 -04:00
public bool isPlasticCard { get; set; } = true;
public bool isPostcard { get; set; } = false;
public string audienceType { get; set; } = string.Empty;
public List<AudienceType> audiences { get; set; } = new List<AudienceType>
{
new AudienceType() {AudienceDescription="Send to my BEST CUSTOMERS"},
new AudienceType() {AudienceDescription="Send to Great Prospects as well as Customers who haven't been in during the past 8 months"}
};
2025-05-15 06:40:41 -04:00
// 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;
2025-05-29 09:59:21 -04:00
public bool designCustom = false;
2025-05-15 06:40:41 -04:00
// Variables for selecting messaging (postcards only)
public TelerikForm messagingForm { get; set; } = new();
public MessagingOptions messagingOptions { get; set; } = new MessagingOptions();
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 goodyear = false;
public bool michelin = false;
public bool custom = false;
public bool isLogoValid = false;
// Variables for offer selection (plastic cards only)
public TelerikForm offerForm { get; set; } = new();
public OfferOptions offerOptions { get; set; } = new OfferOptions();
public bool[] bigOffers = new bool[6];
public bool[] smallOffers = new bool[12];
public bool isOfferSelectionValid = false;
// Location information
public TelerikForm locationForm { get; set; } = new();
public LocationInfo locationInfo { get; set; } = new LocationInfo();
public string locationName { get; set; } = string.Empty;
public string manager { get; set; } = string.Empty;
public string address { get; set; } = string.Empty;
public string city { get; set; } = string.Empty;
public string state { get; set; } = string.Empty;
public string zip { get; set; } = string.Empty;
public string phoneNumber { get; set; } = string.Empty;
public string contactName { get; set; } = string.Empty;
public string contactPhone { get; set; } = string.Empty;
public string contactEmail { get; set; } = string.Empty;
public bool isLocationInfoValid { get; set; } = false;
// 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;
2025-05-29 09:59:21 -04:00
#endregion
2025-05-15 06:40:41 -04:00
public void ToggleCardType()
{
isPlasticCard = !isPlasticCard;
isPostcard = !isPostcard;
}
2025-05-22 06:09:57 -04:00
public void OnAudienceChoiceStepChange(WizardStepChangeEventArgs args)
{
IsAudienceChoiceValid = !string.IsNullOrWhiteSpace(audienceType);
}
2025-05-15 06:40:41 -04:00
public void OnCardChoiceStepChange(WizardStepChangeEventArgs args)
{
IsCardChoiceValid = true; // This is forced to be true but required nonetheless
2025-05-29 13:33:02 -04:00
2025-05-15 06:40:41 -04:00
}
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 OnOfferStepChange(WizardStepChangeEventArgs args)
{
if (isPostcard)
{
isOfferSelectionValid = true;
}
else
{
int bigOfferCount = 0;
foreach (bool selection in bigOffers)
{
if (selection)
bigOfferCount++;
}
int smallOfferCount = 0;
foreach (bool selection in smallOffers)
{
if (selection)
smallOfferCount++;
}
if (smallOfferCount == 4 && bigOfferCount == 2)
isOfferSelectionValid = true;
else
isOfferSelectionValid = false;
if (!isOfferSelectionValid)
{
args.IsCancelled = true;
2025-05-29 09:59:21 -04:00
await Dialogs.AlertAsync("Please select the proper amount of offers.", "You cannot proceed");
2025-05-15 06:40:41 -04:00
}
}
}
public async void OnLocationStepChange(WizardStepChangeEventArgs args)
{
isLocationInfoValid = !string.IsNullOrWhiteSpace(locationInfo.ContactEmail) &&
!string.IsNullOrWhiteSpace(locationInfo.ContactPhone) &&
!string.IsNullOrWhiteSpace(locationInfo.ContactName) &&
!string.IsNullOrWhiteSpace(locationInfo.City) &&
!string.IsNullOrWhiteSpace(locationInfo.State) &&
!string.IsNullOrWhiteSpace(locationInfo.Zip) &&
!string.IsNullOrWhiteSpace(locationInfo.PhoneNumber) &&
!string.IsNullOrWhiteSpace(locationInfo.LocationName) &&
!string.IsNullOrWhiteSpace(locationInfo.Address) &&
!string.IsNullOrWhiteSpace(locationInfo.Manager);
if (!isLocationInfoValid)
{
args.IsCancelled = true;
2025-05-29 09:59:21 -04:00
await Dialogs.AlertAsync("Please fill out all required fields.", "You cannot proceed");
2025-05-15 06:40:41 -04:00
}
}
2025-05-22 06:09:57 -04:00
#region "Models and Such"
2025-05-15 06:40:41 -04:00
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 OfferOptions
{
public string option { get; set; } = string.Empty;
}
public class LocationInfo
{
2025-05-29 13:33:02 -04:00
[Required, Display(Name = "Location Name")]
2025-05-15 06:40:41 -04:00
public string LocationName { get; set; } = string.Empty;
2025-05-29 10:50:22 -04:00
[Required, Display(Name = "Store Manager")]
2025-05-15 06:40:41 -04:00
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;
2025-05-29 10:50:22 -04:00
[Required, Display(Name = "Phone Number")]
2025-05-15 06:40:41 -04:00
public string PhoneNumber { get; set; } = string.Empty;
2025-05-29 10:50:22 -04:00
[Required, Display(Name = "Contact Name")]
2025-05-15 06:40:41 -04:00
public string ContactName { get; set; } = string.Empty;
2025-05-29 10:50:22 -04:00
[Required, Display(Name = "Contact Phone")]
2025-05-15 06:40:41 -04:00
public string ContactPhone { get; set; } = string.Empty;
2025-05-29 10:50:22 -04:00
[Required, Display(Name = "Your Email Address")]
2025-05-15 06:40:41 -04:00
public string ContactEmail { get; set; } = string.Empty;
}
public class PaymentInfo
{
public string info { get; set; } = string.Empty;
}
2025-05-22 06:09:57 -04:00
public class AudienceType
{
public string AudienceDescription { get; set; } = string.Empty;
}
#endregion
2025-05-15 06:40:41 -04:00
}