Commit 48a31497 authored by hasan khaddour's avatar hasan khaddour

fix hours work issue

parent eee081ba
...@@ -6,6 +6,7 @@ using PSManagement.Domain.Projects.DomainEvents; ...@@ -6,6 +6,7 @@ using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.Entities; using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories; using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.DomainEvents; using PSManagement.SharedKernel.DomainEvents;
using PSManagement.SharedKernel.Interfaces;
using PSManagement.SharedKernel.Specification; using PSManagement.SharedKernel.Specification;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -21,6 +22,7 @@ namespace PSManagement.Application.Projects.EventsHandlers ...@@ -21,6 +22,7 @@ namespace PSManagement.Application.Projects.EventsHandlers
private readonly IEmailService _emailService; private readonly IEmailService _emailService;
private readonly IEmployeesRepository _employeesRepository; private readonly IEmployeesRepository _employeesRepository;
private readonly IProjectsRepository _projectsRepository; private readonly IProjectsRepository _projectsRepository;
private readonly IUnitOfWork _unitofwork;
private readonly BaseSpecification<Employee> _specification; private readonly BaseSpecification<Employee> _specification;
public ParticipantAddedEventHandler( public ParticipantAddedEventHandler(
IEmployeesRepository employeesRepository, IEmployeesRepository employeesRepository,
...@@ -40,6 +42,8 @@ namespace PSManagement.Application.Projects.EventsHandlers ...@@ -40,6 +42,8 @@ namespace PSManagement.Application.Projects.EventsHandlers
Employee employee = await _employeesRepository.GetByIdAsync(notification.EmployeeId, _specification); Employee employee = await _employeesRepository.GetByIdAsync(notification.EmployeeId, _specification);
Project project = await _projectsRepository.GetByIdAsync(notification.ProjectId); Project project = await _projectsRepository.GetByIdAsync(notification.ProjectId);
employee.IncreaseWorkHours(notification.PartialTimeRatio);
await _emailService await _emailService
.SendAsync( .SendAsync(
employee.User.Email, employee.User.Email,
......
...@@ -35,7 +35,7 @@ namespace PSManagement.Application.Projects.EventsHandlers ...@@ -35,7 +35,7 @@ namespace PSManagement.Application.Projects.EventsHandlers
Employee employee = await _employeesRepository.GetByIdAsync(notification.EmployeeId ,_specification); Employee employee = await _employeesRepository.GetByIdAsync(notification.EmployeeId ,_specification);
Project project = await _projectsRepository.GetByIdAsync(notification.ProjectId); Project project = await _projectsRepository.GetByIdAsync(notification.ProjectId);
await _emailService await _emailService
.SendAsync( .SendAsync(
employee.User.Email, employee.User.Email,
......
...@@ -17,6 +17,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManag ...@@ -17,6 +17,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManag
private readonly IProjectsRepository _projectsRepository; private readonly IProjectsRepository _projectsRepository;
private readonly BaseSpecification<Project> _specification; private readonly BaseSpecification<Project> _specification;
private readonly IUnitOfWork _unitOfWork; private readonly IUnitOfWork _unitOfWork;
private readonly IEmployeesRepository _employeesRepository;
public ChangeEmployeeParticipationCommandHandler( public ChangeEmployeeParticipationCommandHandler(
IProjectsRepository projectsRepository, IProjectsRepository projectsRepository,
...@@ -32,6 +34,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManag ...@@ -32,6 +34,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManag
public async Task<Result> Handle(ChangeEmployeeParticipationCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(ChangeEmployeeParticipationCommand request, CancellationToken cancellationToken)
{ {
_specification.AddInclude(e => e.EmployeeParticipates); _specification.AddInclude(e => e.EmployeeParticipates);
_specification.AddInclude("EmployeeParticipates.Employee");
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId,_specification); Project project = await _projectsRepository.GetByIdAsync(request.ProjectId,_specification);
...@@ -47,6 +50,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManag ...@@ -47,6 +50,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManag
} }
project.ChangeParticipant(request.ParticipantId,request.PartialTimeRation,request.Role); project.ChangeParticipant(request.ParticipantId,request.PartialTimeRation,request.Role);
......
...@@ -35,6 +35,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant ...@@ -35,6 +35,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant
public async Task<Result> Handle(RemoveParticipantCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(RemoveParticipantCommand request, CancellationToken cancellationToken)
{ {
_specification.AddInclude(e => e.EmployeeParticipates); _specification.AddInclude(e => e.EmployeeParticipates);
_specification.AddInclude("EmployeeParticipates.Employee");
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId,_specification); Project project = await _projectsRepository.GetByIdAsync(request.ProjectId,_specification);
if (project is null) if (project is null)
...@@ -55,8 +57,10 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant ...@@ -55,8 +57,10 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant
return Result.Invalid(ProjectsErrors.ParticipantUnExistError); return Result.Invalid(ProjectsErrors.ParticipantUnExistError);
} }
employeeParticipate.Employee.DecreaseWorkHours(employeeParticipate.PartialTimeRatio);
await _employeeParticipateRepository.DeleteAsync(employeeParticipate);
await _employeeParticipateRepository.DeleteAsync(employeeParticipate);
project.AddDomainEvent(new ParticipantRemovedEvent(request.ParticipantId, request.ProjectId)); project.AddDomainEvent(new ParticipantRemovedEvent(request.ParticipantId, request.ProjectId));
......
...@@ -56,9 +56,21 @@ namespace PSManagement.Domain.Employees.Entities ...@@ -56,9 +56,21 @@ namespace PSManagement.Domain.Employees.Entities
PersonalInfo = personalInfo; PersonalInfo = personalInfo;
HIASTId = hiastId; HIASTId = hiastId;
} }
#endregion Constructors #endregion Constructors
#region business logic encapsulation #region business logic encapsulation
public void IncreaseWorkHours(int workHours)
{
UpdateWorkHours(Availability.CurrentWorkingHours + workHours);
}
public void DecreaseWorkHours(int workHours)
{
UpdateWorkHours(Availability.CurrentWorkingHours - workHours);
}
public void UpdateWorkHours(int workingHour) public void UpdateWorkHours(int workingHour)
{ {
......
...@@ -266,20 +266,12 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -266,20 +266,12 @@ namespace PSManagement.Domain.Projects.Entities
#endregion State Transitions #endregion State Transitions
// validating data
// this methods help to hide the buissness rules
// and encapsulate it
#region Busines rules validators
public bool VailedSteps()
{
int weightSum = 0;
foreach (Step step in Steps) {
weightSum += step.Weight;
}
return weightSum == 100;
} // this methods encapsulate participation change
// its publis a domain event
#region Participation Change Encapsulation
public void ChangeParticipant(int participantId, int partialTimeRation, string role) public void ChangeParticipant(int participantId, int partialTimeRation, string role)
{ {
...@@ -292,6 +284,28 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -292,6 +284,28 @@ namespace PSManagement.Domain.Projects.Entities
participate.Role = role; participate.Role = role;
participate.PartialTimeRatio = partialTimeRation; participate.PartialTimeRatio = partialTimeRation;
participate.Employee.IncreaseWorkHours(partialTimeRation);
participate.Employee.DecreaseWorkHours(participate.PartialTimeRatio);
}
#endregion Participation Change Encapsulation
// validating data
// this methods help to hide the buissness rules
// and encapsulate it
#region Busines rules validators
public bool VailedSteps()
{
int weightSum = 0;
foreach (Step step in Steps) {
weightSum += step.Weight;
}
return weightSum == 100;
} }
public bool HasParticipant(int participantId) public bool HasParticipant(int participantId)
{ {
......
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