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.
143 lines
4.6 KiB
143 lines
4.6 KiB
using EPAServeur.Context;
|
|
using EPAServeur.IServices;
|
|
using EPAServeur.Models.Notes;
|
|
using IO.Swagger.DTO;
|
|
using IO.Swagger.ModelCollaborateur;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EPAServeur.Services
|
|
{
|
|
public class NoteService : INoteService
|
|
{
|
|
private readonly ICollaborateurService collaborateurService;
|
|
private readonly EpContext context;
|
|
|
|
public NoteService(ICollaborateurService _collaborateurService, EpContext _context)
|
|
{
|
|
collaborateurService = _collaborateurService;
|
|
context = _context;
|
|
}
|
|
|
|
public bool AjouterNote(DetailsNoteDTO nouvelleNote)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public IEnumerable<AffichageNoteDTO> GetNotesByCollaborateur(Guid? idAuteur, Guid? idCollaborateur, bool? asc, int? numPage, int? parPage, string texte, string tri)
|
|
{
|
|
if (collaborateurService.GetProfilById(idAuteur) == null || collaborateurService.GetProfilById(idCollaborateur) == null)
|
|
return null;
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
int skip = (numPage.Value - 1) * parPage.Value;
|
|
int take = parPage.Value;
|
|
IEnumerable<AffichageNoteDTO> AffichageNoteDTO = (from n in context.Note
|
|
where n.IdAuteur == idAuteur && n.IdCollaborateur == idCollaborateur
|
|
select NoteToAffichageDTO(n, collaborateurService));
|
|
AffichageNoteDTO = (from a in AffichageNoteDTO
|
|
where a.Collaborateur.ToLower().Contains(texte) || a.Titre.ToLower().Contains(texte)
|
|
select a).Skip(skip).Take(take);
|
|
return AffichageNoteDTO;
|
|
}
|
|
|
|
public DetailsNoteDTO GetNoteById(int? idNote)
|
|
{
|
|
DetailsNoteDTO details = NoteToDetailSDTO(context.Note.Where(c => c.Id == idNote).FirstOrDefault());
|
|
return details;
|
|
/*return (from n in context.Note
|
|
where n.Id == idNote
|
|
select NoteToDetailSDTO(n)).ToList().FirstOrDefault();*/
|
|
}
|
|
|
|
public IEnumerable<AffichageNoteDTO> GetNotes(bool? asc, int? numPage, int? parPage, string texte, string tri)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public IEnumerable<AffichageNoteDTO> GetNotesByAuteur(Guid? idAuteur, bool? asc, int? numPage, int? parPage, string texte, string tri)
|
|
{
|
|
if (collaborateurService.GetCollaborateurById(idAuteur) == null)
|
|
return null;
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
int skip = (numPage.Value - 1) * parPage.Value;
|
|
int take = parPage.Value;
|
|
//Stopwatch stopwatch = new Stopwatch();
|
|
//stopwatch.Start();
|
|
IEnumerable<AffichageNoteDTO> AffichageNoteDTO = (from n in context.Note
|
|
where n.IdAuteur == idAuteur
|
|
select NoteToAffichageDTO(n, collaborateurService));
|
|
//stopwatch.Stop();
|
|
//Console.WriteLine("Durée d'exécution numéro 1: {0}", stopwatch.Elapsed.TotalSeconds);
|
|
//stopwatch.Restart();
|
|
AffichageNoteDTO = (from a in AffichageNoteDTO
|
|
where a.Collaborateur.ToLower().Contains(texte) || a.Titre.ToLower().Contains(texte)
|
|
select a).Skip(skip).Take(take);
|
|
//stopwatch.Stop();
|
|
//Console.WriteLine("Durée d'exécution numéro 2: {0}", stopwatch.Elapsed.TotalSeconds);
|
|
return AffichageNoteDTO;
|
|
}
|
|
|
|
public bool SupprimerNote(int? idNote)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void UpdateNote(int? idNote, DetailsNoteDTO note)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
//Object to DTO
|
|
private static AffichageNoteDTO NoteToAffichageDTO(Note note, ICollaborateurService collaborateurService)
|
|
{
|
|
CollaborateurDTO collaborateur = collaborateurService.GetCollaborateurById(note.IdCollaborateur);
|
|
AffichageNoteDTO affichage = new AffichageNoteDTO()
|
|
{
|
|
Id = note.Id,
|
|
IdCollaborateur = note.IdCollaborateur,
|
|
Collaborateur = collaborateur.Prenom + collaborateur.Nom,
|
|
Titre = note.Titre,
|
|
DateMiseAjour = note.DateUpdate
|
|
};
|
|
return affichage;
|
|
}
|
|
|
|
private DetailsNoteDTO NoteToDetailSDTO(Note note)
|
|
{
|
|
DetailsNoteDTO details = new DetailsNoteDTO()
|
|
{
|
|
Id = note.Id,
|
|
DateCreation = note.DateCreation,
|
|
DateMiseAjour = note.DateUpdate,
|
|
Titre = note.Titre,
|
|
Texte = note.Texte,
|
|
IdAuteur = note.IdAuteur,
|
|
Collaborateur = collaborateurService.GetCollaborateurById(note.IdCollaborateur)
|
|
};
|
|
return details;
|
|
}
|
|
|
|
//DTO to Object
|
|
private Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO)
|
|
{
|
|
Note note = new Note()
|
|
{
|
|
IdAuteur = detailsNoteDTO.IdAuteur.Value,
|
|
IdCollaborateur = detailsNoteDTO.Collaborateur.Id.Value,
|
|
Texte = detailsNoteDTO.Texte,
|
|
Titre = detailsNoteDTO.Titre,
|
|
DateCreation = DateTime.Now
|
|
};
|
|
return note;
|
|
}
|
|
}
|
|
}
|
|
|