Files
litecharmsshop/Shop/Components/Pages/Contact.razor.cs
T
khwezi 7fc448d525
continuous-integration/drone/pr Build is passing
Updated job scheduler
2026-05-10 18:23:09 +02:00

47 lines
1.4 KiB
C#

using LiteCharms.Abstractions;
using LiteCharms.Features.Email.Events;
using LiteCharms.Models;
using static LiteCharms.Abstractions.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);
}
}