|
|
|
@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
namespace EPAServeur.Services |
|
|
|
|
{ |
|
|
|
@ -51,6 +52,25 @@ namespace EPAServeur.Services |
|
|
|
|
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) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
return GetFormationDTO(formation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupérer la liste des formations |
|
|
|
|
/// </summary> |
|
|
|
@ -113,6 +133,68 @@ namespace EPAServeur.Services |
|
|
|
|
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, 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) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
formations = await epContext.Formation.Include(formation => formation.Statut) |
|
|
|
|
.Include(formation => formation.ModeFormation) |
|
|
|
|
.Include(formation => formation.Origine) |
|
|
|
|
.Include(formation => formation.TypeFormation).ToListAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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> |
|
|
|
@ -157,6 +239,50 @@ namespace EPAServeur.Services |
|
|
|
|
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> |
|
|
|
@ -221,6 +347,70 @@ namespace EPAServeur.Services |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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> |
|
|
|
@ -275,6 +465,60 @@ namespace EPAServeur.Services |
|
|
|
|
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) |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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> |
|
|
|
@ -300,6 +544,31 @@ namespace EPAServeur.Services |
|
|
|
|
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; |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
modeFormations = await epContext.ModeFormation.ToListAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (modeFormations == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); |
|
|
|
|
|
|
|
|
|
return modeFormationDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupérer les origines de formation |
|
|
|
|
/// </summary> |
|
|
|
@ -326,6 +595,32 @@ namespace EPAServeur.Services |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
origineFormations = await epContext.OrigineFormation.ToListAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (origineFormations == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); |
|
|
|
|
|
|
|
|
|
return origineFormationDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupérer les statuts de formation |
|
|
|
|
/// </summary> |
|
|
|
@ -353,6 +648,33 @@ namespace EPAServeur.Services |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
statutFormations = await epContext.StatutFormation.ToListAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (statutFormations == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); |
|
|
|
|
|
|
|
|
|
return statutFormationDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupérer les types de formation |
|
|
|
|
/// </summary> |
|
|
|
@ -379,6 +701,32 @@ namespace EPAServeur.Services |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
typeFormations = await epContext.TypeFormation.ToListAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (typeFormations == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); |
|
|
|
|
|
|
|
|
|
return typeFormationDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Ajouter une formation |
|
|
|
|
/// </summary> |
|
|
|
@ -411,6 +759,38 @@ namespace EPAServeur.Services |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
await epContext.SaveChangesAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return GetFormationDTO(formation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Modifier une formation |
|
|
|
|
/// </summary> |
|
|
|
@ -419,6 +799,11 @@ namespace EPAServeur.Services |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO) |
|
|
|
|
{ |
|
|
|
|
if (formationDTO == null && !formationDTO.Id.HasValue && formationDTO.Id.Value != idFormation) |
|
|
|
|
{ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Formation formation = epContext.Formation.Find(idFormation); |
|
|
|
|
|
|
|
|
|
if (formation == null) |
|
|
|
@ -439,6 +824,39 @@ namespace EPAServeur.Services |
|
|
|
|
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 (formationDTO == null && !formationDTO.Id.HasValue && formationDTO.Id.Value != idFormation) |
|
|
|
|
{ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Formation formation = await epContext.Formation.FindAsync(idFormation); |
|
|
|
|
|
|
|
|
|
if (formation == null) |
|
|
|
|
{ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
formation = SetFormation(formation, formationDTO); |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
await epContext.SaveChangesAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return GetFormationDTO(formation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Supprimer une formation |
|
|
|
|
/// </summary> |
|
|
|
@ -465,6 +883,31 @@ namespace EPAServeur.Services |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Supprimer une formation de manière asynchrone |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="idFormation"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<bool> DeleteFormationByIdAsync(long? idFormation) |
|
|
|
|
{ |
|
|
|
|
Formation formation = await epContext.Formation.FindAsync(idFormation); |
|
|
|
|
|
|
|
|
|
if (formation == null) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
epContext.Remove(formation); |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
await epContext.SaveChangesAsync(); |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Méthodes Privée |
|
|
|
|