Merge avec la branche notes et résolution des conflits

develop
Yanaël GRETTE 4 years ago
commit 4e7c474b0b
  1. 127
      Context/EpContext.cs
  2. 170
      Controllers/NotesApi.cs
  3. 22
      IServices/INoteService.cs
  4. 6
      Models/Notes/Note.cs
  5. 2
      Properties/launchSettings.json
  6. 171
      Services/NoteService.cs
  7. 4
      Startup.cs

@ -820,5 +820,132 @@ namespace EPAServeur.Context
this.SaveChanges();
}
public void AjouterNotes()
{
Note note;
note = new Note()
{
Id = 1,
Titre = "Titre1",
Texte = "Texte1",
IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 2,
Titre = "Titre2",
Texte = "Texte2",
IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 3,
Titre = "Titre3",
Texte = "Texte3",
IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 4,
Titre = "Titre4",
Texte = "Texte4",
IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 5,
Titre = "Titre5",
Texte = "Texte5",
IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 6,
Titre = "Titre6",
Texte = "Texte6",
IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"),
IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 7,
Titre = "Titre7",
Texte = "Texte7",
IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"),
IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 8,
Titre = "Titre8",
Texte = "Texte8",
IdAuteur = new Guid("571463f3-b286-4a21-9eab-0707dc506dec"),
IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 9,
Titre = "Titre9",
Texte = "Texte9",
IdAuteur = new Guid("571463f3-b286-4a21-9eab-0707dc506dec"),
IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
note = new Note()
{
Id = 10,
Titre = "Titre10",
Texte = "Texte10",
IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"),
IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now,
DateUpdate = DateTime.Now
};
this.Note.Add(note);
this.SaveChanges();
}
}
}

