|
|
|
@ -5,6 +5,7 @@ using EPAServeur.Models.EP; |
|
|
|
|
using EPAServeur.Models.Formation; |
|
|
|
|
using EPAServeur.Models.SaisieChamp; |
|
|
|
|
using IO.Swagger.DTO; |
|
|
|
|
using IO.Swagger.Enum; |
|
|
|
|
using IO.Swagger.ModelCollaborateur; |
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
using System; |
|
|
|
@ -41,7 +42,7 @@ namespace EPAServeur.Services |
|
|
|
|
|
|
|
|
|
#region Méthodes Service |
|
|
|
|
|
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagements(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagements(bool? asc, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
@ -53,10 +54,7 @@ namespace EPAServeur.Services |
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence).Skip(skip).Take(take); |
|
|
|
|
else |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Skip(skip).Take(take); |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Skip(skip).Take(take); |
|
|
|
|
|
|
|
|
|
if (engagements == null || engagements.Count() == 0) |
|
|
|
|
return new List<EngagementDTO>(); |
|
|
|
@ -66,7 +64,7 @@ namespace EPAServeur.Services |
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsAsync(bool? asc, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
@ -78,10 +76,7 @@ namespace EPAServeur.Services |
|
|
|
|
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).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
else |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
|
|
|
|
|
if (engagements == null || engagements.Count() == 0) |
|
|
|
|
return new List<EngagementDTO>(); |
|
|
|
@ -92,7 +87,7 @@ namespace EPAServeur.Services |
|
|
|
|
return results; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagementsEnAttente(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagementsEnAttente(bool? asc, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
@ -104,10 +99,7 @@ namespace EPAServeur.Services |
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).Skip(skip).Take(take).ToList(); |
|
|
|
|
else |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).Skip(skip).Take(take).ToList(); |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.EtatEngagement == EtatEngagement.EnAttente).Skip(skip).Take(take).ToList(); |
|
|
|
|
|
|
|
|
|
if (engagements == null || engagements.Count() == 0) |
|
|
|
|
return new List<EngagementDTO>(); |
|
|
|
@ -117,7 +109,7 @@ namespace EPAServeur.Services |
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsEnAttenteAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsEnAttenteAsync(bool? asc, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
@ -129,10 +121,7 @@ namespace EPAServeur.Services |
|
|
|
|
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).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
else |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.EtatEngagement == EtatEngagement.EnAttente).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
|
|
|
|
|
if (engagements == null || engagements.Count() == 0) |
|
|
|
|
return new List<EngagementDTO>(); |
|
|
|
@ -143,7 +132,7 @@ namespace EPAServeur.Services |
|
|
|
|
return results; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagementsRepondus(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagementsRepondus(bool? asc, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
@ -155,10 +144,7 @@ namespace EPAServeur.Services |
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idAgence != null) |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take); |
|
|
|
|
else |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take); |
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.EtatEngagement == EtatEngagement.Respecte && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take); |
|
|
|
|
|
|
|
|
|
if (engagements == null || engagements.Count() == 0) |
|
|
|
|
return new List<EngagementDTO>(); |
|
|
|
@ -168,7 +154,7 @@ namespace EPAServeur.Services |
|
|
|
|
return engagementDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsRepondusAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) |
|
|
|
|
public async Task<IEnumerable<EngagementDTO>> GetEngagementsRepondusAsync(bool? asc, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Engagement> engagements; |
|
|
|
|
|
|
|
|
@ -180,10 +166,7 @@ namespace EPAServeur.Services |
|
|
|
|
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)).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
else |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.EtatEngagement == EtatEngagement.Respecte && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take).ToListAsync(); |
|
|
|
|
|
|
|
|
|
if (engagements == null || engagements.Count() == 0) |
|
|
|
|
return new List<EngagementDTO>(); |
|
|
|
@ -206,7 +189,7 @@ namespace EPAServeur.Services |
|
|
|
|
if (!IsEngagementValide(engagementDTO)) |
|
|
|
|
throw new EngagementInvalidException("Impossible de répondre à l'engagement, des données sont manquants."); |
|
|
|
|
|
|
|
|
|
if (engagementDTO.Realise == false && string.IsNullOrWhiteSpace(engagementDTO.RaisonNonRealisable)) |
|
|
|
|
if (engagementDTO.EtatEngagement == EtatEngagement.NonRealisable && string.IsNullOrWhiteSpace(engagementDTO.RaisonNonRealisable)) |
|
|
|
|
throw new EngagementInvalidException("Impossible de répondre à l'engagement, une raison doit être rensignée lorsqu'un engagement n'est pas réalisé."); |
|
|
|
|
|
|
|
|
|
if (engagementDTO == null && !engagementDTO.Id.HasValue && engagementDTO.Id.Value != idEngagement) |
|
|
|
@ -218,20 +201,20 @@ namespace EPAServeur.Services |
|
|
|
|
if (engagement == null) |
|
|
|
|
throw new EngagementNotFoundException(); |
|
|
|
|
|
|
|
|
|
engagement.Realise = engagementDTO.Realise; |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
|
|
|
|
|
switch (engagement.Realise) |
|
|
|
|
switch (engagement.EtatEngagement) |
|
|
|
|
{ |
|
|
|
|
case true: |
|
|
|
|
engagement.Realisable = engagementDTO.Realisable; |
|
|
|
|
case EtatEngagement.Respecte: |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
engagement.RaisonNonRealisable = null; |
|
|
|
|
break; |
|
|
|
|
case false: |
|
|
|
|
engagement.Realisable = engagementDTO.Realisable; |
|
|
|
|
case EtatEngagement.NonRealisable: |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
engagement.Realisable = null; |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
engagement.RaisonNonRealisable = null; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -254,7 +237,7 @@ namespace EPAServeur.Services |
|
|
|
|
if (!IsEngagementValide(engagementDTO)) |
|
|
|
|
throw new EngagementInvalidException("Impossible de répondre à l'engagement, des données sont manquants."); |
|
|
|
|
|
|
|
|
|
if (engagementDTO.Realise == false && string.IsNullOrWhiteSpace(engagementDTO.RaisonNonRealisable)) |
|
|
|
|
if (engagementDTO.EtatEngagement == EtatEngagement.NonRealisable && string.IsNullOrWhiteSpace(engagementDTO.RaisonNonRealisable)) |
|
|
|
|
throw new EngagementInvalidException("Impossible de répondre à l'engagement, une raison doit être rensignée lorsqu'un engagement n'est pas réalisé."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -263,24 +246,23 @@ namespace EPAServeur.Services |
|
|
|
|
if (engagement == null) |
|
|
|
|
throw new EngagementNotFoundException(); |
|
|
|
|
|
|
|
|
|
engagement.Realise = engagementDTO.Realise; |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
|
|
|
|
|
switch (engagement.Realise) |
|
|
|
|
switch (engagement.EtatEngagement) |
|
|
|
|
{ |
|
|
|
|
case true: |
|
|
|
|
engagement.Realisable = engagementDTO.Realisable; |
|
|
|
|
case EtatEngagement.Respecte: |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
engagement.RaisonNonRealisable = null; |
|
|
|
|
break; |
|
|
|
|
case false: |
|
|
|
|
engagement.Realisable = engagementDTO.Realisable; |
|
|
|
|
case EtatEngagement.NonRealisable: |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
engagement.Realisable = null; |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
engagement.RaisonNonRealisable = null; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await epContext.SaveChangesAsync(); |
|
|
|
|
|
|
|
|
|
return await GetEngagementDTOAsync(engagement); |
|
|
|
@ -292,7 +274,7 @@ 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.DateLimite == null || engagementDTO.Dispositif == null || engagementDTO.Modalite == null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Object to DTO |
|
|
|
@ -308,12 +290,11 @@ namespace EPAServeur.Services |
|
|
|
|
{ |
|
|
|
|
Id = engagement.IdEngagement, |
|
|
|
|
Action = engagement.Action, |
|
|
|
|
DatePrevisionnelle = engagement.DateLimite, |
|
|
|
|
DateLimite = engagement.DateLimite, |
|
|
|
|
Dispositif = engagement.Dispositif, |
|
|
|
|
Modalite = engagement.Modalite, |
|
|
|
|
RaisonNonRealisable = engagement.RaisonNonRealisable, |
|
|
|
|
Realisable = engagement.Realisable, |
|
|
|
|
Realise = engagement.Realise, |
|
|
|
|
EtatEngagement = engagement.EtatEngagement, |
|
|
|
|
Ep = GetEpInformationDTO(engagement.Ep) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -331,12 +312,11 @@ namespace EPAServeur.Services |
|
|
|
|
{ |
|
|
|
|
Id = engagement.IdEngagement, |
|
|
|
|
Action = engagement.Action, |
|
|
|
|
DatePrevisionnelle = engagement.DateLimite, |
|
|
|
|
DateLimite = engagement.DateLimite, |
|
|
|
|
Dispositif = engagement.Dispositif, |
|
|
|
|
Modalite = engagement.Modalite, |
|
|
|
|
RaisonNonRealisable = engagement.RaisonNonRealisable, |
|
|
|
|
Realisable = engagement.Realisable, |
|
|
|
|
Realise = engagement.Realise, |
|
|
|
|
EtatEngagement = engagement.EtatEngagement, |
|
|
|
|
Ep = await GetEpInformationDTOAsync(engagement.Ep) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -352,7 +332,7 @@ namespace EPAServeur.Services |
|
|
|
|
{ |
|
|
|
|
EpInformationDTO epInformationDTO = new EpInformationDTO() |
|
|
|
|
{ |
|
|
|
|
Id = ep.Id, |
|
|
|
|
Id = ep.IdEP, |
|
|
|
|
Type = ep.TypeEP.ToString(), |
|
|
|
|
Statut = ep.Statut.ToString(), |
|
|
|
|
DatePrevisionnelle = ep.DatePrevisionnelle, |
|
|
|
@ -374,7 +354,7 @@ namespace EPAServeur.Services |
|
|
|
|
{ |
|
|
|
|
EpInformationDTO epInformationDTO = new EpInformationDTO() |
|
|
|
|
{ |
|
|
|
|
Id = ep.Id, |
|
|
|
|
Id = ep.IdEP, |
|
|
|
|
Type = ep.TypeEP.ToString(), |
|
|
|
|
Statut = ep.Statut.ToString(), |
|
|
|
|
DatePrevisionnelle = ep.DatePrevisionnelle, |
|
|
|
@ -406,12 +386,11 @@ namespace EPAServeur.Services |
|
|
|
|
private Engagement SetEngagement(Engagement engagement, EngagementDTO engagementDTO) |
|
|
|
|
{ |
|
|
|
|
engagement.Action = engagementDTO.Action; |
|
|
|
|
engagement.DateLimite = engagementDTO.DatePrevisionnelle.Value; |
|
|
|
|
engagement.DateLimite = engagementDTO.DateLimite.Value; |
|
|
|
|
engagement.Dispositif = engagementDTO.Dispositif; |
|
|
|
|
engagement.Modalite = engagementDTO.Modalite; |
|
|
|
|
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable; |
|
|
|
|
engagement.Realisable = engagementDTO.Realisable; |
|
|
|
|
engagement.Realise = engagementDTO.Realise; |
|
|
|
|
engagement.EtatEngagement = engagementDTO.EtatEngagement; |
|
|
|
|
engagement.Ep = GetEp(engagementDTO.Ep); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -429,14 +408,14 @@ namespace EPAServeur.Services |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
// Traiter |
|
|
|
|
Enum.TryParse(epInformationDTO.Type, out TypeChamp typeChamp); |
|
|
|
|
Enum.TryParse(epInformationDTO.Type, out TypeEp typeEP); |
|
|
|
|
|
|
|
|
|
Enum.TryParse(epInformationDTO.Statut, out StatutEP statutEP); |
|
|
|
|
Enum.TryParse(epInformationDTO.Statut, out StatutEp statutEP); |
|
|
|
|
|
|
|
|
|
Ep ep = new Ep() |
|
|
|
|
{ |
|
|
|
|
Id = epInformationDTO.Id.Value, |
|
|
|
|
TypeEP = typeChamp, |
|
|
|
|
IdEP = epInformationDTO.Id.Value, |
|
|
|
|
TypeEP = typeEP, |
|
|
|
|
Statut = statutEP, |
|
|
|
|
DatePrevisionnelle = epInformationDTO.DatePrevisionnelle.Value, |
|
|
|
|
Obligatoire = epInformationDTO.Obligatoire.Value, |
|
|
|
|