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.
1005 lines
43 KiB
1005 lines
43 KiB
using EPAServeur.Context;
|
|
using EPAServeur.Exceptions;
|
|
using EPAServeur.IServices;
|
|
using EPAServeur.Models.Formation;
|
|
using IO.Swagger.DTO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EPAServeur.Services
|
|
{
|
|
public class FormationService : IFormationService
|
|
{
|
|
#region Variables
|
|
|
|
private readonly EpContext epContext;
|
|
|
|
#endregion
|
|
|
|
#region Contructeurs
|
|
|
|
/// <summary>
|
|
/// Constructeur de la classe FormationService
|
|
/// </summary>
|
|
/// <param name="_epContext"></param>
|
|
public FormationService(EpContext _epContext)
|
|
{
|
|
epContext = _epContext;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Méthodes Service
|
|
|
|
/// <summary>
|
|
/// Récupérer une formation par son id
|
|
/// </summary>
|
|
/// <param name="idFormation"></param>
|
|
/// <returns></returns>
|
|
public FormationDTO GetFormationById(long? idFormation)
|
|
{
|
|
Formation formation = epContext.Formation.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation)
|
|
.FirstOrDefault(formation => formation.Id == idFormation);
|
|
|
|
if (formation == null)
|
|
throw new FormationNotFoundException();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer une formation par son id de manière asynchrone
|
|
/// </summary>
|
|
/// <param name="idFormation"></param>
|
|
/// <returns></returns>
|
|
public async Task<FormationDTO> GetFormationByIdAsync(long? idFormation)
|
|
{
|
|
Formation formation = await epContext.Formation.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation)
|
|
.FirstOrDefaultAsync(formation => formation.Id == idFormation);
|
|
|
|
if (formation == null)
|
|
throw new FormationNotFoundException();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer la liste des formations
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public IEnumerable<FormationDTO> GetFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (statutFormation != null && idAgence != null)
|
|
{
|
|
formations = epContext.Formation
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation)
|
|
.Where(formation => formation.Statut.Id == statutFormation && formation.IdAgence == idAgence);
|
|
}
|
|
else if (statutFormation != null && idAgence == null)
|
|
{
|
|
formations = epContext.Formation
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation)
|
|
.Where(formation => formation.Statut.Id == statutFormation);
|
|
}
|
|
else if (idAgence != null)
|
|
{
|
|
formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
}
|
|
else
|
|
{
|
|
formations = epContext.Formation.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
}
|
|
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer la liste des formations de manière asynchrone
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<FormationDTO>> GetFormationsAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (statutFormation != null && idAgence != null)
|
|
{
|
|
formations = await epContext.Formation
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation)
|
|
.Where(formation => formation.Statut.Id == statutFormation && formation.IdAgence == idAgence).ToListAsync();
|
|
}
|
|
else if (statutFormation != null && idAgence == null)
|
|
{
|
|
formations = await epContext.Formation
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation)
|
|
.Where(formation => formation.Statut.Id == statutFormation).ToListAsync();
|
|
}
|
|
else if (idAgence != null)
|
|
{
|
|
|
|
formations = await epContext.Formation
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).Where(formation => formation.IdAgence == idAgence).ToListAsync();
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
formations = await epContext.Formation.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).ToListAsync();
|
|
|
|
}
|
|
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les formations annulées
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public IEnumerable<FormationDTO> GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (idAgence != null)
|
|
formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.Id == 4)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
else
|
|
formations = epContext.Formation.Where(formation => formation.Statut.Id == 4)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les formations annulées de manière asynchrone
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<FormationDTO>> GetFormationAnnuleesAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (idAgence != null)
|
|
formations = await epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.Id == 4)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).ToListAsync();
|
|
else
|
|
formations = await epContext.Formation.Where(formation => formation.Statut.Id == 4)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).ToListAsync();
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les formations réalisées
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public IEnumerable<FormationDTO> GetFormationRealisee(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (idAgence != null)
|
|
{
|
|
|
|
formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.Id == 3)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
}
|
|
|
|
else
|
|
{
|
|
|
|
formations = epContext.Formation.Where(formation => formation.Statut.Id == 3)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
|
|
}
|
|
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les formations réalisées de manière asynchrone
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<FormationDTO>> GetFormationRealiseeAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (idAgence != null)
|
|
{
|
|
|
|
formations = await epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.Id == 3)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).ToListAsync();
|
|
}
|
|
|
|
else
|
|
{
|
|
|
|
formations = await epContext.Formation.Where(formation => formation.Statut.Id == 3)
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).ToListAsync();
|
|
}
|
|
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les formations plannifiées et replannifiées
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public IEnumerable<FormationDTO> GetProchainesFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (idAgence != null)
|
|
{
|
|
formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && (formation.Statut.Id == 1 || formation.Statut.Id == 2))
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
|
|
}
|
|
else
|
|
{
|
|
formations = epContext.Formation.Where(formation => (formation.Statut.Id == 1 || formation.Statut.Id == 2))
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation);
|
|
}
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les formations plannifiées et replannifiées de manère asynchrone
|
|
/// </summary>
|
|
/// <param name="asc">Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false)</param>
|
|
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
|
|
/// <param name="parPAge">Nombre d'éléments affiché sur chaque page du tableau</param>
|
|
/// <param name="idAgence">id de l'agence à laquelle sont rattachées les données à récupérer</param>
|
|
/// <param name="texte">Texte permettant d'identifier l'objet rechercher</param>
|
|
/// <param name="tri">Colonne du tableau sur lequel le tri s'effectue</param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<FormationDTO>> GetProchainesFormationAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri)
|
|
{
|
|
IEnumerable<Formation> formations;
|
|
IEnumerable<FormationDTO> formationDTOs;
|
|
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value;
|
|
int take = parPAge.Value;
|
|
|
|
if (idAgence != null)
|
|
{
|
|
formations = await epContext.Formation.Where(formation => formation.IdAgence == idAgence && (formation.Statut.Id == 1 || formation.Statut.Id == 2))
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).ToListAsync();
|
|
|
|
}
|
|
|
|
else
|
|
{
|
|
formations = await epContext.Formation.Where(formation => (formation.Statut.Id == 1 || formation.Statut.Id == 2))
|
|
.Include(formation => formation.Statut)
|
|
.Include(formation => formation.ModeFormation)
|
|
.Include(formation => formation.Origine)
|
|
.Include(formation => formation.TypeFormation).ToListAsync();
|
|
}
|
|
|
|
if (formations == null)
|
|
return null;
|
|
|
|
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
|
|
|
|
return formationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les modes de formation
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IEnumerable<ModeFormationDTO> GetModesFormation()
|
|
{
|
|
IEnumerable<ModeFormation> modeFormations;
|
|
IEnumerable<ModeFormationDTO> modeFormationDTOs;
|
|
|
|
modeFormations = epContext.ModeFormation;
|
|
|
|
if (modeFormations == null)
|
|
return null;
|
|
|
|
modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation));
|
|
|
|
return modeFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les modes de formation de manière asynchrone
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<ModeFormationDTO>> GetModesFormationAsync()
|
|
{
|
|
IEnumerable<ModeFormation> modeFormations;
|
|
IEnumerable<ModeFormationDTO> modeFormationDTOs;
|
|
modeFormations = await epContext.ModeFormation.ToListAsync();
|
|
|
|
if (modeFormations == null)
|
|
return null;
|
|
|
|
modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation));
|
|
|
|
return modeFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les origines de formation
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IEnumerable<OrigineFormationDTO> GetOriginesFormation()
|
|
{
|
|
IEnumerable<OrigineFormation> origineFormations;
|
|
IEnumerable<OrigineFormationDTO> origineFormationDTOs;
|
|
|
|
origineFormations = epContext.OrigineFormation;
|
|
|
|
if (origineFormations == null)
|
|
return null;
|
|
|
|
origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation));
|
|
|
|
return origineFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les origines de formation de manière asynchrone
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<OrigineFormationDTO>> GetOriginesFormationAsync()
|
|
{
|
|
IEnumerable<OrigineFormation> origineFormations;
|
|
IEnumerable<OrigineFormationDTO> origineFormationDTOs;
|
|
|
|
origineFormations = await epContext.OrigineFormation.ToListAsync();
|
|
|
|
if (origineFormations == null)
|
|
return null;
|
|
|
|
origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation));
|
|
|
|
return origineFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les statuts de formation
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IEnumerable<StatutFormationDTO> GetStatutsFormation()
|
|
{
|
|
IEnumerable<StatutFormation> statutFormations;
|
|
IEnumerable<StatutFormationDTO> statutFormationDTOs;
|
|
|
|
statutFormations = epContext.StatutFormation;
|
|
|
|
if (statutFormations == null)
|
|
return null;
|
|
|
|
statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation));
|
|
|
|
return statutFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les statuts de formation de manière asynchrone
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<StatutFormationDTO>> GetStatutsFormationAsync()
|
|
{
|
|
IEnumerable<StatutFormation> statutFormations;
|
|
IEnumerable<StatutFormationDTO> statutFormationDTOs;
|
|
|
|
statutFormations = await epContext.StatutFormation.ToListAsync();
|
|
|
|
if (statutFormations == null)
|
|
return null;
|
|
|
|
statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation));
|
|
|
|
return statutFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les types de formation
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IEnumerable<TypeFormationDTO> GetTypesFormation()
|
|
{
|
|
IEnumerable<TypeFormation> typeFormations;
|
|
IEnumerable<TypeFormationDTO> typeFormationDTOs;
|
|
|
|
typeFormations = epContext.TypeFormation;
|
|
|
|
if (typeFormations == null)
|
|
return null;
|
|
|
|
typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation));
|
|
|
|
return typeFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupérer les types de formation de manière asynchrone
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<TypeFormationDTO>> GetTypesFormationAsync()
|
|
{
|
|
IEnumerable<TypeFormation> typeFormations;
|
|
IEnumerable<TypeFormationDTO> typeFormationDTOs;
|
|
|
|
typeFormations = await epContext.TypeFormation.ToListAsync();
|
|
|
|
if (typeFormations == null)
|
|
return null;
|
|
|
|
typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation));
|
|
|
|
return typeFormationDTOs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ajouter une formation
|
|
/// </summary>
|
|
/// <param name="formationDTO"></param>
|
|
/// <returns></returns>
|
|
public FormationDTO AddFormation(FormationDTO formationDTO)
|
|
{
|
|
if (!IsFormationValide(formationDTO))
|
|
throw new FormationInvalidException();
|
|
|
|
Formation formation = new Formation();
|
|
formation = SetFormation(formation, formationDTO);
|
|
|
|
if (formation.Statut != null)
|
|
epContext.StatutFormation.Attach(formation.Statut);
|
|
|
|
epContext.OrigineFormation.Attach(formation.Origine);
|
|
epContext.ModeFormation.Attach(formation.ModeFormation);
|
|
epContext.TypeFormation.Attach(formation.TypeFormation);
|
|
epContext.Add(formation);
|
|
|
|
epContext.SaveChanges();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ajouter une formation de manière asynchrone
|
|
/// </summary>
|
|
/// <param name="formationDTO"></param>
|
|
/// <returns></returns>
|
|
public async Task<FormationDTO> AddFormationAsync(FormationDTO formationDTO)
|
|
{
|
|
if (!IsFormationValide(formationDTO))
|
|
throw new FormationInvalidException();
|
|
|
|
Formation formation = new Formation();
|
|
formation = SetFormation(formation, formationDTO);
|
|
|
|
if (formation.Statut != null)
|
|
epContext.StatutFormation.Attach(formation.Statut);
|
|
|
|
epContext.OrigineFormation.Attach(formation.Origine);
|
|
epContext.ModeFormation.Attach(formation.ModeFormation);
|
|
epContext.TypeFormation.Attach(formation.TypeFormation);
|
|
epContext.Add(formation);
|
|
|
|
await epContext.SaveChangesAsync();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modifier une formation
|
|
/// </summary>
|
|
/// <param name="idFormation"></param>
|
|
/// <param name="formationDTO"></param>
|
|
/// <returns></returns>
|
|
public FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO)
|
|
{
|
|
if (!IsFormationValide(formationDTO))
|
|
throw new FormationInvalidException();
|
|
|
|
if (formationDTO == null && !formationDTO.Id.HasValue && formationDTO.Id.Value != idFormation)
|
|
throw new FormationIncompatibleIdException();
|
|
|
|
Formation formation = epContext.Formation.Find(idFormation);
|
|
|
|
if (formation == null)
|
|
return null;
|
|
|
|
formation = SetFormation(formation, formationDTO);
|
|
|
|
epContext.SaveChanges();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modifier une formation de manière asynchrone
|
|
/// </summary>
|
|
/// <param name="idFormation"></param>
|
|
/// <param name="formationDTO"></param>
|
|
/// <returns></returns>
|
|
public async Task<FormationDTO> UpdateFormationAsync(long? idFormation, FormationDTO formationDTO)
|
|
{
|
|
if (!IsFormationValide(formationDTO))
|
|
throw new FormationInvalidException();
|
|
|
|
if (formationDTO == null && !formationDTO.Id.HasValue && formationDTO.Id.Value != idFormation)
|
|
throw new FormationIncompatibleIdException();
|
|
|
|
Formation formation = await epContext.Formation.FindAsync(idFormation);
|
|
|
|
if (formation == null)
|
|
return null;
|
|
|
|
formation = SetFormation(formation, formationDTO);
|
|
await epContext.SaveChangesAsync();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Supprimer une formation
|
|
/// </summary>
|
|
/// <param name="idFormation"></param>
|
|
/// <returns></returns>
|
|
public FormationDTO DeleteFormationById(long? idFormation)
|
|
{
|
|
Formation formation = epContext.Formation.Find(idFormation);
|
|
|
|
if (formation == null)
|
|
throw new FormationNotFoundException();
|
|
|
|
epContext.Remove(formation);
|
|
|
|
|
|
epContext.SaveChanges();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Supprimer une formation de manière asynchrone
|
|
/// </summary>
|
|
/// <param name="idFormation"></param>
|
|
/// <returns></returns>
|
|
public async Task<FormationDTO> DeleteFormationByIdAsync(long? idFormation)
|
|
{
|
|
Formation formation = await epContext.Formation.FindAsync(idFormation);
|
|
|
|
if (formation == null)
|
|
throw new FormationNotFoundException();
|
|
|
|
epContext.Remove(formation);
|
|
|
|
await epContext.SaveChangesAsync();
|
|
|
|
return GetFormationDTO(formation);
|
|
}
|
|
#endregion
|
|
|
|
#region Méthodes Privée
|
|
/// <summary>
|
|
/// Vérifier si un objet FormationDTO est valide pour ajout ou mise à jour
|
|
/// </summary>
|
|
/// <remarks> Un objet FormationDTO est valide si aucune de ses propriétés n'est à null</remarks>
|
|
/// <param name="formation"></param>
|
|
/// <returns>true si l'objet est valide, false sinon</returns>
|
|
private bool IsFormationValide(FormationDTO formation)
|
|
{
|
|
return !(formation == null || formation.IdAgence == null || formation.Intitule == null || formation.Organisme == null);
|
|
}
|
|
|
|
#region Object to DTO
|
|
/// <summary>
|
|
/// Récupère un objet FormationDTO en fonction d'un objet Formation
|
|
/// </summary>
|
|
/// <param name="formation"></param>
|
|
/// <returns></returns>
|
|
private FormationDTO GetFormationDTO(Formation formation)
|
|
{
|
|
FormationDTO formationDTO = new FormationDTO()
|
|
{
|
|
Id = formation.Id,
|
|
Intitule = formation.Intitule,
|
|
IdAgence = formation.IdAgence,
|
|
DateDebut = formation.DateDebut,
|
|
DateFin = formation.DateFin,
|
|
Heure = formation.Heure,
|
|
Jour = formation.Jour,
|
|
Organisme = formation.Organisme,
|
|
EstCertifie = formation.EstCertifiee,
|
|
Origine = GetOrigineFormationDTO(formation.Origine),
|
|
Statut = GetStatutFormationDTO(formation.Statut),
|
|
Mode = GetModeFormationDTO(formation.ModeFormation),
|
|
Type = GetTypeFormationDTO(formation.TypeFormation)
|
|
};
|
|
|
|
return formationDTO;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère un objet OrigineFormationDTO en fonction d'un objet OrigineFormation
|
|
/// </summary>
|
|
/// <param name="origineFormation"></param>
|
|
/// <returns></returns>
|
|
private OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation)
|
|
{
|
|
if (origineFormation == null)
|
|
return null;
|
|
OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO()
|
|
{
|
|
Id = origineFormation.Id,
|
|
Libelle = origineFormation.Libelle
|
|
};
|
|
return origineFormationDTO;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère un objet StatutFormationDTO en fonction d'un objet StatutFormation
|
|
/// </summary>
|
|
/// <param name="statutFormation"></param>
|
|
/// <returns></returns>
|
|
private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation)
|
|
{
|
|
if (statutFormation == null)
|
|
return null;
|
|
StatutFormationDTO statutFormationDTO = new StatutFormationDTO()
|
|
{
|
|
Id = statutFormation.Id,
|
|
Libelle = statutFormation.Libelle
|
|
};
|
|
return statutFormationDTO;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère un objet ModeFormationDTO en fonction d'un objet ModeFormation
|
|
/// </summary>
|
|
/// <param name="modeFormation"></param>
|
|
/// <returns></returns>
|
|
private ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation)
|
|
{
|
|
if (modeFormation == null)
|
|
return null;
|
|
ModeFormationDTO modeFormationDTO = new ModeFormationDTO()
|
|
{
|
|
Id = modeFormation.Id,
|
|
Libelle = modeFormation.Libelle
|
|
};
|
|
return modeFormationDTO;
|
|
}
|
|
/// <summary>
|
|
/// Récupère un objet TypeFormationDTO en fonction d'un objet TypeFormation
|
|
/// </summary>
|
|
/// <param name="typeFormation"></param>
|
|
/// <returns></returns>
|
|
private TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation)
|
|
{
|
|
if (typeFormation == null)
|
|
return null;
|
|
TypeFormationDTO typeFormationDTO = new TypeFormationDTO()
|
|
{
|
|
Id = typeFormation.Id,
|
|
Libelle = typeFormation.Libelle
|
|
};
|
|
return typeFormationDTO;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DTO to Object
|
|
|
|
/// <summary>
|
|
/// Modifie un objet Formation en fonction d'un objet FormationDTO
|
|
/// </summary>
|
|
/// <param name="formation"></param>
|
|
/// <param name="formationDTO"></param>
|
|
/// <returns></returns>
|
|
private Formation SetFormation(Formation formation, FormationDTO formationDTO)
|
|
{
|
|
formation.Intitule = formationDTO.Intitule;
|
|
formation.IdAgence = formationDTO.IdAgence.Value;
|
|
formation.DateDebut = formationDTO.DateDebut.Value;
|
|
formation.DateFin = formationDTO.DateFin.Value;
|
|
formation.Heure = Convert.ToInt32(formationDTO.Heure.Value);
|
|
formation.Jour = Convert.ToInt32(formationDTO.Jour.Value);
|
|
formation.Organisme = formationDTO.Organisme;
|
|
formation.EstCertifiee = formationDTO.EstCertifie.Value;
|
|
formation.Origine = GetOrigineFormation(formationDTO.Origine);
|
|
formation.Statut = GetStatutFormation(formationDTO.Statut);
|
|
formation.ModeFormation = GetModeFormation(formationDTO.Mode);
|
|
formation.TypeFormation = GetTypeFormation(formationDTO.Type);
|
|
|
|
return formation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère un objet OrigineFormation en fonction d'un objet OrigineFormationDTO
|
|
/// </summary>
|
|
/// <param name="origineFormationDTO"></param>
|
|
/// <returns></returns>
|
|
private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO)
|
|
{
|
|
if (origineFormationDTO == null)
|
|
return null;
|
|
OrigineFormation origineFormation = new OrigineFormation()
|
|
{
|
|
Id = origineFormationDTO.Id.Value,
|
|
Libelle = origineFormationDTO.Libelle
|
|
};
|
|
return origineFormation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère un objet StatutFormation en fonction d'un objet StatutFormationDTO
|
|
/// </summary>
|
|
/// <param name="statutFormationDTO"></param>
|
|
/// <returns></returns>
|
|
private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO)
|
|
{
|
|
if (statutFormationDTO == null)
|
|
return null;
|
|
StatutFormation statutFormation = new StatutFormation()
|
|
{
|
|
Id = statutFormationDTO.Id.Value,
|
|
Libelle = statutFormationDTO.Libelle
|
|
};
|
|
return statutFormation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère un objet ModeFormation en fonction d'un objet ModeFormationDTO
|
|
/// </summary>
|
|
/// <param name="modeFormationDTO"></param>
|
|
/// <returns></returns>
|
|
private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO)
|
|
{
|
|
if (modeFormationDTO == null)
|
|
return null;
|
|
ModeFormation modeFormation = new ModeFormation()
|
|
{
|
|
Id = modeFormationDTO.Id.Value,
|
|
Libelle = modeFormationDTO.Libelle
|
|
};
|
|
return modeFormation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère un objet TypeFormation en fonction d'un objet TypeFormationDTO
|
|
/// </summary>
|
|
/// <param name="typeFormationDTO"></param>
|
|
/// <returns></returns>
|
|
private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO)
|
|
{
|
|
if (typeFormationDTO == null)
|
|
return null;
|
|
TypeFormation typeFormation = new TypeFormation()
|
|
{
|
|
Id = typeFormationDTO.Id.Value,
|
|
Libelle = typeFormationDTO.Libelle
|
|
};
|
|
return typeFormation;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|