diff --git a/Moonlight/App/Event/Events.cs b/Moonlight/App/Event/Events.cs index 3a7e16dd..ed42ae12 100644 --- a/Moonlight/App/Event/Events.cs +++ b/Moonlight/App/Event/Events.cs @@ -1,4 +1,5 @@ using Moonlight.App.Database.Entities; +using Moonlight.App.Database.Entities.Store; using Moonlight.App.Event.Args; namespace Moonlight.App.Event; @@ -9,4 +10,5 @@ public class Events public static EventHandler OnUserPasswordChanged; public static EventHandler OnUserTotpSet; public static EventHandler OnUserMailVerify; + public static EventHandler OnServiceOrdered; } \ No newline at end of file diff --git a/Moonlight/App/Services/Background/AutoMailSendService.cs b/Moonlight/App/Services/Background/AutoMailSendService.cs index e159855d..6548cd94 100644 --- a/Moonlight/App/Services/Background/AutoMailSendService.cs +++ b/Moonlight/App/Services/Background/AutoMailSendService.cs @@ -1,4 +1,5 @@ using Moonlight.App.Database.Entities; +using Moonlight.App.Database.Entities.Store; using Moonlight.App.Event; namespace Moonlight.App.Services.Background; @@ -12,12 +13,30 @@ public class AutoMailSendService // This service is responsible for sending mail { MailService = mailService; ConfigService = configService; - + Events.OnUserRegistered += OnUserRegistered; + Events.OnServiceOrdered += OnServiceOrdered; + } + + private async void OnServiceOrdered(object? _, Service service) + { + await MailService.Send( + service.Owner, + "New product ordered", + "serviceOrdered", + service, + service.Product, + service.Owner + ); } private async void OnUserRegistered(object? _, User user) { - await MailService.Send(user, $"Welcome {user.Username}", "welcome", user); + await MailService.Send( + user, + $"Welcome {user.Username}", + "welcome", + user + ); } } \ No newline at end of file diff --git a/Moonlight/App/Services/Store/StoreOrderService.cs b/Moonlight/App/Services/Store/StoreOrderService.cs index a222ee30..ab5924af 100644 --- a/Moonlight/App/Services/Store/StoreOrderService.cs +++ b/Moonlight/App/Services/Store/StoreOrderService.cs @@ -1,7 +1,9 @@ using Microsoft.EntityFrameworkCore; using Moonlight.App.Database.Entities; using Moonlight.App.Database.Entities.Store; +using Moonlight.App.Event; using Moonlight.App.Exceptions; +using Moonlight.App.Extensions; using Moonlight.App.Repositories; using Moonlight.App.Services.ServiceManage; @@ -138,8 +140,12 @@ public class StoreOrderService } // Create service - return await serviceService.Admin.Create(u, p, + var service = await serviceService.Admin.Create(u, p, service => { service.RenewAt = DateTime.UtcNow.AddDays(duration); }); + + await Events.OnServiceOrdered.InvokeAsync(service); + + return service; } public Task ValidateRenew(User u, Service s, int durationMultiplier) diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 6c263fb0..ba132670 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -19,7 +19,6 @@ -