47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using LiteCharms.Features.Email.Events;
|
|
using LiteCharms.Features.Email.Models;
|
|
using LiteCharms.Features.ServiceBus.Abstractions;
|
|
using static LiteCharms.Features.ServiceBus.Constants;
|
|
|
|
namespace Shop.Components.Pages;
|
|
|
|
public partial class Contact([FromKeyedServices(EmailServiceBus)] IEventBus emailBus, IToastService toastService) : IDisposable
|
|
{
|
|
public CancellationTokenSource TokenSource { get; set; } = new();
|
|
|
|
public EmailEnquiry Input { get; set; } = new();
|
|
|
|
public async Task SendEmailAsync()
|
|
{
|
|
try
|
|
{
|
|
var notification = SendShopEmailEnquiryEvent.Create(Input.FullName!, Input.EmailAddress!, Input.EmailSubject!, Input.Message!);
|
|
|
|
var result = await emailBus.PublishAsync(notification, TokenSource.Token);
|
|
|
|
if (result.IsFailed)
|
|
{
|
|
toastService.ShowSuccess("Failed to send email to the team, please try again, alternatively use the Discord / Slack button to contact us", "Lite Charms Team");
|
|
|
|
return;
|
|
}
|
|
|
|
toastService.ShowSuccess("Thank you, " + Input.FullName + ". We will get back to you shortly.", "Lite Charms Team");
|
|
|
|
Input = new EmailEnquiry();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
toastService.ShowSuccess(ex.Message, "Lite Charms Team");
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
TokenSource.Cancel();
|
|
TokenSource.Dispose();
|
|
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|