Commit b68de4f1 authored by hasan khaddour's avatar hasan khaddour

add event handler for register and notifie cparticipant changes

parent a95bdaa3
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.Entities;
using PSManagement.SharedKernel.DomainEvents;
using PSManagement.SharedKernel.Interfaces;
using PSManagement.SharedKernel.Repositories;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.EventsHandlers
{
public class ChangeRegisterationOnParticipationChangedEventHandler : IDomainEventHandler<ParticipationChangedEvent>
{
private readonly IRepository<ParticipationChange> _repository;
private readonly IUnitOfWork _unitOfWork;
public ChangeRegisterationOnParticipationChangedEventHandler(IRepository<ParticipationChange> repository, IUnitOfWork unitOfWork)
{
_repository = repository;
_unitOfWork = unitOfWork;
}
public async Task Handle(ParticipationChangedEvent notification, CancellationToken cancellationToken)
{
await _repository
.AddAsync(
new ParticipationChange {
PartialTimeAfter= notification.PartialTimeRatioAfter ,
PartialTimeBefore= notification.PartialTimeRatioBefore ,
EmployeeId=notification.ParticipantId,
ProjectId=notification.ProjectId,
ChangeDate=notification.DateTime,
RoleAfter=notification.RoleAfter,
RoleBefore=notification.RoleBefore
});
await _unitOfWork.SaveChangesAsync();
}
}
}
using PSManagement.Application.Contracts.Email;
using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Employees.Repositories;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.SharedKernel.DomainEvents;
using PSManagement.SharedKernel.Specification;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.EventsHandlers
{
public class NotifieParticipantOnParticipationChangedEventHandler : IDomainEventHandler<ParticipationChangedEvent>
{
private readonly IEmailService _emailService;
private readonly IEmployeesRepository _employeeRepository;
private readonly BaseSpecification<Employee> _specification;
public NotifieParticipantOnParticipationChangedEventHandler(IEmailService emailService, IEmployeesRepository employeeRepository)
{
_emailService = emailService;
_employeeRepository = employeeRepository;
}
public async Task Handle(ParticipationChangedEvent notification, CancellationToken cancellationToken)
{
_specification.AddInclude(e => e.User);
Employee employee = await _employeeRepository.GetByIdAsync(notification.ParticipantId,_specification);
await _emailService.SendAsync(
employee.User.Email,
"Participation Change",
"Mr,"+employee.PersonalInfo.FirstName +"your particiaption changed to "+notification.RoleAfter + notification.PartialTimeRatioAfter
);
}
}
}
......@@ -3,7 +3,7 @@ using System;
namespace PSManagement.Domain.Projects.DomainEvents
{
public record ParticipationChanged(
public record ParticipationChangedEvent(
int ParticipantId,
int PartialTimeRatioBefore,
int PartialTimeRatioAfter,
......
......@@ -221,7 +221,7 @@ namespace PSManagement.Domain.Projects.Entities
public void ChangeParticipant(int participantId, int partialTimeRation, string role)
{
var participate = EmployeeParticipates.Where(e => e.EmployeeId == participantId).FirstOrDefault();
AddDomainEvent(new ParticipationChanged(
AddDomainEvent(new ParticipationChangedEvent(
participantId,
participate.PartialTimeRatio,partialTimeRation,
role,participate.Role, Id, DateTime.Now));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment