|
|
|
|
using EPAServeur.Context;
|
|
|
|
|
using EPAServeur.IServices;
|
|
|
|
|
using EPAServeur.Models.EP;
|
|
|
|
|
using EPAServeur.Models.Formation;
|
|
|
|
|
using EPAServeur.Models.SaisieChamp;
|
|
|
|
|
using IO.Swagger.DTO;
|
|
|
|
|
using IO.Swagger.ModelCollaborateur;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace EPAServeur.Services
|
|
|
|
|
{
|
|
|
|
|
public class EngagementService : IEngagementService
|
|
|
|
|
{
|
|
|
|
|
#region Variables
|
|
|
|
|
|
|
|
|
|
private readonly EpContext epContext;
|
|
|
|
|
private readonly ICollaborateurService collaborateurService;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Contructeurs
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructeur de la classe EngagementService
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="_epContext"></param>
|
|
|
|
|
public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService)
|
|
|
|
|
{
|
|
|
|
|
epContext = _epContext;
|
|
|
|
|
collaborateurService = _collaborateurService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Méthodes Service
|
|
|
|
|
|
|
|
|
|
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 = "";
|
|
|
|
|
else
|
|
|
|
|
texte = texte.ToLower();
|
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (engagements == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
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 = "";
|
|
|
|
|
else
|
|
|
|
|
texte = texte.ToLower();
|
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
|
|
|
int take = parPAge.Value;
|
|
|
|
|
|
|
|
|
|
if (idAgence != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (engagements == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement));
|
|
|
|
|
return engagementDTOs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<EngagementDTO> GetEngagementsRepondus(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Engagement> engagements;
|
|
|
|
|
IEnumerable<EngagementDTO> engagementDTOs;
|
|
|
|
|
|
|
|
|
|
if (texte == null)
|
|
|
|
|
texte = "";
|
|
|
|
|
else
|
|
|
|
|
texte = texte.ToLower();
|
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
|
|
|
int take = parPAge.Value;
|
|
|
|
|
|
|
|
|
|
if (idAgence != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise != null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (engagements == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
engagementDTOs = engagements.Where(engagement => engagement.Modalite.ToLower().Contains(texte)).Select(engagement => GetEngagementDTO(engagement));
|
|
|
|
|
return engagementDTOs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Donner une réponse à un engagement
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="engagementDTO"></param>
|
|
|
|
|
/// <param name="idEngagement"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
engagement.Realise = engagementDTO.Realise;
|
|
|
|
|
|
|
|
|
|
if (engagement.Realise == false)
|
|
|
|
|
{
|
|
|
|
|
engagement.Realisable = engagementDTO.Realisable;
|
|
|
|
|
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
epContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return GetEngagementDTO(engagement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Object to DTO
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère un objet EngagementDTO en fonction d'un objet Engagement
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="engagement"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private EngagementDTO GetEngagementDTO(Engagement engagement)
|
|
|
|
|
{
|
|
|
|
|
EngagementDTO engagementDTO = new EngagementDTO()
|
|
|
|
|
{
|
|
|
|
|
Id = engagement.Id,
|
|
|
|
|
Action = engagement.Action,
|
|
|
|
|
DatePrevisionnelle = engagement.DateLimite,
|
|
|
|
|
Dispositif = engagement.Disposition,
|
|
|
|
|
Modalite = engagement.Modalite,
|
|
|
|
|
RaisonNonRealisable = engagement.RaisonNonRealisable,
|
|
|
|
|
Realisable = engagement.Realisable,
|
|
|
|
|
Realise = engagement.Realise,
|
|
|
|
|
Ep = GetEpInformationDTO(engagement.Ep)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return engagementDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère un objet EpInformationDTO en fonction d'un objet Ep
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ep"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private EpInformationDTO GetEpInformationDTO(Ep ep)
|
|
|
|
|
{
|
|
|
|
|
EpInformationDTO epInformationDTO = new EpInformationDTO()
|
|
|
|
|
{
|
|
|
|
|
Id = ep.Id,
|
|
|
|
|
Type = ep.TypeEP.ToString(),
|
|
|
|
|
Statut = ep.Statut.ToString(),
|
|
|
|
|
DatePrevisionnelle = ep.DatePrevisionnelle,
|
|
|
|
|
Obligatoire = ep.Obligatoire,
|
|
|
|
|
Collaborateur = collaborateurService.GetProfilById(ep.IdCollaborateur)
|
|
|
|
|
//Referent = null //collaborateurService.GetProfilById(ep.IdReferent)
|
|
|
|
|
//Ajouter la date de disponibilité
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return epInformationDTO;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region DTO to Object
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Modifie un objet Engagement en fonction d'un objet FormationDTO
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="engagement"></param>
|
|
|
|
|
/// <param name="engagementDTO"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private Engagement SetEngagement(Engagement engagement, EngagementDTO engagementDTO)
|
|
|
|
|
{
|
|
|
|
|
engagement.Action = engagementDTO.Action;
|
|
|
|
|
engagement.DateLimite = engagementDTO.DatePrevisionnelle.Value;
|
|
|
|
|
engagement.Disposition = engagementDTO.Dispositif;
|
|
|
|
|
engagement.Modalite = engagementDTO.Modalite;
|
|
|
|
|
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable;
|
|
|
|
|
engagement.Realisable = engagementDTO.Realisable;
|
|
|
|
|
engagement.Realise = engagementDTO.Realise;
|
|
|
|
|
engagement.Ep = GetEp(engagementDTO.Ep);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return engagement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère un objet Ep en fonction d'un objet EpDTO
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="origineFormationDTO"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private Ep GetEp(EpInformationDTO epInformationDTO)
|
|
|
|
|
{
|
|
|
|
|
if (epInformationDTO == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
// Traiter
|
|
|
|
|
Enum.TryParse(epInformationDTO.Type, out TypeChamp typeChamp);
|
|
|
|
|
|
|
|
|
|
Enum.TryParse(epInformationDTO.Statut, out StatutEP statutEP);
|
|
|
|
|
|
|
|
|
|
Ep ep = new Ep()
|
|
|
|
|
{
|
|
|
|
|
Id = epInformationDTO.Id.Value,
|
|
|
|
|
TypeEP = typeChamp,
|
|
|
|
|
Statut = statutEP,
|
|
|
|
|
DatePrevisionnelle = epInformationDTO.DatePrevisionnelle.Value,
|
|
|
|
|
Obligatoire = epInformationDTO.Obligatoire.Value,
|
|
|
|
|
IdReferent = epInformationDTO.Referent.Id.Value,
|
|
|
|
|
IdCollaborateur = epInformationDTO.Collaborateur.Id.Value,
|
|
|
|
|
// Ajouter la date de disponibilité
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|