You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
7.8 KiB
223 lines
7.8 KiB
using EPAServeur.Context;
|
|
using EPAServeur.IServices;
|
|
using EPAServeur.Models.EP;
|
|
using IO.Swagger.DTO;
|
|
using IO.Swagger.Enum;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EPAServeur.Services
|
|
{
|
|
public class EpInformationService : IEpInformationService
|
|
{
|
|
#region Variables
|
|
private EpContext context;
|
|
private ICollaborateurService collaborateurService;
|
|
private int? minParPage = 5;
|
|
private int? maxParPage = 100;
|
|
private int? defaultParPage = 15;
|
|
#endregion
|
|
|
|
#region constructeur
|
|
public EpInformationService(EpContext context, ICollaborateurService collaborateurService)
|
|
{
|
|
this.context = context;
|
|
this.collaborateurService = collaborateurService;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Services async
|
|
public async Task<IEnumerable<EpInformationDTO>> GetEPEnCours(List<long?> idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => EstEpEnCours(ep.Statut));
|
|
eps = TriDate(eps, dateDebut, dateFin);
|
|
|
|
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList();
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
|
|
|
|
IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs));
|
|
|
|
epDTOs = epDTOs.Where(e => TriTexte(e, texte));
|
|
|
|
epDTOs = TriColonne(epDTOs, tri);
|
|
|
|
if (asc != null && asc.HasValue && !asc.Value)
|
|
epDTOs = epDTOs.Reverse();
|
|
|
|
return SkipAndTake(epDTOs, numPage, parPage);
|
|
}
|
|
|
|
|
|
|
|
public async Task<int> GetEPEnCoursCount(List<long?> idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => EstEpEnCours(ep.Statut));
|
|
eps = TriDate(eps, dateDebut, dateFin);
|
|
|
|
|
|
|
|
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList();
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
|
|
|
|
IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs));
|
|
|
|
epDTOs = epDTOs.Where(e => TriTexte(e, texte));
|
|
|
|
return epDTOs.Count();
|
|
}
|
|
|
|
public async Task<IEnumerable<EpInformationDTO>> GetEPEnCoursCollaborateurParticipant(Guid? idCollaborateur)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<IEnumerable<EpInformationDTO>> GetEPEnCoursReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<int> GetEPEnCoursReferentCount(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<IEnumerable<EpInformationDTO>> GetEPSignes(List<long?> idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe);
|
|
eps = TriDate(eps, dateDebut, dateFin);
|
|
|
|
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList();
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
|
|
|
|
IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs));
|
|
|
|
epDTOs = epDTOs.Where(e => TriTexte(e, texte));
|
|
|
|
epDTOs = TriColonne(epDTOs, tri);
|
|
|
|
if (asc != null && asc.HasValue && !asc.Value)
|
|
epDTOs = epDTOs.Reverse();
|
|
|
|
return SkipAndTake(epDTOs, numPage, parPage);
|
|
}
|
|
|
|
public async Task<IEnumerable<EpInformationDTO>> GetEPSignesCollaborateur(Guid? idCollaborateur)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<int> GetEPSignesCount(List<long?> idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe);
|
|
eps = TriDate(eps, dateDebut, dateFin);
|
|
|
|
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList();
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
|
|
|
|
IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs));
|
|
|
|
epDTOs = epDTOs.Where(e => TriTexte(e, texte));
|
|
|
|
return epDTOs.Count();
|
|
}
|
|
|
|
public async Task<IEnumerable<EpInformationDTO>> GetEPSignesReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<int> GetEPSignesReferentCount(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<EpInformationDTO> GetProchainEPCollaborateur(Guid? idCollaborateur)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
#endregion
|
|
|
|
#region méthodes privées
|
|
private IEnumerable<Ep> TriDate(IEnumerable<Ep> eps, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
if (dateDebut.HasValue && dateDebut.Value != null)
|
|
eps = eps.Where(ep => ep.DatePrevisionnelle >= dateDebut.Value);
|
|
|
|
if (dateFin.HasValue && dateFin.Value != null)
|
|
eps = eps.Where(ep => ep.DatePrevisionnelle < dateFin.Value.AddDays(1));
|
|
return eps;
|
|
}
|
|
|
|
|
|
private EpInformationDTO EpToEpDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
|
|
{
|
|
return new EpInformationDTO()
|
|
{
|
|
Id = ep.IdEP,
|
|
Collaborateur = collaborateurDTOs.Where(c => c.Id.Equals(ep.IdCollaborateur)).FirstOrDefault(),
|
|
DateDisponibilite = ep.DateDisponibilite,
|
|
DatePrevisionnelle = ep.DatePrevisionnelle,
|
|
Obligatoire = ep.Obligatoire,
|
|
Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)),
|
|
Statut = ep.Statut,
|
|
Type = ep.TypeEP
|
|
};
|
|
}
|
|
|
|
private IEnumerable<EpInformationDTO> TriColonne(IEnumerable<EpInformationDTO> epDTOs, string tri)
|
|
{
|
|
switch (tri)
|
|
{
|
|
case "agence":
|
|
epDTOs = epDTOs.OrderBy(e => e.Collaborateur.BusinessUnit.Nom);
|
|
break;
|
|
case "collaborateur":
|
|
epDTOs = epDTOs.OrderBy(e => e.Collaborateur.Nom + e.Collaborateur.Prenom);
|
|
break;
|
|
case "referent":
|
|
epDTOs = epDTOs.OrderBy(e => e.Referent.Nom + e.Referent.Prenom);
|
|
break;
|
|
case "date":
|
|
epDTOs = epDTOs.OrderBy(e => e.DatePrevisionnelle);
|
|
break;
|
|
case "typeep":
|
|
epDTOs = epDTOs.OrderBy(e => e.Type);
|
|
break;
|
|
case "etatep":
|
|
epDTOs = epDTOs.OrderBy(e => e.Statut);
|
|
break;
|
|
}
|
|
return epDTOs;
|
|
}
|
|
|
|
private IEnumerable<EpInformationDTO> SkipAndTake(IEnumerable<EpInformationDTO> epDTOs, int? numPage, int? parPage)
|
|
{
|
|
if(numPage == null ||!numPage.HasValue)
|
|
numPage = 1;
|
|
if (parPage == null || !parPage.HasValue || parPage < minParPage || parPage > maxParPage)
|
|
parPage = defaultParPage;
|
|
int skip = (numPage.Value - 1) * parPage.Value;
|
|
return epDTOs.Skip(skip).Take(parPage.Value);
|
|
|
|
}
|
|
|
|
private bool EstEpEnCours(StatutEp statut)
|
|
{
|
|
return statut != StatutEp.Annule && statut != StatutEp.Cree && statut != StatutEp.Rejete && statut != StatutEp.Signe;
|
|
}
|
|
|
|
private bool TriTexte(EpInformationDTO epDTOs, string texte)
|
|
{
|
|
return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).ToLower().Contains(texte.ToLower());
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|