Skip to content

Commit

Permalink
New - Envoi d'un email lorsqu'un producteur atteint 150€/mois de comm…
Browse files Browse the repository at this point in the history
…ande
  • Loading branch information
noelmugnier committed Nov 7, 2020
1 parent 4bc100f commit ed55db4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Sheaft.Core;
using System;
using Newtonsoft.Json;

namespace Sheaft.Application.Events
{
public class ProducerDeclarationRequiredEvent : Event
{
[JsonConstructor]
public ProducerDeclarationRequiredEvent(RequestUser requestUser) : base(requestUser)
{
}

public Guid ProducerId { get; set; }
}
}
2 changes: 2 additions & 0 deletions Sheaft.Application.Handlers/Commands/LegalCommandsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Sheaft.Domain.Enums;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Sheaft.Application.Events;

namespace Sheaft.Application.Handlers
{
Expand Down Expand Up @@ -263,6 +264,7 @@ public async Task<Result<bool>> Handle(CheckLegalsDeclarationRequiredCommand req
{
legal.SetDeclarationRequired(true);
await _context.SaveChangesAsync(token);
_mediatr.Post(new ProducerDeclarationRequiredEvent(request.RequestUser) { ProducerId = request.UserId });
}
return Ok(legal.DeclarationRequired);
Expand Down
15 changes: 14 additions & 1 deletion Sheaft.Application.Handlers/Events/ProducerEventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace Sheaft.Application.Handlers
public class ProducerEventsHandler : EventsHandler,
INotificationHandler<ProducerDeclarationNotValidatedEvent>,
INotificationHandler<ProducerDocumentsNotValidatedEvent>,
INotificationHandler<ProducerRegisteredEvent>
INotificationHandler<ProducerRegisteredEvent>,
INotificationHandler<ProducerDeclarationRequiredEvent>
{
public ProducerEventsHandler(
IAppDbContext context,
Expand Down Expand Up @@ -59,5 +60,17 @@ await _emailService.SendEmailAsync(
false,
token);
}

public async Task Handle(ProducerDeclarationRequiredEvent notification, CancellationToken token)
{
var producer = await _context.GetSingleAsync<Producer>(c => c.Id == notification.ProducerId, token);
await _emailService.SendEmailAsync(
"[email protected]",
"Support",
$"Un producteur vient de dépasser les 150€/mois de commandes",
$"Un producteur ({producer.Name}) vient de franchir la limite des 150€/mois sur la plateforme, contactez le par email ({producer.Email}) ou par téléphone ({producer.Phone}) pour valider avec lui les documents banquaires.",
false,
token);
}
}
}

0 comments on commit ed55db4

Please sign in to comment.