public async Task Handle(DomainEventNotification <UpdatedServiceRequest> notification,
                                 CancellationToken cancellationToken)
        {
            var serviceRequest = notification.DomainEvent.ServiceRequest;

            if (serviceRequest.State == ServiceRequestState.Pending)
            {
                return;
            }

            var client =
                await _clientsRepository.GetClientWithUser(serviceRequest.ClientId);

            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);
        }
    }
}
示例#2
0
        public async Task <ActionResult <ActivityViewModel> > PostActivity([FromBody] ActivityInputModel activityModel)
        {
            Client client = await _clientsRepository.GetClientWithUser(activityModel.ClientId);

            if (client is null)
            {
                return(NotFound($"El cliente con identificación {activityModel.ClientId} no se encuentra registrado."));
            }

            Activity activity = _mapper.Map <Activity>(activityModel);

            activity.Client = client;
            _activitiesRepository.Insert(activity);
            activity.PublishEvent(new SavedActivity(activity));

            await _unitWork.SaveAsync();

            return(_mapper.Map <ActivityViewModel>(activity));
        }
        public async Task Handle(DomainEventNotification <UpdatedServiceRequest> notification,
                                 CancellationToken cancellationToken)
        {
            var serviceRequest = notification.DomainEvent.ServiceRequest;

            if (serviceRequest.State == ServiceRequestState.Pending)
            {
                return;
            }

            var client =
                await _clientsRepository.GetClientWithUser(serviceRequest.ClientId);

            var clientNotification = await SaveServiceRequestNotification(serviceRequest, client.User);

            if (clientNotification is null)
            {
                return;
            }

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