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

Commit

Permalink
refactor(back-end): Remove unused properties
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Feb 26, 2021
1 parent b33669d commit 5c8d7f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
29 changes: 14 additions & 15 deletions Kaizen/DomainEvents/Handlers/OnSavedPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Kaizen.Hubs;
using Kaizen.Middleware;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.SignalR;

namespace Kaizen.DomainEvents.Handlers
Expand All @@ -24,22 +22,20 @@ public class Handler : INotificationHandler<DomainEventNotification<SavedPerson>
private readonly IHubContext<ClientHub> _clientHub;
private readonly IMailTemplate _mailTemplate;
private readonly IStatisticsRepository _statisticsRepository;
private readonly IHttpContextAccessor _accessor;
private readonly LinkGenerator _generator;

public Handler(IMailService mailService, IHubContext<ClientHub> clientHub, IMailTemplate mailTemplate, IApplicationUserRepository applicationUserRepository,
IStatisticsRepository statisticsRepository, IHttpContextAccessor accessor, LinkGenerator generator)
public Handler(IMailService mailService, IHubContext<ClientHub> clientHub, IMailTemplate mailTemplate,
IApplicationUserRepository applicationUserRepository,
IStatisticsRepository statisticsRepository)
{
_mailService = mailService;
_clientHub = clientHub;
_mailTemplate = mailTemplate;
_statisticsRepository = statisticsRepository;
_accessor = accessor;
_generator = generator;
_applicationUserRepository = applicationUserRepository;
}

public async Task Handle(DomainEventNotification<SavedPerson> notification, CancellationToken cancellationToken)
public async Task Handle(DomainEventNotification<SavedPerson> notification,
CancellationToken cancellationToken)
{
Client savedClient = notification.DomainEvent.Client;

Expand All @@ -50,25 +46,28 @@ public async Task Handle(DomainEventNotification<SavedPerson> notification, Canc

private async Task SendConfirmationEmail(Client client)
{
string emailConfirmationToken = await _applicationUserRepository.GenerateEmailConfirmationTokenAsync(client.User);
string emailConfirmationToken =
await _applicationUserRepository.GenerateEmailConfirmationTokenAsync(client.User);
UriBuilder uriBuilder = new UriBuilder(KaizenHttpContext.BaseUrl)
{
Path = "user/ConfirmEmail",
Query = $"token={emailConfirmationToken.Base64ForUrlEncode()}&email={client.User.Email}"
};
string emailConfirmationLink = uriBuilder.ToString();

string emailMessage = _mailTemplate.LoadTemplate("NewClient.html", $"{client.FirstName} {client.LastName}",
$"{client.TradeName}", $"{client.ClientAddress.City}",
$"{client.ClientAddress.Neighborhood}", $"{client.ClientAddress.Street}",
$"{emailConfirmationLink}");
string emailMessage = _mailTemplate.LoadTemplate("NewClient.html",
$"{client.FirstName} {client.LastName}",
$"{client.TradeName}", $"{client.ClientAddress.City}",
$"{client.ClientAddress.Neighborhood}", $"{client.ClientAddress.Street}",
$"{emailConfirmationLink}");

await _mailService.SendEmailAsync(client.User.Email, "Cliente Registrado", emailMessage, true);
}

private async Task NotifyNewClientRegister(CancellationToken cancellationToken)
{
await _clientHub.Clients.Groups("Administrator", "OfficeEmployee").SendAsync("NewPersonRequest", cancellationToken: cancellationToken);
await _clientHub.Clients.Groups("Administrator", "OfficeEmployee")
.SendAsync("NewPersonRequest", cancellationToken: cancellationToken);
}

private async Task RegisterNewClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,25 @@
using Kaizen.Domain.Entities;
using Kaizen.Domain.Repositories;
using Kaizen.Middleware;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

namespace Kaizen.HostedServices.ProcessingServices
{
public class PendingActivitiesToConfirmed : IScopedProcessingService
{
private static readonly int DelayTime = (int)TimeSpan.FromDays(1.0).TotalMilliseconds;
private static readonly int DelayTime = (int) TimeSpan.FromDays(1.0).TotalMilliseconds;

private readonly IActivitiesRepository _activitiesRepository;
private readonly IMailService _mailService;
private readonly IMailTemplate _mailTemplate;
private readonly IHttpContextAccessor _accessor;
private readonly LinkGenerator _generator;

public PendingActivitiesToConfirmed(
IActivitiesRepository activitiesRepository,
IMailService mailService,
IMailTemplate mailTemplate,
IHttpContextAccessor accessor,
LinkGenerator generator)
IMailTemplate mailTemplate)
{
_activitiesRepository = activitiesRepository;
_mailService = mailService;
_mailTemplate = mailTemplate;
_accessor = accessor;
_generator = generator;
}

public async Task DoWork(CancellationToken cancellationToken)
Expand Down Expand Up @@ -60,11 +52,12 @@ private async Task SendPendingActivityEmail(Activity activity)
$"{activity.Client.FirstName} {activity.Client.SecondName} {activity.Client.LastName} {activity.Client.SecondLastName}",
$"{activity.Date}", activityConfirmationLink, activityRejectLink, changeDateLink);

await _mailService.SendEmailAsync(activity.Client.User.Email, "Actividad pendiente a confirmación", mailMessage,
await _mailService.SendEmailAsync(activity.Client.User.Email, "Actividad pendiente a confirmación",
mailMessage,
true);
}

private string GetActivityLink(string action, int activityCode)
private static string GetActivityLink(string action, int activityCode)
{
UriBuilder uriBuilder = new UriBuilder(KaizenHttpContext.BaseUrl)
{
Expand Down

0 comments on commit 5c8d7f5

Please sign in to comment.