Ajout des méthodes asynchrones et modification du DTO FormationDetailsDTO

develop
jboinembalome 4 years ago
parent 2144a10458
commit 13c4fb74fd
  1. 63
      Controllers/FormationsApi.cs
  2. 7
      DTO/FormationDetailsDTO.cs
  3. 14
      IServices/IFormationService.cs
  4. 443
      Services/FormationService.cs

@ -17,6 +17,7 @@ using IO.Swagger.Attributes;
using IO.Swagger.DTO; using IO.Swagger.DTO;
using EPAServeur.IServices; using EPAServeur.IServices;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
namespace IO.Swagger.Controllers namespace IO.Swagger.Controllers
{ {
@ -46,9 +47,9 @@ namespace IO.Swagger.Controllers
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("AjouterFormation")] [SwaggerOperation("AjouterFormation")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult AjouterFormation([FromBody] FormationDTO body) public virtual async Task<IActionResult> AjouterFormation([FromBody] FormationDTO body)
{ {
FormationDTO nouvelleFormation = formationService.AddFormation(body); FormationDTO nouvelleFormation = await formationService.AddFormationAsync(body);
return Created("", nouvelleFormation); return Created("", nouvelleFormation);
} }
@ -66,9 +67,9 @@ namespace IO.Swagger.Controllers
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("DeleteFormation")] [SwaggerOperation("DeleteFormation")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult DeleteFormation([FromRoute][Required] long? idFormation) public virtual async Task<IActionResult> DeleteFormation([FromRoute][Required] long? idFormation)
{ {
if (!formationService.DeleteFormationById(idFormation)) if ( ! await formationService.DeleteFormationByIdAsync(idFormation))
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
{ {
@ -102,10 +103,10 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetFormationAnnulees([FromQuery][Required()] bool? asc, [FromQuery][Required()] int? numPage, [FromQuery][Required()] int? parPAge, [FromQuery] int? idAgence, [FromQuery] string texte, [FromQuery] string tri) public virtual async Task<IActionResult> GetFormationAnnulees([FromQuery][Required()] bool? asc, [FromQuery][Required()] int? numPage, [FromQuery][Required()] int? parPAge, [FromQuery] int? idAgence, [FromQuery] string texte, [FromQuery] string tri)
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<FormationDTO> formations = formationService.GetFormationAnnulees(asc, numPage, parPAge, idAgence, texte, tri); IEnumerable<FormationDTO> formations = await formationService.GetFormationAnnuleesAsync(asc, numPage, parPAge, idAgence, texte, tri);
if (formations == null) if (formations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -135,9 +136,9 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 200, type: typeof(FormationDTO), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(FormationDTO), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetFormationById([FromRoute][Required] long? idFormation) public virtual async Task<IActionResult> GetFormationById([FromRoute][Required] long? idFormation)
{ {
FormationDTO formationDTO = formationService.GetFormationById(Convert.ToInt32(idFormation)); FormationDTO formationDTO = await formationService.GetFormationByIdAsync(idFormation);
if (formationDTO == null) if (formationDTO == null)
{ {
ErreurDTO erreurDTO = new ErreurDTO() ErreurDTO erreurDTO = new ErreurDTO()
@ -171,10 +172,10 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetFormationRealisee([FromQuery][Required()] bool? asc, [FromQuery][Required()] int? numPage, [FromQuery][Required()] int? parPAge, [FromQuery] int? idAgence, [FromQuery] string texte, [FromQuery] string tri) public virtual async Task<IActionResult> GetFormationRealisee([FromQuery][Required()] bool? asc, [FromQuery][Required()] int? numPage, [FromQuery][Required()] int? parPAge, [FromQuery] int? idAgence, [FromQuery] string texte, [FromQuery] string tri)
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<FormationDTO> formations = formationService.GetFormationRealisee(asc, numPage, parPAge, idAgence, texte, tri); IEnumerable<FormationDTO> formations = await formationService.GetFormationRealiseeAsync(asc, numPage, parPAge, idAgence, texte, tri);
if (formations == null) if (formations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -209,10 +210,10 @@ namespace IO.Swagger.Controllers
[SwaggerOperation("GetFormations")] [SwaggerOperation("GetFormations")]
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetFormations([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]int? idAgence, [FromQuery]int? statutFormation, [FromQuery]string texte, [FromQuery]string tri) public virtual async Task<IActionResult> GetFormations([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]int? idAgence, [FromQuery]int? statutFormation, [FromQuery]string texte, [FromQuery]string tri)
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<FormationDTO> formations = formationService.GetFormations(asc, numPage, parPAge, idAgence, texte, tri); IEnumerable<FormationDTO> formations = await formationService.GetFormationsAsync(asc, numPage, parPAge, idAgence, texte, tri);
if (formations == null) if (formations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -239,10 +240,10 @@ namespace IO.Swagger.Controllers
[SwaggerOperation("GetModesFormation")] [SwaggerOperation("GetModesFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<ModeFormationDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<ModeFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetModesFormation() public virtual async Task<IActionResult> GetModesFormation()
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<ModeFormationDTO> modeFormations = formationService.GetModesFormation(); IEnumerable<ModeFormationDTO> modeFormations = await formationService.GetModesFormationAsync();
if (modeFormations == null) if (modeFormations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -269,10 +270,10 @@ namespace IO.Swagger.Controllers
[SwaggerOperation("GetOriginesFormation")] [SwaggerOperation("GetOriginesFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<OrigineFormationDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<OrigineFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetOriginesFormation() public virtual async Task<IActionResult> GetOriginesFormation()
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<OrigineFormationDTO> origineFormations = formationService.GetOriginesFormation(); IEnumerable<OrigineFormationDTO> origineFormations = await formationService.GetOriginesFormationAsync();
if (origineFormations == null) if (origineFormations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -307,10 +308,10 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetProchainesFormation([FromQuery][Required()] bool? asc, [FromQuery][Required()] int? numPage, [FromQuery][Required()] int? parPAge, [FromQuery] int? idAgence, [FromQuery] string texte, [FromQuery] string tri) public virtual async Task<IActionResult> GetProchainesFormation([FromQuery][Required()] bool? asc, [FromQuery][Required()] int? numPage, [FromQuery][Required()] int? parPAge, [FromQuery] int? idAgence, [FromQuery] string texte, [FromQuery] string tri)
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<FormationDTO> formations = formationService.GetProchainesFormation(asc, numPage, parPAge, idAgence, texte, tri); IEnumerable<FormationDTO> formations = await formationService.GetProchainesFormationAsync(asc, numPage, parPAge, idAgence, texte, tri);
if (formations == null) if (formations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -337,10 +338,10 @@ namespace IO.Swagger.Controllers
[SwaggerOperation("GetStatutsFormation")] [SwaggerOperation("GetStatutsFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<StatutFormationDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<StatutFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetStatutsFormation() public virtual async Task<IActionResult> GetStatutsFormation()
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<StatutFormationDTO> statutFormations = formationService.GetStatutsFormation(); IEnumerable<StatutFormationDTO> statutFormations = await formationService.GetStatutsFormationAsync();
if (statutFormations == null) if (statutFormations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -367,10 +368,10 @@ namespace IO.Swagger.Controllers
[SwaggerOperation("GetTypesFormation")] [SwaggerOperation("GetTypesFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<TypeFormationDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<TypeFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetTypesFormation() public virtual async Task<IActionResult> GetTypesFormation()
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
IEnumerable<TypeFormationDTO> typeFormations = formationService.GetTypesFormation(); IEnumerable<TypeFormationDTO> typeFormations = await formationService.GetTypesFormationAsync();
if (typeFormations == null) if (typeFormations == null)
{ {
ErreurDTO erreur = new ErreurDTO() ErreurDTO erreur = new ErreurDTO()
@ -399,29 +400,15 @@ namespace IO.Swagger.Controllers
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("UpdateFormation")] [SwaggerOperation("UpdateFormation")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult UpdateFormation([FromBody] FormationDTO body, [FromRoute][Required] long? idFormation) public virtual async Task<IActionResult> UpdateFormation([FromBody] FormationDTO body, [FromRoute][Required] long? idFormation)
{ {
FormationDTO formation = formationService.UpdateFormation(idFormation, body); FormationDTO formation = await formationService.UpdateFormationAsync(idFormation, body);
if (formation == null) if (formation == null)
{ {
formation = formationService.AddFormation(body); formation = formationService.AddFormation(body);
return Created("", formation); return Created("", formation);
} }
return Ok(formation); return Ok(formation);
//switch (formationService.UpdateFormation(body))
//{
// case 0:
// return Ok();
// case 1:
// return StatusCode(201);
// case 2:
// return Forbid();
// default:
// return NotFound();
//}
} }
} }
} }

@ -66,6 +66,13 @@ namespace IO.Swagger.DTO
[DataMember(Name="nbPartitipants")] [DataMember(Name="nbPartitipants")]
public int? NbPartitipants { get; set; } public int? NbPartitipants { get; set; }
/// <summary>
/// Gets or Sets Origine
/// </summary>
[Required]
[DataMember(Name = "origine")]
public OrigineFormationDTO Origine { get; set; }
/// <summary> /// <summary>
/// Gets or Sets Mode /// Gets or Sets Mode
/// </summary> /// </summary>

@ -11,18 +11,30 @@ namespace EPAServeur.IServices
public interface IFormationService public interface IFormationService
{ {
FormationDTO GetFormationById(long? idFormation); FormationDTO GetFormationById(long? idFormation);
Task<FormationDTO> GetFormationByIdAsync(long? idFormation);
IEnumerable<FormationDTO> GetFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); IEnumerable<FormationDTO> GetFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetFormationsAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
IEnumerable<FormationDTO> GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); IEnumerable<FormationDTO> GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetFormationAnnuleesAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
IEnumerable<FormationDTO> GetFormationRealisee(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); IEnumerable<FormationDTO> GetFormationRealisee(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetFormationRealiseeAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
IEnumerable<FormationDTO> GetProchainesFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); IEnumerable<FormationDTO> GetProchainesFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetProchainesFormationAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri);
IEnumerable<ModeFormationDTO> GetModesFormation(); IEnumerable<ModeFormationDTO> GetModesFormation();
Task<IEnumerable<ModeFormationDTO>> GetModesFormationAsync();
IEnumerable<OrigineFormationDTO> GetOriginesFormation(); IEnumerable<OrigineFormationDTO> GetOriginesFormation();
Task<IEnumerable<OrigineFormationDTO>> GetOriginesFormationAsync();
IEnumerable<StatutFormationDTO> GetStatutsFormation(); IEnumerable<StatutFormationDTO> GetStatutsFormation();
Task<IEnumerable<StatutFormationDTO>> GetStatutsFormationAsync();
IEnumerable<TypeFormationDTO> GetTypesFormation(); IEnumerable<TypeFormationDTO> GetTypesFormation();
Task<IEnumerable<TypeFormationDTO>> GetTypesFormationAsync();
FormationDTO AddFormation(FormationDTO formationDTO); FormationDTO AddFormation(FormationDTO formationDTO);
Task<FormationDTO> AddFormationAsync(FormationDTO formationDTO);
FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO); FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO);
Task<FormationDTO> UpdateFormationAsync(long? idFormation, FormationDTO formationDTO);
bool DeleteFormationById(long? idFormation); bool DeleteFormationById(long? idFormation);
Task<bool> DeleteFormationByIdAsync(long? idFormation);
} }
} }

@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Services namespace EPAServeur.Services
{ {
@ -51,6 +52,25 @@ namespace EPAServeur.Services
return GetFormationDTO(formation); 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> /// <summary>
/// Récupérer la liste des formations /// Récupérer la liste des formations
/// </summary> /// </summary>
@ -113,6 +133,68 @@ namespace EPAServeur.Services
return formationDTOs; 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&#x27;ordre (true) ou dans l&#x27;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&#x27;éléments affiché sur chaque page du tableau</param>
/// <param name="idAgence">id de l&#x27;agence à laquelle sont rattachées les données à récupérer</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;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> /// <summary>
/// Récupérer les formations annulées /// Récupérer les formations annulées
/// </summary> /// </summary>
@ -157,6 +239,50 @@ namespace EPAServeur.Services
return formationDTOs; 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&#x27;ordre (true) ou dans l&#x27;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&#x27;éléments affiché sur chaque page du tableau</param>
/// <param name="idAgence">id de l&#x27;agence à laquelle sont rattachées les données à récupérer</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;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> /// <summary>
/// Récupérer les formations réalisées /// Récupérer les formations réalisées
/// </summary> /// </summary>
@ -221,6 +347,70 @@ namespace EPAServeur.Services
return formationDTOs; 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&#x27;ordre (true) ou dans l&#x27;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&#x27;éléments affiché sur chaque page du tableau</param>
/// <param name="idAgence">id de l&#x27;agence à laquelle sont rattachées les données à récupérer</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;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> /// <summary>
/// Récupérer les formations plannifiées et replannifiées /// Récupérer les formations plannifiées et replannifiées
/// </summary> /// </summary>
@ -275,6 +465,60 @@ namespace EPAServeur.Services
return formationDTOs; 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&#x27;ordre (true) ou dans l&#x27;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&#x27;éléments affiché sur chaque page du tableau</param>
/// <param name="idAgence">id de l&#x27;agence à laquelle sont rattachées les données à récupérer</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;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> /// <summary>
/// Récupérer les modes de formation /// Récupérer les modes de formation
/// </summary> /// </summary>
@ -300,6 +544,31 @@ namespace EPAServeur.Services
return modeFormationDTOs; 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> /// <summary>
/// Récupérer les origines de formation /// Récupérer les origines de formation
/// </summary> /// </summary>
@ -326,6 +595,32 @@ namespace EPAServeur.Services
return origineFormationDTOs; 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> /// <summary>
/// Récupérer les statuts de formation /// Récupérer les statuts de formation
/// </summary> /// </summary>
@ -353,6 +648,33 @@ namespace EPAServeur.Services
return statutFormationDTOs; 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> /// <summary>
/// Récupérer les types de formation /// Récupérer les types de formation
/// </summary> /// </summary>
@ -379,6 +701,32 @@ namespace EPAServeur.Services
return typeFormationDTOs; 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> /// <summary>
/// Ajouter une formation /// Ajouter une formation
/// </summary> /// </summary>
@ -411,6 +759,38 @@ namespace EPAServeur.Services
return GetFormationDTO(formation); 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> /// <summary>
/// Modifier une formation /// Modifier une formation
/// </summary> /// </summary>
@ -419,6 +799,11 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
public FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO) 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); Formation formation = epContext.Formation.Find(idFormation);
if (formation == null) if (formation == null)
@ -439,6 +824,39 @@ namespace EPAServeur.Services
return GetFormationDTO(formation); 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> /// <summary>
/// Supprimer une formation /// Supprimer une formation
/// </summary> /// </summary>
@ -465,6 +883,31 @@ namespace EPAServeur.Services
return true; 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 #endregion
#region Méthodes Privée #region Méthodes Privée

Loading…
Cancel
Save