|
|
|
@ -20,6 +20,7 @@ namespace EPAServeur.Services |
|
|
|
|
|
|
|
|
|
private readonly EpContext epContext; |
|
|
|
|
private readonly ICollaborateurService collaborateurService; |
|
|
|
|
private readonly IReferentService referentService; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Contructeurs |
|
|
|
@ -28,10 +29,11 @@ namespace EPAServeur.Services |
|
|
|
|
/// Constructeur de la classe EngagementService |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="_epContext"></param> |
|
|
|
|
public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService) |
|
|
|
|
public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService, IReferentService _referentService) |
|
|
|
|
{ |
|
|
|
|
epContext = _epContext; |
|
|
|
|
collaborateurService = _collaborateurService; |
|
|
|
|
referentService = _referentService; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
@ -41,7 +43,6 @@ namespace EPAServeur.Services |
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagements(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
IEnumerable<EngagementDTO> engagementDTOs; |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
@ -52,40 +53,46 @@ namespace EPAServeur.Services |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep); |
|
|
|
|
|
|
|
|
|
if (engagements == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
var engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement)); |
|
|
|
|
|
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
|
else |
|
|
|
|
texte = texte.ToLower(); |
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence).ToListAsync(); |
|
|
|
|
else |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).ToListAsync(); |
|
|
|
|
|
|
|
|
|
if (engagements == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement)); |
|
|
|
|
var engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement)); |
|
|
|
|
|
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagementsEnAttente(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
IEnumerable<EngagementDTO> engagementDTOs; |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
@ -96,40 +103,47 @@ namespace EPAServeur.Services |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).ToList(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).ToList(); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).ToList(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).ToList(); |
|
|
|
|
|
|
|
|
|
if (engagements == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
var engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement)); |
|
|
|
|
|
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsEnAttenteAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
|
else |
|
|
|
|
texte = texte.ToLower(); |
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).ToListAsync(); |
|
|
|
|
else |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).ToListAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (engagements == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement)); |
|
|
|
|
var engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement)); |
|
|
|
|
|
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IList<EngagementDTO>> GetEngagementsRepondus(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagementsRepondus(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
//<EngagementDTO> engagementDTOs = new List<EngagementDTO>(); |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
@ -140,38 +154,41 @@ namespace EPAServeur.Services |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Modalite.ToLower().Contains(texte)); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (engagements == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
var engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTOAsync(engagement)); |
|
|
|
|
var engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement)); |
|
|
|
|
|
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsRepondusAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
|
else |
|
|
|
|
texte = texte.ToLower(); |
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Modalite.ToLower().Contains(texte)).ToListAsync(); |
|
|
|
|
else |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)).ToListAsync(); |
|
|
|
|
|
|
|
|
|
if (engagements == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
var engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTOAsync(engagement)); |
|
|
|
|
var results = await Task.WhenAll(engagementDTOs); |
|
|
|
|
//foreach (var engagement in engagements) |
|
|
|
|
//{ |
|
|
|
|
// engagementDTOs.Add(await GetEngagementDTOAsync(engagement)); |
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
return results; |
|
|
|
|
} |
|
|
|
@ -182,18 +199,15 @@ namespace EPAServeur.Services |
|
|
|
|
/// <param name="engagementDTO"></param> |
|
|
|
|
/// <param name="idEngagement"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<EngagementDTO> RepondreEngagement(EngagementDTO engagementDTO, long? idEngagement) |
|
|
|
|
public EngagementDTO RepondreEngagement(EngagementDTO engagementDTO, long? idEngagement) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!IsEngagementValide(engagementDTO)) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
if (engagementDTO.Id != idEngagement) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
if (engagementDTO.Realise == false && string.IsNullOrWhiteSpace(engagementDTO.RaisonNonRealisable)) |
|
|
|
|
return null; // Créer une exception pour ce cas |
|
|
|
|
|
|
|
|
|
Engagement engagement = epContext.Engagement.Include(engagement => engagement.Ep).FirstOrDefault(engagement => engagement.Id == idEngagement); |
|
|
|
|
|
|
|
|
|
if (engagement == null) |
|
|
|
@ -209,6 +223,40 @@ namespace EPAServeur.Services |
|
|
|
|
|
|
|
|
|
epContext.SaveChanges(); |
|
|
|
|
|
|
|
|
|
return GetEngagementDTO(engagement); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Donner une réponse à un engagement de manière asynchrone |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="engagementDTO"></param> |
|
|
|
|
/// <param name="idEngagement"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<EngagementDTO> RepondreEngagementAsync(EngagementDTO engagementDTO, long? idEngagement) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
if (!IsEngagementValide(engagementDTO)) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
if (engagementDTO.Id != idEngagement) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
Engagement engagement = await epContext.Engagement.Include(engagement => engagement.Ep).FirstOrDefaultAsync(engagement => engagement.Id == idEngagement); |
|
|
|
|
|
|
|
|
|
if (engagement == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
engagement.Realise = engagementDTO.Realise; |
|
|
|
|
|
|
|
|
|
if (engagement.Realise == false) |
|
|
|
|
{ |
|
|
|
|
engagement.Realisable = engagementDTO.Realisable; |
|
|
|
|
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await epContext.SaveChangesAsync(); |
|
|
|
|
|
|
|
|
|
return await GetEngagementDTOAsync(engagement); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -218,11 +266,11 @@ namespace EPAServeur.Services |
|
|
|
|
#region Méthodes Privée |
|
|
|
|
private bool IsEngagementValide(EngagementDTO engagementDTO) |
|
|
|
|
{ |
|
|
|
|
return !(engagementDTO == null || engagementDTO.Id == null || engagementDTO.Action == null || engagementDTO.DatePrevisionnelle == null || engagementDTO.Dispositif == null || engagementDTO.Modalite == null); |
|
|
|
|
return !(engagementDTO == null || engagementDTO.Id == null || engagementDTO.Action == null || engagementDTO.DatePrevisionnelle == null || engagementDTO.Dispositif == null || engagementDTO.Modalite == null || (engagementDTO.Realise == false && string.IsNullOrWhiteSpace(engagementDTO.RaisonNonRealisable))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Object to DTO |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un objet EngagementDTO en fonction d'un objet Engagement |
|
|
|
|
/// </summary> |
|
|
|
@ -274,7 +322,7 @@ namespace EPAServeur.Services |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="ep"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private EpInformationDTO GetEpInformationDTO(Ep ep) |
|
|
|
|
private EpInformationDTO GetEpInformationDTO(Ep ep) |
|
|
|
|
{ |
|
|
|
|
EpInformationDTO epInformationDTO = new EpInformationDTO() |
|
|
|
|
{ |
|
|
|
@ -284,7 +332,7 @@ namespace EPAServeur.Services |
|
|
|
|
DatePrevisionnelle = ep.DatePrevisionnelle, |
|
|
|
|
Obligatoire = ep.Obligatoire, |
|
|
|
|
Collaborateur = collaborateurService.GetCollaborateurById(ep.IdCollaborateur), |
|
|
|
|
Referent = collaborateurService.GetCollaborateurById(ep.IdReferent) |
|
|
|
|
Referent = referentService.GetReferentById(ep.IdReferent) |
|
|
|
|
//Ajouter la date de disponibilité |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -304,11 +352,17 @@ namespace EPAServeur.Services |
|
|
|
|
Type = ep.TypeEP.ToString(), |
|
|
|
|
Statut = ep.Statut.ToString(), |
|
|
|
|
DatePrevisionnelle = ep.DatePrevisionnelle, |
|
|
|
|
Obligatoire = ep.Obligatoire, |
|
|
|
|
Collaborateur = await collaborateurService.GetCollaborateurByIdAsync(ep.IdCollaborateur), |
|
|
|
|
Referent = await collaborateurService.GetCollaborateurByIdAsync(ep.IdReferent) |
|
|
|
|
Obligatoire = ep.Obligatoire |
|
|
|
|
//Ajouter la date de disponibilité |
|
|
|
|
}; |
|
|
|
|
var collaborateur = collaborateurService.GetCollaborateurByIdAsync(ep.IdCollaborateur); |
|
|
|
|
var referent = referentService.GetReferentByIdAsync(ep.IdReferent); |
|
|
|
|
|
|
|
|
|
await Task.WhenAll(collaborateur, referent); |
|
|
|
|
|
|
|
|
|
epInformationDTO.Collaborateur = collaborateur.Result; |
|
|
|
|
epInformationDTO.Referent = referent.Result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return epInformationDTO; |
|
|
|
|
} |
|
|
|
@ -368,7 +422,7 @@ namespace EPAServeur.Services |
|
|
|
|
return ep; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|