Skip to content
This repository was archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
feat(back-end): Send response email of a service request
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Apr 12, 2021
1 parent 09fd85c commit 36a6ada
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 2 deletions.
55 changes: 54 additions & 1 deletion Kaizen/DomainEvents/Handlers/OnUpdatedServiceRequest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using Kaizen.Core.Services;
using Kaizen.Domain.Entities;
using Kaizen.Domain.Events;
using Kaizen.Domain.Repositories;
using Kaizen.Hubs;
using Kaizen.Middleware;
using Kaizen.Models.Notification;
using MediatR;
using Microsoft.AspNetCore.SignalR;
Expand All @@ -20,15 +23,20 @@ public class Handler : INotificationHandler<DomainEventNotification<UpdatedServi
private readonly IClientsRepository _clientsRepository;
private readonly INotificationsRepository _notificationsRepository;
private readonly IUnitWork _unitWork;
private readonly IMailTemplate _mailTemplate;
private readonly IMailService _mailService;

public Handler(IHubContext<NotificationHub> notificationsHub, IClientsRepository clientsRepository,
INotificationsRepository notificationsRepository, IUnitWork unitWork, IMapper mapper)
INotificationsRepository notificationsRepository, IUnitWork unitWork, IMapper mapper,
IMailTemplate mailTemplate, IMailService mailService)
{
_notificationsHub = notificationsHub;
_clientsRepository = clientsRepository;
_notificationsRepository = notificationsRepository;
_unitWork = unitWork;
_mapper = mapper;
_mailTemplate = mailTemplate;
_mailService = mailService;
}

public async Task Handle(DomainEventNotification<UpdatedServiceRequest> notification,
Expand All @@ -50,6 +58,51 @@ public async Task Handle(DomainEventNotification<UpdatedServiceRequest> notifica
}

await SendServiceRequestNotification(clientNotification, client.User.Id, cancellationToken);
await SendServiceRequestResponseEmail(serviceRequest, client);
}

private async Task SendServiceRequestResponseEmail(ServiceRequest serviceRequest, Client client)
{
string responseMessage = serviceRequest.State switch
{
ServiceRequestState.Accepted =>
"Hemos aceptado tu solicitud de servicio y agendamos las actividades a aplicar.",
ServiceRequestState.Rejected => "Desafortunadamente hemos rechazado tu solicitud de servicio.",
ServiceRequestState.PendingSuggestedDate =>
"Te hemos sugerido una nueva fecha de aplicación de nuestros servicios.",
_ => "Tu solicitud aún está pendiente"
};

var responseUrl = new UriBuilder(KaizenHttpContext.BaseUrl)
{
Path = serviceRequest.State switch
{
ServiceRequestState.Accepted => "/activity_schedule/client_schedule",
ServiceRequestState.Rejected => "/service_requests/register",
ServiceRequestState.PendingSuggestedDate => "/service_requests/new_date",
_ => $"/service_requests/{serviceRequest.Code}"
}
};

var responseButtonMessage = serviceRequest.State switch
{
ServiceRequestState.Accepted => "Ver mi calendario de actividades",
ServiceRequestState.Rejected => "Intentar hacer otra solicitud",
ServiceRequestState.PendingSuggestedDate => "Ver fecha sugerida",
_ => "Ver solicitud"
};

string emailMessage = _mailTemplate.LoadTemplate("ServiceRequestResponse.html",
$"{client.FirstName} {client.LastName}",
responseMessage,
responseUrl.ToString(),
responseButtonMessage);

await _mailService.SendEmailAsync(
client.User.Email,
"Respuesta de solicitud de servicio",
emailMessage,
true);
}

private async Task<Notification> SaveServiceRequestNotification(ServiceRequest serviceRequest,
Expand Down
2 changes: 1 addition & 1 deletion Kaizen/EmailTemplates/NewActivity.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
margin-bottom: 17px;
"
>
Respuesta de solicitud de servicios
Actividad agendada
</h1>
<div
style="margin: 0 auto; align-items: center; width: 150px; height: 150px;"
Expand Down
130 changes: 130 additions & 0 deletions Kaizen/EmailTemplates/ServiceRequestResponse.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Respuesta de solicitud de servicio</title>
<style>
* {
margin: 0;
padding: 0;
font-family: "Roboto", Arial, Helvetica, sans-serif;
}

span {
max-width: 780px;
}
</style>
</head>
<body style="display: block; margin: 0; padding: 0;">
<div
style="
background-color: #0039ac;
height: 30px;
max-width: 800px;
display: block;
margin: 0 auto;
"
></div>
<h1
style="
text-align: center;
font-size: 30px;
font-family: 'Roboto', Arial, Helvetica, sans-serif;
margin-top: 17px;
margin-bottom: 17px;
"
>
Respuesta de solicitud de servicios
</h1>
<div
style="margin: 0 auto; align-items: center; width: 150px; height: 150px;"
>
<img
src="https://i.imgur.com/aVtcOk3.png"
alt="Logo ecolplag"
width="150"
height="150"
/>
</div>
<span
style="
font-size: 15px;
font-family: 'Roboto', Arial, Helvetica, sans-serif;
display: block;
padding: 15px 35px;
text-align: center;
margin: 7px auto 0;
"
>
Estimado {1}, hemos procesado tu solicitud de nuestros servicios.
</span>
<span
style="
font-size: 15px;
font-family: 'Roboto', Arial, Helvetica, sans-serif;
display: block;
margin: 0 auto;
padding: 10px 35px;
text-align: center;
">
{2}
</span>
<a
href="{3}"
style="
display: block;
margin: 0 auto;
text-align: center;
font-size: 20px;
text-decoration: none;
font-family: 'Roboto', Arial, Helvetica, sans-serif;
background-color: #0039ac;
min-width: 200px;
max-width: 210px;
border-radius: 7px;
color: white;
padding: 7px;
line-height: 25px;
margin-top: 5px;
margin-bottom: 7px;
"
target="blank"
>
{4}
</a>
<span
style="
font-size: 15px;
font-family: 'Roboto', Arial, Helvetica, sans-serif;
display: block;
margin: 0 auto;
padding: 15px 35px;
text-align: center;
"
>
<strong>
Agradecemos que nos escogieras.
</strong>
</span>
<span
style="
text-align: center;
display: block;
margin: 0 auto 7px;
"
>
<small>
<strong>&copy; Ecolplag S.A.S</strong>
</small>
</span>
<div
style="
background-color: #0039ac;
height: 30px;
max-width: 800px;
display: block;
margin: 1.5rem auto 0;
"
></div>
</body>
</html>

0 comments on commit 36a6ada

Please sign in to comment.