@ -4,7 +4,7 @@
* API qui sra utilisée afin de faire communiquer le client et le serveur ainsi que le serveur et la boîte noire.
*
* OpenAPI spec version: 1.3.4
*
*
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
using System;
@ -18,17 +18,27 @@ using IO.Swagger.Attributes;
using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization;
using IO.Swagger.DTO;
using EPAServeur.Services;
using EPAServeur.IServices;
using EPAServeur.Models.Notes;
namespace IO.Swagger.Controllers
{
{
/// <summary>
///
///
/// </summary>
[ApiController]
public class NotesApiController : ControllerBase
{
{
private readonly INoteService noteService;
public NotesApiController(INoteService _noteService)
{
noteService = _noteService;
}
/// <summary>
///
///
/// </summary>
/// <remarks>Supprimer une note</remarks>
/// <param name="idNote">id note</param>
@ -37,27 +47,29 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpDelete]
[Route("/api/notes/{idNote}/supprimer")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("DeleteNote")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult DeleteNote([FromRoute][Required]long? idNote)
{
//TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(204);
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
throw new NotImplementedException();
if(!noteService.SupprimerNote(idNote))
{
ErreurDTO erreur = new ErreurDTO()
{
Code = "404",
Message = "Aucune note trouvé"
};
return NotFound(erreur);
};
return NoContent();
}
/// <summary>
///
///
/// </summary>
/// <remarks>Récupérer une note par son id</remarks>
/// <param name="idNote">id note</param>
@ -66,33 +78,31 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/notes/{idNote}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetNoteById")]
[SwaggerResponse(statusCode: 200, type: typeof(DetailsNoteDTO), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetNoteById([FromRoute][Required]long? idNote)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200, default(DetailsNoteDTO));
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
string exampleJson = null;
exampleJson = "{\n \"idAuteur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"texte\" : \"texte\",\n \"id\" : 0,\n \"collaborateur\" : {\n \"businessUnit\" : {\n \"agence\" : {\n \"bu\" : [ null, null ],\n \"id\" : 6,\n \"nom\" : \"nom\"\n },\n \"id\" : 0,\n \"nom\" : \"nom\"\n },\n \"referent\" : {\n \"mailApside\" : \"\",\n \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"nom\" : \"nom\",\n \"prenom\" : \"prenom\",\n \"collaborateurs\" : [ null, null ]\n },\n \"mailApside\" : \"\",\n \"dateArrivee\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateDepart\" : \"2000-01-23T04:56:07.000+00:00\",\n \"nom\" : \"nom\",\n \"prenom\" : \"prenom\"\n }\n}";
var example = exampleJson != null
? JsonConvert.DeserializeObject<DetailsNoteDTO>(exampleJson)
: default(DetailsNoteDTO); //TODO: Change the data returned
return new ObjectResult(example);
DetailsNoteDTO note = noteService.GetNoteById(idNote);
if(note == null)
{
ErreurDTO erreur = new ErreurDTO()
{
Code = "404",
Message = "Aucune note n'a été trouvée"
};
return NotFound(erreur);
}
return Ok(note);
}
/// <summary>
///
///
/// </summary>
/// <remarks>Récupérer toutes les notes</remarks>
/// <param name="asc">Préciser si les données sont dans l&#x27;ordre (true) ou dans l&#x27;ordre inverse (false)</param>
@ -110,7 +120,7 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetNotes([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [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(..), ...
// return StatusCode(200, default(List<AffichageNoteDTO>));
@ -118,7 +128,7 @@ namespace IO.Swagger.Controllers
// return StatusCode(403, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n}, {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<AffichageNoteDTO>>(exampleJson)
: default(List<AffichageNoteDTO>); //TODO: Change the data returned
@ -126,7 +136,7 @@ namespace IO.Swagger.Controllers
}
/// <summary>
///
///
/// </summary>
/// <remarks>Récupérer les notes d&#x27;une personne a écrite</remarks>
/// <param name="asc">Préciser si les données sont dans l&#x27;ordre (true) ou dans l&#x27;ordre inverse (false)</param>
@ -140,33 +150,31 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/notes/auteur/{idReferent}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetNotesByAuteur")]
[SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetNotesByAuteur([FromQuery][Required()]bool? asc, [FromRoute][Required]Guid? idReferent, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [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(..), ...
// return StatusCode(200, default(List<AffichageNoteDTO>));
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n}, {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<AffichageNoteDTO>>(exampleJson)
: default(List<AffichageNoteDTO>); //TODO: Change the data returned
return new ObjectResult(example);
IEnumerable<AffichageNoteDTO> notes = noteService.GetNotesByAuteur(idReferent, asc, numPage, parPAge, texte, tri);
if(notes == null)
{
ErreurDTO erreur = new ErreurDTO()
{
Code = "404",
Message = "Aucun id ne correspond au référent"
};
return NotFound(erreur);
}
return Ok(notes);
}
/// <summary>
///
///
/// </summary>
/// <remarks>Récupérer une note par son id</remarks>
/// <param name="asc">Préciser si les données sont dans l&#x27;ordre (true) ou dans l&#x27;ordre inverse (false)</param>
@ -181,33 +189,31 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/notes/auteur/{idReferent}/collaborateur/{idCollaborateur}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetNotesByCollaborateur")]
[SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetNotesByCollaborateur([FromQuery][Required()]bool? asc, [FromRoute][Required]Guid? idCollaborateur, [FromRoute][Required]Guid? idReferent, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [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(..), ...
// return StatusCode(200, default(List<AffichageNoteDTO>));
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n}, {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<AffichageNoteDTO>>(exampleJson)
: default(List<AffichageNoteDTO>); //TODO: Change the data returned
return new ObjectResult(example);
IEnumerable<AffichageNoteDTO> notes = noteService.GetNotesByCollaborateur(idReferent, idCollaborateur, asc, numPage, parPAge, texte, tri);
if (notes == null)
{
ErreurDTO erreur = new ErreurDTO()
{
Code = "404",
Message = "Aucun id ne correspond au référent et/ou au collaborateur"
};
return NotFound(erreur);
}
return Ok(notes);
}
/// <summary>
///
///
/// </summary>
/// <remarks>Ajouter une nouvelle note</remarks>
/// <param name="body"></param>
@ -215,23 +221,20 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpPost]
[Route("/api/notes/nouvellenote")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("NouvelleNote")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult NouvelleNote([FromBody]DetailsNoteDTO body)
{
//TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(201);
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
throw new NotImplementedException();
Note nouvelleNote = noteService.AjouterNote(body);
return Created("",nouvelleNote);
}
/// <summary>
///
///
/// </summary>
/// <remarks>Mettre à jour une note</remarks>
/// <param name="body"></param>
@ -241,22 +244,21 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpPut]
[Route("/api/notes/{idNote}/updateNote")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("UpdateNote")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult UpdateNote([FromBody]DetailsNoteDTO body, [FromRoute][Required]long? idNote)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200);
//TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(201);
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
throw new NotImplementedException();
Note note = noteService.UpdateNote(idNote, body);
if (note == null)
note = noteService.AjouterNote(body);
return Ok(note);
//TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(201);
}
}
}

@ -0,0 +1,22 @@
using EPAServeur.Models.Notes;
using IO.Swagger.DTO;
using Org.BouncyCastle.Bcpg.OpenPgp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.IServices
{
public interface INoteService
{
//bool? asc, int? numPage, int? parPAge, string texte, string tri)
public IEnumerable<AffichageNoteDTO> GetNotes(bool? asc, int? numPage, int? parPAge, string texte, string tri);
public IEnumerable<AffichageNoteDTO> GetNotesByAuteur(Guid? idAuteur, bool? asc, int? numPage, int? parPAge, string texte, string tri);
public DetailsNoteDTO GetNoteById(long? idNote);
public IEnumerable<AffichageNoteDTO> GetNotesByCollaborateur(Guid? idAuteur, Guid? idCollaborateur, bool? asc, int? numPage, int? parPAge, string texte, string tri);
public Note AjouterNote(DetailsNoteDTO nouvelleNote);
public bool SupprimerNote(long? idNote);
public Note UpdateNote(long? idNote, DetailsNoteDTO note);
}
}

@ -10,7 +10,9 @@ namespace EPAServeur.Models.Notes
public long Id { get; set; }
public string Titre { get; set; }
public string Texte { get; set; }
public string IdAuteur { get; set; }
public string IdCollaborateur { get; set; }
public Guid IdAuteur { get; set; }
public Guid IdCollaborateur { get; set; }
public DateTime DateCreation { get; set; }
public DateTime DateUpdate { get; set; }
}
}

@ -12,7 +12,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/collaborateurs/59a8becb-bc0a-4d3d-adb1-8a8bd13c48c9",
"launchUrl": "api/notes/1",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

@ -0,0 +1,171 @@
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 Note AjouterNote(DetailsNoteDTO nouvelleNote)
{
if (!IsDetailsNoteValide(nouvelleNote))
return null;
Note note = DetailsNoteDTOToNouvelleNote(nouvelleNote);
context.Note.Add(note);
context.SaveChanges();
return note;
}
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(long? idNote)
{
Note note = context.Note.Find(idNote);
if (note == null)
return null;
return NoteToDetailSDTO(note);
/*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(long? idNote)
{
Note note = context.Note.Find(idNote);
if (note == null)
return false;
context.Remove(note);
context.SaveChanges();
return true;
}
public Note UpdateNote(long? idNote, DetailsNoteDTO note)
{
if (!IsDetailsNoteValide(note))
return null;
Note noteToUpdate = context.Note.Find(idNote);
if (noteToUpdate == null)
return AjouterNote(note);
noteToUpdate.Titre = note.Titre;
noteToUpdate.Texte = note.Texte;
noteToUpdate.DateUpdate = DateTime.Now;
context.SaveChanges();
return noteToUpdate;
}
private bool IsDetailsNoteValide(DetailsNoteDTO note)
{
return !(note == null || note.IdAuteur == null || note.Collaborateur == null || note.Collaborateur.Id == null || note.Titre == null || note.Texte == null) ;
}
//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,
DateUpdate = DateTime.Now
};
return note;
}
}
}

@ -43,6 +43,7 @@ namespace EPAServeur
context.SaveChanges();
context.AjoutInformationsDeBase();
context.AjoutChamps();
context.AjouterNotes();
}
//faire using, check si kekchoz exkist puis appeler les méthodes de création si il n'y a rien
@ -51,8 +52,11 @@ namespace EPAServeur
services.AddScoped<IAgenceApi, AgenceApi>();
services.AddScoped<IRfrentApi, RfrentApi>();
//Services
services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<INoteService, NoteService>();
}

Loading…
Cancel
Save