|
|
|
@ -8,11 +8,15 @@ namespace espacecollab.backend.appservices; |
|
|
|
|
public class CollaborateursService : GenericsServices<CollaborateurSqlDto, CollaborateurApiDto> |
|
|
|
|
{ |
|
|
|
|
private ICollaborateurRepository CollaborateurRepository { get; } |
|
|
|
|
private IPeriodeEssaiRepository PeriodeEssaiRepository { get; } |
|
|
|
|
private IReferencementRepository ReferencementRepository { get; } |
|
|
|
|
|
|
|
|
|
public CollaborateursService(ICollaborateurRepository collaborateurRepository) |
|
|
|
|
public CollaborateursService(ICollaborateurRepository collaborateurRepository, IPeriodeEssaiRepository periodeEssaiRepository, IReferencementRepository referencementRepository) |
|
|
|
|
: base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql) |
|
|
|
|
{ |
|
|
|
|
CollaborateurRepository = collaborateurRepository; |
|
|
|
|
PeriodeEssaiRepository = periodeEssaiRepository; |
|
|
|
|
ReferencementRepository = referencementRepository; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public (CollaborateurApiDto?,int) Add(CollaborateurApiDto apiDto) |
|
|
|
@ -41,8 +45,6 @@ public class CollaborateursService : GenericsServices<CollaborateurSqlDto, Colla |
|
|
|
|
return (null,2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CollaborateurSqlDto sqlDto = apiDto.ToSql(); |
|
|
|
|
CollaborateurSqlDto? sqlDtoValidation = CollaborateurRepository.Update(sqlDto); |
|
|
|
|
|
|
|
|
@ -52,6 +54,37 @@ public class CollaborateursService : GenericsServices<CollaborateurSqlDto, Colla |
|
|
|
|
return (sqlDtoValidation.ToApi(),0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public new bool Delete(uint apiDtoId) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<ReferencementSqlDto>? referencements = ReferencementRepository.GetAll(); |
|
|
|
|
IEnumerable<PeriodeEssaiSqlDto>? periodeEssais = PeriodeEssaiRepository.GetAll(); |
|
|
|
|
|
|
|
|
|
if (referencements.Any()) |
|
|
|
|
{ |
|
|
|
|
foreach (var referencement in referencements) |
|
|
|
|
{ |
|
|
|
|
if (referencement.ReferredId == apiDtoId || referencement.ReferrerId == apiDtoId) |
|
|
|
|
{ |
|
|
|
|
ReferencementRepository.Delete(referencement.Id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (periodeEssais.Any()) |
|
|
|
|
{ |
|
|
|
|
foreach (var periodeEssai in periodeEssais) |
|
|
|
|
{ |
|
|
|
|
if (periodeEssai.CollaborateurId== apiDtoId) |
|
|
|
|
{ |
|
|
|
|
PeriodeEssaiRepository.Delete(periodeEssai.Id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return CollaborateurRepository.Delete((int)apiDtoId); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IEnumerable<CollaborateurApiDto> GetCollaborateursByBusinessUnit(uint businessUnitId) |
|
|
|
|
{ |
|
|
|
|
return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); |
|
|
|
|