diff --git a/.drone.yml b/.drone.yml
new file mode 100644
index 0000000..894663d
--- /dev/null
+++ b/.drone.yml
@@ -0,0 +1,82 @@
+kind: pipeline
+type: docker
+name: CI_ApiPm
+
+trigger:
+ event:
+ - push
+ branch:
+ exclude:
+ - master
+
+steps:
+ - name: retore & build
+ image: mcr.microsoft.com/dotnet/sdk:8.0
+ commands:
+ - dotnet build WF_EF_Api/WF_EF_Api.sln --configuration Release
+ depend_on: [clone]
+
+ - name: test
+ image: mcr.microsoft.com/dotnet/sdk:8.0
+ commands:
+ - dotnet test WF_EF_Api/XUnitTest/XUnitTest.csproj
+ depends_on: [retore & build]
+
+ - name: publish
+ image: mcr.microsoft.com/dotnet/sdk:8.0
+ commands:
+ - dotnet publish WF_EF_Api/WfApi/WfApi.csproj -c Release -o out
+ depends_on: [retore & build, test]
+
+---
+
+kind: pipeline
+type: docker
+name: CI_ApiPm_Master
+
+trigger:
+ event:
+ - push
+ branch:
+ - master
+
+volumes:
+ - name: doc
+ temp: {}
+
+
+steps:
+ - name: retore & build
+ image: mcr.microsoft.com/dotnet/sdk:8.0
+ commands:
+ - dotnet build --configuration Release
+ depend_on: [clone]
+
+ - name: test
+ image: mcr.microsoft.com/dotnet/sdk:8.0
+ commands:
+ - dotnet test
+ depends_on: [retore & build]
+
+ - name: generate doc
+ image: mcr.microsoft.com/dotnet/sdk:8.0
+ volumes:
+ - name: doc
+ path: /doc
+ commands:
+ - dotnet new tool-manifest
+ - dotnet tool install NSwag.ConsoleCore
+ - dotnet restore
+ - cd WF_EF_Api/WfApi
+ - dotnet nswag aspnetcore2openapi /output:/doc/swagger.json
+ depends_on: [clone, retore & build]
+
+ #- name: code-inspection
+ # image: hub.codefirst.iut.uca.fr/marc.chevaldonne:codefirs-dronsonarplugin-dotnet8
+ # secret: [SECRET_SONAR_LOGIN]
+ # A FINIR
+ - name: publish
+ image: mcr.microsoft.com/dotnet/sdk:8.0
+ commands:
+ - dotnet publish -c Release -o out
+ depends_on: [retore & build, test]
\ No newline at end of file
diff --git a/README.md b/README.md
index 94b08a7..7cf3392 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,59 @@
# WF-PmAPI
+
+### Paquets
+NSwag.AspNetCore
+Moq
+
+🟨 En cours / ✅ Fait / ❌ Pas fait
+
+### Critères Entity Framework
+
+niveau | description | coeff | jalon | État
+--- | --- | --- | --- | ---
+☢️ | Le dépôt doit être accessible par l'enseignant | ☢️ | J1 | ✅
+☢️ | un .gitignore doit exister au premier push | ☢️ | J1 | ✅
+🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | ✅
+🎬 | le projet et le tests s'exécutent sans bug (concernant la partie persistance) | 3 | J1 & J2 | ✅
+🟢 | Transcription du modèle : Modèle vers entités (et inversement) | 2 | J1 | ✅
+🟢 | Requêtes CRUD simples (sur une table) | 1 | J1 | ✅
+🟢 | Utilisation de LINQ to Entities | 2 | J1 | ✅
+🟡 | Injection / indépendance du fournisseur | 1 | J1 | ✅
+🟡 | Requêtes CRUD sur des données complexes (images par exemple) | 2 | J1 | ✅
+🟢 | Tests - Appli Console | 1 | J1 | ✅
+🟢 | Tests - Tests unitaires (avec SQLite in memory) | 2 | J1 | ❌
+🟢 | Tests - Données stubbées et/ou Moq | 1 | J1 | ✅
+🟡 | CI : build, tests, Sonar (doc?) | 1 | J1 | ❌
+🟡 | Utilisation de relations (One-to-One, One-to-Many, Many-to-Many) (+ mapping, TU, Requêtes) | 4 | J1 | ✅
+🟢 | Liens avec le web service | 2 | J1 | ✅
+🟡 | Utilisation d'un *Logger* | 1 | J1 | ❌
+🟡 | Déploiement | 4 | J2 | ❌
+🔴 | Unit of Work❌ / Repository✅ + extras (héritage, accès concurrents...) | 8 | J2 | 🟨
+🟢 | Utilisation dans le projet | 2 | J2 | ❌
+🟢 | mon dépôt possède un readme qui apporte quelque chose... | 2 | J2 | ✅
+
+
+### Critères Web API
+
+niveau | description | coeff | jalon | État
+--- | --- | --- | --- | ---
+☢️ | Le dépôt doit être accessible par l'enseignant | ☢️ | J1 | ✅
+☢️ | un .gitignore doit exister au premier push | ☢️ | J1 | ✅
+🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | ✅
+🎬 | le projet et le tests s'exécutent sans bug (concernant la partie web api) | 4 | J1 & J2 | ✅
+🟢 | Modèle <-> DTO | 1 | J1 | ❌
+🟢 | Entities <-> DTO | 1 | J1 | ✅
+🟡 | Authentification | 4 | J1 |
+🟢 | Requêtes GET, PUT, POST, DELETE sur des données simples (1 seul type d'objet en retour, propriétés de types natifs) | 2 | J1 | ✅
+🟡 | Pagination & filtrage | 2 | J1 | ✅
+🟢 | Injection de service | 2 | J1 | ✅
+🟡 | Requêtes GET, PUT, POST, DELETE sur des données complexes (plusieurs données complexes en retour) | 4 | J1 | 🟨
+🟢 | Tests - Appli Console (consommation des requêtes) | 4 | J1 | 🟨
+🟢 | Tests - Tests unitaires (avec Stub et/ou Moq) | 2 | J1 | ❌
+🟡 | CI : build, tests, Sonar, Documentation (en particulier Swagger avec exemples...) | 1 | J1 | ❌
+🟢 | Liens avec la persistance en base de données | 4 | J1 | ✅
+🟡 | Utilisation d'un *Logger* | 1 | J1 | ❌
+🟡 | Déploiement | 4 | J2 | ❌
+🟡 | Utilisation dans le projet | 4 | J2 | ❌
+🎬 | mon dépôt possède un readme qui apporte quelque chose... | 1 | J2 | ✅
+
diff --git a/WF_EF_Api/.dockerignore b/WF_EF_Api/.dockerignore
new file mode 100644
index 0000000..4d72b4f
--- /dev/null
+++ b/WF_EF_Api/.dockerignore
@@ -0,0 +1,30 @@
+**/.classpath
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/azds.yaml
+**/bin
+**/charts
+**/docker-compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md
+!**/.gitignore
+!.git/HEAD
+!.git/config
+!.git/packed-refs
+!.git/refs/heads/**
\ No newline at end of file
diff --git a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj
new file mode 100644
index 0000000..73a6de7
--- /dev/null
+++ b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj
@@ -0,0 +1,22 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs
new file mode 100644
index 0000000..4c4c4f5
--- /dev/null
+++ b/WF_EF_Api/ConsoleTest/Program.cs
@@ -0,0 +1,134 @@
+using Contextlib;
+using Entity;
+using Microsoft.Data.Sqlite;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Options;
+using StubbedContextLib;
+using static System.Net.Mime.MediaTypeNames;
+using static System.Net.WebRequestMethods;
+
+var connection = new SqliteConnection("DataSource=:memory:");
+connection.Open();
+var options = new DbContextOptionsBuilder()
+ .UseSqlite(connection)
+ .Options;
+
+using (var _context = new StubWTFContext(options))
+{
+ _context.Database.EnsureCreated();
+
+ // ---- Test Image ---- //
+
+ var imageManager = new DbImagesManager(_context);
+
+
+ await imageManager.AddImage(new Images() { Id = 0, ImgPath = "https://www.bing.com/ck/a?!&&p=390428c2820add92760900204667aa721b17d4eb9e8537c91544d76283d06b14JmltdHM9MTc0MjQyODgwMA&ptn=3&ver=2&hsh=4&fclid=297ef5ed-ac44-66f2-2498-e058adb06776&u=a1aHR0cHM6Ly93d3cucG9rZXBlZGlhLmZyL01hamFzcGlj&ntb=1" });
+ await imageManager.AddImage(new Images() { Id = 0, ImgPath = "https://www.bing.com/images/search?view=detailV2&ccid=t57OzeAT&id=1CCCBB65825E5FB93F10CA6D29EFDBBFEB5CDF27&thid=OIP.t57OzeATZKjBDDrzXqbc5gHaE7&mediaurl=https%3a%2f%2fimg-19.commentcamarche.net%2fP51ArxVXHJKsgdTzGDaqajlWJ3s%3d%2f1500x%2fsmart%2f7b5dd43e607643fea1a61960e3f66fc4%2fccmcms-commentcamarche%2f39481621.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.b79ececde01364a8c10c3af35ea6dce6%3frik%3dJ99c67%252fb7yltyg%26pid%3dImgRaw%26r%3d0&exph=999&expw=1500&q=image&simid=608026907577902968&ck=0D54F216D075AD6E0ABC46B3AAB7E80A&selectedIndex=19&itb=0" });
+ Console.WriteLine("---- Test ajout image (id : 11, 12)");
+ var images = await imageManager.GetAllImage();
+ foreach (var image in images.items)
+ {
+ Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40)+"...")}");
+
+
+ }
+ Console.WriteLine("");
+
+
+ await imageManager.UpdateImage(12, new Images() { ImgPath = "https://testUpdate/stub"});
+ Console.WriteLine("---- Test mise a jour image (id : 12)");
+ images = await imageManager.GetAllImage();
+ foreach (var image in images.items)
+ {
+ Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}");
+ }
+ Console.WriteLine("");
+
+
+ await imageManager.RemoveImage(12);
+ Console.WriteLine("---- Test suppression image (id : 12)");
+ images = await imageManager.GetAllImage();
+ foreach (var image in images.items)
+ {
+ Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}");
+ }
+ Console.WriteLine("");
+
+
+ Console.WriteLine("---- Test getById image (id : 11)");
+ var img = await imageManager.GetImageById(11);
+ Console.WriteLine($"- ({img.Id}) : {(img.ImgPath.Length <= 40 ? img.ImgPath : img.ImgPath.Substring(0, 40) + "...")}");
+ Console.WriteLine("");
+
+
+ Console.WriteLine("---- Test getSomme image (nb : 5, page : 1)");
+ images = await imageManager.GetSomeImage(1,5);
+ foreach (var image in images.items)
+ {
+ Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}");
+ }
+ Console.WriteLine("");
+
+
+ Console.WriteLine("---- Test LastId image");
+ var id = await imageManager.GetLastImageId();
+ Console.WriteLine($"- Last image id : {id}");
+ Console.WriteLine("");
+
+ Console.WriteLine("-------------------------------------------------------------------------------");
+
+ // ---- Test Character ---- //
+
+ var characterManager = new DbCharacterManager(_context);
+
+
+ await characterManager.AddCharacter(new Character() { Id = 0, Name = "Vipélière", IdImage = 11 });
+ Console.WriteLine("---- Test ajout charcter (id : 11)");
+ var characters = await characterManager.GetAll();
+ foreach (var charac in characters.items)
+ {
+ Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}");
+ }
+ Console.WriteLine("");
+
+
+ await characterManager.UpdateCharacter(11,new Character() {Name = "Majespic"});
+ Console.WriteLine("---- Test mise a jour charcter (id : 11)");
+ characters = await characterManager.GetAll();
+ foreach (var charac in characters.items)
+ {
+ Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}");
+ }
+ Console.WriteLine("");
+
+
+ await characterManager.RemoveCharacter(11);
+ Console.WriteLine("---- Test sup (id : 5)");
+ characters = await characterManager.GetAll();
+ foreach (var charac in characters.items)
+ {
+ Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}");
+ }
+ Console.WriteLine("");
+
+
+ Console.WriteLine("---- Test GetById (id : 5)");
+ var chara = await characterManager.GetCharById(5);
+ Console.WriteLine($"- ({chara.Id}) : {chara.Name} -> {chara.IdImage} : {(chara.Images.ImgPath.Length <= 40 ? chara.Images.ImgPath : chara.Images.ImgPath.Substring(0, 40) + "...")}");
+ Console.WriteLine("");
+
+
+ Console.WriteLine("---- Test GetByName (name : Jon Snow)");
+ chara = await characterManager.GetCharByName("Jon Snow");
+ Console.WriteLine($"- ({chara.Id}) : {chara.Name} -> {chara.IdImage} : {(chara.Images.ImgPath.Length <= 40 ? chara.Images.ImgPath : chara.Images.ImgPath.Substring(0, 40) + "...")}");
+ Console.WriteLine("");
+
+
+ Console.WriteLine("---- Test LastId Character");
+ id = await characterManager.GetLastCharId();
+ Console.WriteLine($"- Last character id : {id}");
+ Console.WriteLine("");
+}
+
+
+
diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj
new file mode 100644
index 0000000..960e394
--- /dev/null
+++ b/WF_EF_Api/Contextlib/Contextlib.csproj
@@ -0,0 +1,29 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs
new file mode 100644
index 0000000..7d01f7f
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs
@@ -0,0 +1,137 @@
+using Entity;
+using Microsoft.EntityFrameworkCore;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contextlib
+{
+ public class DbCharacterManager : ICharacterService
+ {
+ private WTFContext _context;
+ private GenericRepository _repo;
+
+ public DbCharacterManager(WTFContext context)
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repo = new GenericRepository(_context);
+ }
+
+ ///
+ /// Adds a new character to the database.
+ ///
+ /// The character to be added to the database.
+ /// A task that represents the asynchronous operation.
+ /// Thrown when the provided character is null.
+ public async Task AddCharacter(Character character)
+ {
+ if (character == null)
+ {
+ throw new ArgumentNullException(nameof(character), "character cannot be null.");
+ }
+ _repo.Insert(character);
+ await _context.SaveChangesAsync();
+ }
+
+ ///
+ /// Retrieves all characters from the database and returns them in a paginated format.
+ ///
+ /// A task representing the asynchronous operation, with a as its result containing the full list of characters and pagination information.
+ public async Task> GetAll()
+ {
+ List charLst = _repo.GetItems(0, _repo.Count(), [nameof(Character.Images)]).ToList();
+ return new PaginationResult(charLst.Count, 0, charLst.Count, charLst);
+ }
+
+ ///
+ /// Retrieves a character by its ID from the database.
+ ///
+ /// The unique identifier of the character to retrieve.
+ /// A task that represents the asynchronous operation, with a as its result.
+ /// Thrown when no character is found with the given ID.
+ public async Task GetCharById(int id)
+ {
+ Character? character = _repo.GetById(id, item => item.Id == id, nameof(Character.Images));
+ if (character == null)
+ {
+ throw new KeyNotFoundException($"Error : No character found with the ID: {id}.");
+ }
+ return character;
+ }
+
+ ///
+ /// Retrieves a character by its name from the database.
+ ///
+ /// The name of the character to retrieve.
+ /// A task that represents the asynchronous operation, with a as its result.
+ /// Thrown when no character is found with the given name.
+ public async Task GetCharByName(string name)
+ {
+ var character = _repo.GetItems(item => item.Name == name,0,1, [nameof(Character.Images)]).FirstOrDefault();
+
+ return character;
+ }
+
+ ///
+ /// Retrieves the highest character ID from the database.
+ ///
+ /// The highest character ID in the database. 0 if there is no character in the database
+ public async Task GetLastCharId()
+ {
+ PaginationResult characters = await GetAll();
+ int lastCharId = 0;
+ foreach (Character character in characters.items)
+ {
+ if (character.Id >= lastCharId)
+ {
+ lastCharId = character.Id + 1;
+ }
+ }
+ return lastCharId;
+ }
+
+ ///
+ /// Removes a character from the database by its ID.
+ ///
+ /// The ID of the character to remove.
+ /// A task representing the asynchronous operation.
+ /// Thrown when no character is found with the given ID.
+ public async Task RemoveCharacter(int id)
+ {
+ _repo.Delete(id);
+ await _context.SaveChangesAsync();
+ }
+
+ ///
+ /// Updates a character's details by its ID.
+ ///
+ /// The ID of the character to update.
+ /// The updated character information.
+ /// A task representing the asynchronous operation.
+ /// /// Thrown when the provided character is null.
+ /// Thrown when no character is found with the given ID.
+ public async Task UpdateCharacter(int id, Character character)
+ {
+ Character? charac = _repo.GetById(id);
+ if (charac != null)
+ {
+ bool change = false;
+ if (character.IdImage != 0)
+ {
+ charac.IdImage = character.IdImage;
+ change = true;
+ }
+ if (character.Name != null)
+ {
+ charac.Name = character.Name;
+ change = true;
+ }
+ _repo.Update(charac);
+ if (change) _context.SaveChanges();
+ }
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs
new file mode 100644
index 0000000..bac04e3
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs
@@ -0,0 +1,221 @@
+using Entity;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Update;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contextlib
+{
+ public class DbCommentaryManager : ICommentaryService
+ {
+ private WTFContext _context;
+ private GenericRepository _repo;
+
+ public DbCommentaryManager(WTFContext context)
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repo = new GenericRepository(context);
+ }
+
+ ///
+ /// Adds a new comment to the database.
+ ///
+ /// The comment to add.
+ /// A task representing the asynchronous operation.
+ /// Thrown when the comment is null.
+ public async Task AddComment(Commentary comment, int idQuote)
+ {
+ if (comment == null)
+ {
+ throw new ArgumentNullException(nameof(comment), "Comment cannot be null.");
+ }
+
+ var quote = await _context.quotes
+ .Include(q => q.Commentarys) // collection des commentaires est chargée
+ .FirstOrDefaultAsync(q => q.Id == idQuote);
+
+ var dbU = new DbUsersManager(_context);
+ var User = await dbU.GetUserByUsername(comment.User.UserName);
+ if (User == null)
+ {
+ throw new ArgumentException("Quote not exist", nameof(comment.User.UserName));
+ }
+
+ if (quote == null)
+ {
+ throw new ArgumentException("Quote not exist", nameof(idQuote));
+ }
+
+ comment.User = User;
+ comment.IdUser = User.Id;
+
+ // Lien entre le commentaire et la citation
+ comment.Quote = quote;
+ comment.IdQuote = idQuote;
+
+ // Ajout commentaire à la collection des commentaires de la citation
+ //_repo.Insert(comment);
+ _context.Add(comment);
+ await _context.SaveChangesAsync();
+ }
+
+ ///
+ /// Deletes all comments associated with a specific quote ID from the database.
+ ///
+ /// The ID of the quote whose comments need to be deleted.
+ /// A task representing the asynchronous operation.
+ /// Thrown when no comments are found for the provided quote ID.
+ public async Task DeleteCommentaryForQuote(int quoteId)
+ {
+ var comments = await _context.comments.Where(x => x.IdQuote == quoteId).ToListAsync();
+ if (!comments.Any())
+ {
+ throw new KeyNotFoundException($"No comments found for the quote ID: {quoteId}.");
+ }
+
+ _context.comments.RemoveRange(comments);
+ await _context.SaveChangesAsync();
+ }
+
+ ///
+ /// Deletes all comments associated with a specific user ID from the database.
+ ///
+ /// The ID of the user whose comments need to be deleted.
+ /// A task representing the asynchronous operation.
+ /// Thrown when no comments are found for the provided user ID.
+ public async Task DeleteCommentaryForUser(int userId)
+ {
+ var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync();
+ if (!comments.Any())
+ {
+ throw new KeyNotFoundException($"No comments found for the user ID: {userId}.");
+ }
+
+ _context.comments.RemoveRange(comments);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task> GetAllCommentary()
+ {
+ var comments = await _context.comments.Include(c => c.User).Include(c=>c.User.Images).ToListAsync();
+ return new PaginationResult(comments.Count, 0, comments.Count, comments);
+ }
+
+ public async Task GetCommentaryById(int id)
+ {
+ var comment = await _context.comments.Include(c => c.User).Include(c => c.User.Images).Where(x => x.Id == id).FirstOrDefaultAsync();
+ if(comment == null)
+ {
+ throw new KeyNotFoundException($"No comments found with the given ID: {id}.");
+ }
+ return comment;
+ }
+
+ public async Task> GetCommentaryByQuote(int quoteId, int index, int pageSize)
+ {
+ var comments = await _context.comments.Include(c => c.User).Include(c => c.User.Images).Where(x => x.IdQuote == quoteId).ToListAsync();
+ if (!comments.Any())
+ {
+ throw new KeyNotFoundException($"No comments found for the quote ID: {quoteId}.");
+ }
+ if ((index * pageSize + pageSize) > comments.Count)
+ {
+ if (pageSize > comments.Count)
+ {
+ return new PaginationResult(comments.Count(), index, pageSize, comments);
+ }
+ else
+ {
+ return new PaginationResult(pageSize, index, pageSize, comments.Skip(index * pageSize - (((index * pageSize) + pageSize) - comments.Count)).Take(pageSize).ToList());
+ }
+
+ }
+ return new PaginationResult(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList());
+ }
+
+ public async Task> GetCommentaryByUser(int userId, int index, int pageSize)
+ {
+ var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync();
+ if (!comments.Any())
+ {
+ throw new KeyNotFoundException($"No comments found for the user ID: {userId}.");
+ }
+ if ((index * pageSize + pageSize) > comments.Count)
+ {
+ if (pageSize > comments.Count)
+ {
+ return new PaginationResult(comments.Count(), index, pageSize, comments);
+ }
+ else
+ {
+ return new PaginationResult(pageSize, index, pageSize, comments.Skip(index * pageSize - (((index * pageSize) + pageSize) - comments.Count)).Take(pageSize).ToList());
+ }
+
+ }
+ return new PaginationResult(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList());
+ }
+
+ public async Task LastCommentaryId()
+ {
+ var last = await _context.comments.OrderByDescending(x => x.Id).FirstOrDefaultAsync();
+ if(last == null)
+ {
+ return 0;
+ }
+ return last.Id;
+ }
+
+ public async Task RemoveCommentary(int id)
+ {
+
+ Commentary? commentary = await GetCommentaryById(id);
+ if (commentary == null)
+ {
+ throw new KeyNotFoundException($"Error : No comment found with the ID: {id}.");
+ }
+ _repo.Delete(commentary);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task UpdateCommentary(int id, Commentary comment)
+ {
+ var modif = false;
+ var com = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync();
+ if (comment == null)
+ {
+ throw new ArgumentNullException(nameof(comment), "The updated comment data cannot be null.");
+ }
+ if (com == null)
+ {
+ throw new KeyNotFoundException($"No comments found with the given ID: {id}.");
+ }
+ if (comment.Comment != null)
+ {
+ com.Comment = comment.Comment;
+ modif = true;
+ }
+ if(comment.DateCommentary != null){
+ com.DateCommentary = comment.DateCommentary;
+ modif = true;
+ }
+ if(comment.IdQuote != 0)
+ {
+ com.IdQuote = comment.IdQuote;
+ modif = true;
+ }
+ if (comment.IdUser != 0)
+ {
+ com.IdUser = comment.IdUser;
+ modif = true;
+ }
+ if (modif)
+ {
+ await _context.SaveChangesAsync();
+ }
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/DbFavoriteManager.cs b/WF_EF_Api/Contextlib/DbFavoriteManager.cs
new file mode 100644
index 0000000..0fbdd59
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbFavoriteManager.cs
@@ -0,0 +1,117 @@
+using Entity;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contextlib
+{
+ public class DbFavoriteManager : IFavoriteService
+ {
+ private WTFContext _context;
+ private GenericRepository _repo;
+
+ public DbFavoriteManager(WTFContext context)
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repo = new GenericRepository(context);
+ }
+
+ public async Task AddFavorite(int quoteid, int userId)
+ {
+ var quote = await _context.quotes // collection des commentaires est chargée
+ .Include(q => q.Favorite)
+ .FirstOrDefaultAsync(q => q.Id == quoteid);
+
+ var user = await _context.users // collection des commentaires est chargée
+ .Include(u => u.Favorite)
+ .FirstOrDefaultAsync(q => q.Id == userId);
+
+ if (quote == null && user == null)
+ {
+ throw new ArgumentException("Quote or User not exist", nameof(quoteid));
+ }
+
+
+ var fav = new Favorite
+ {
+ // Lien entre le favorite et la citation
+ Quote = quote,
+ IdQuote = quoteid,
+ // Lien entre le favorite et le user
+ Users = user,
+ IdUsers = userId,
+ };
+
+ if (fav != null)
+ {
+ // Ajout favorite à la collection des favorites de la citation
+ quote.Favorite.Add(user);
+
+ // Ajout favorite à la collection des favorites de la citation
+ user.Favorite.Add(quote);
+ }
+ _context.Add(fav);
+ await _context.SaveChangesAsync();
+ }
+
+
+ public async Task RemoveAllFavoriteForQuote(int quoteId)
+ {
+ var fav = _context.favorites.Where(item => item.IdQuote == quoteId).ToList();
+
+ if (fav == null) throw new KeyNotFoundException();
+
+ foreach (var item in fav)
+ {
+ _context.favorites.Remove(item);
+ }
+
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task RemoveAllFavoriteForUser(int userId)
+ {
+ var fav = _context.favorites.Where(item => item.IdUsers == userId).ToList();
+
+ if (fav == null) throw new KeyNotFoundException();
+
+ foreach (var item in fav)
+ {
+ _context.favorites.Remove(item);
+ }
+
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task RemoveFavorite(int quoteid, int userId)
+ {
+ var fav = await _context.favorites.Where(item=>item.IdQuote==quoteid && item.IdUsers==userId).FirstAsync();
+
+ if (fav == null) throw new KeyNotFoundException();
+
+ _context.favorites.Remove(fav);
+
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task GetFavorite(int userId, int idQuote)
+ {
+ return await _context.quotes.Where( item => item.Id == idQuote && item.Favorite.Any(u => u.Id == userId) )
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q=>q.Favorite)
+ .FirstOrDefaultAsync();
+ }
+
+ public async Task> GetFavoriteByIdUser(int userId, int index, int count)
+ {
+ List fav = await _context.quotes.Where(item => item.Favorite.Any(u => u.Id == userId))
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
+ .Skip(index * count).Take(count).ToListAsync();
+ return new PaginationResult(fav.Count,index,count,fav);
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/DbImagesManager.cs b/WF_EF_Api/Contextlib/DbImagesManager.cs
new file mode 100644
index 0000000..e549cf9
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbImagesManager.cs
@@ -0,0 +1,97 @@
+using Entity;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace Contextlib
+{
+ public class DbImagesManager : IImagesService
+ {
+ private WTFContext _context;
+ private GenericRepository _repository;
+
+ public DbImagesManager(WTFContext context)
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repository = new GenericRepository(context);
+ }
+
+ public async Task AddImage(Images image)
+ {
+ _repository.Insert(image);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task> GetAllImage()
+ {
+ return new PaginationResult(await CountImage(), 0, await CountImage(), _repository.GetItems(0, await CountImage()).ToList());
+ }
+
+ public async Task GetImageById(int id)
+ {
+ return _repository.GetById(id);
+ }
+
+ public async Task GetLastImageId()
+ {
+ var last = await GetAllImage();
+ int id = 1;
+ {
+ foreach (Images image in last.items)
+ {
+ if(image.Id >= id)
+ id = image.Id + 1;
+ }
+ }
+ return id;
+ }
+
+ public async Task> GetSomeImage(int index, int pageSize)
+ {
+ var images = _repository.GetItems(index, pageSize);
+ return new PaginationResult(images.Count(),index,pageSize,images.ToList());
+ }
+
+ public async Task RemoveImage(int id)
+ {
+ _repository.Delete(id);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task UpdateImage(int id, Images image)
+ {
+ var img = _repository.GetById(id);
+ var modif = false;
+ if (image != null && img != null)
+ {
+ if (image.ImgPath != null)
+ {
+ img.ImgPath = image.ImgPath;
+ modif = true;
+ }
+ _repository.Update(img);
+ if (modif)
+ {
+ await _context.SaveChangesAsync();
+ }
+ }
+ }
+
+ public async Task CountImage()
+ {
+ return await _context.images.CountAsync();
+ }
+
+ public async Task GetImageByPath(string path)
+ {
+ var image = _repository.GetItems(item => item.ImgPath == path,0,1).FirstOrDefault();
+ return image;
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/DbQuestionManager.cs b/WF_EF_Api/Contextlib/DbQuestionManager.cs
new file mode 100644
index 0000000..5e323b7
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbQuestionManager.cs
@@ -0,0 +1,155 @@
+using Entity;
+using Microsoft.EntityFrameworkCore;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contextlib
+{
+ public class DbQuestionManager : IQuestionService
+ {
+ private WTFContext _context;
+ private GenericRepository _repository;
+
+ public DbQuestionManager(WTFContext context)
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repository = new GenericRepository(context);
+ }
+
+ public async Task AddQuestion(Question question)
+ {
+ _repository.Insert(question);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task CountQuestions()
+ {
+ return _repository.Count();
+ }
+
+ public async Task> GetAllQuestion()
+ {
+ return new PaginationResult(_repository.Count(), 0, _repository.Count(), _repository.GetItems(0,_repository.Count()).ToList());
+ }
+
+ public async Task> GetInvalidQuestion(int index, int pageSize)
+ {
+ List questionList = _repository.GetItems(item => item.IsValid == false, index, pageSize).ToList();
+ return new PaginationResult(questionList.Count(), index, pageSize, questionList);
+ }
+
+ public async Task GetQuestionById(int id)
+ {
+ return _repository.GetById(id);
+ }
+
+ public async Task GetRandomQuestion()
+ {
+ Random rnd = new Random();
+ Question? question = null;
+ while(question == null)
+ {
+ question = await GetQuestionById(rnd.Next(0, await LastId()-1));
+ }
+ return question;
+ }
+
+ public async Task GetRandomQuestionQuoteToCharacter()
+ {
+ //dabord implémenter get random quote
+ throw new NotImplementedException();
+ }
+
+ public async Task GetRandomQuestionQuoteToSource()
+ {
+ //dabord implémenter get random quote
+ throw new NotImplementedException();
+ }
+
+ public async Task> GetSomeQuestion(int index, int pageSize)
+ {
+ List questionList = _repository.GetItems(item => item.IsValid == false, index, pageSize).ToList();
+ return new PaginationResult(questionList.Count(), index, pageSize, questionList);
+ }
+
+ public async Task RemoveQuestion(int id)
+ {
+ _repository.Delete(id);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task UpdateQuestion(int id, Question question)
+ {
+ Question? questionUpdated = await GetQuestionById(id);
+ if (question != null && questionUpdated != null)
+ {
+ bool modified = false;
+ if (question.IsValid != questionUpdated.IsValid)
+ {
+ questionUpdated.IsValid = question.IsValid;
+ modified = true;
+ }
+ if (question.Text != null)
+ {
+ questionUpdated.Text = question.Text;
+ modified = true;
+ }
+ if (question.AnswerA != null)
+ {
+ questionUpdated.AnswerA = question.AnswerA;
+ modified = true;
+ }
+ if (question.AnswerB != null)
+ {
+ questionUpdated.AnswerB = question.AnswerB;
+ modified = true;
+ }
+ if (question.AnswerC != null)
+ {
+ questionUpdated.AnswerC = question.AnswerC;
+ modified = true;
+ }
+ if (question.AnswerD != null)
+ {
+ questionUpdated.AnswerD = question.AnswerD;
+ modified = true;
+ }
+ if (question.CorrectAnswer != null)
+ {
+ questionUpdated.CorrectAnswer = question.CorrectAnswer;
+ modified = true;
+ }
+ _repository.Update(questionUpdated);
+ if(modified) _context.SaveChanges();
+ }
+ ;
+
+ }
+
+ public async Task ValidateQuestion(int id, bool isvalid)
+ {
+ Question? question = await GetQuestionById(id);
+ if (question == null) throw new KeyNotFoundException($"Aucune question avec l'id {id}");
+ question.IsValid = isvalid;
+ _repository.Update(question);
+ }
+
+ public async Task LastId()
+ {
+ PaginationResult questions = await GetAllQuestion();
+ int id = 1;
+ foreach (Question question in questions.items)
+ {
+ if (question.Id >= id)
+ {
+ id = question.Id + 1;
+ }
+ }
+ return id;
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs
new file mode 100644
index 0000000..0a4236a
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs
@@ -0,0 +1,298 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+using Entity;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
+using Shared;
+
+namespace Contextlib
+{
+ public class DbQuoteManager : IQuoteService
+ {
+ private WTFContext _context;
+ private GenericRepository _repo;
+ private DbCharacterManager _dbC;
+ private DbSourceManager _dbS;
+ private DbImagesManager _dbI;
+
+ public DbQuoteManager(WTFContext context)
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repo = new GenericRepository(_context);
+ _dbS = new DbSourceManager(_context);
+ _dbC = new DbCharacterManager(_context);
+ _dbI = new DbImagesManager(_context);
+
+ }
+
+
+ public async Task AddQuote(Quote quote)
+ {
+ if (quote == null)
+ {
+ throw new ArgumentNullException(nameof(quote), "quote cannot be null.");
+ }
+ //Character
+ var c = await _dbC.GetCharByName(quote.Character.Name);
+ if (c != null)
+ {
+ quote.IdCharacter = c.Id;
+ quote.Character = c;
+ }
+ //Image
+ var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath);
+ if (i != null)
+ {
+ quote.Character.IdImage = i.Id;
+ quote.Character.Images = i;
+ }
+ //Source
+ var s = await _dbS.GetSourceByTitle(quote.Source.Title);
+ if (s != null)
+ {
+ quote.IdSource = s.Id;
+ quote.Source = s;
+ }
+
+ _repo.Insert(quote);
+ await _context.SaveChangesAsync();
+ return quote;
+ }
+
+ public async Task> GetAllQuote()
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .ToList();
+ return new PaginationResult(quotes.Count, 0, quotes.Count, quotes);
+ }
+
+ public async Task> GetAllQuoteLang(int index, int pageSize, int lang)
+ {
+ List quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToListAsync();
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task GetDailyQuote(DateOnly date, int lang)
+ {
+ List quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
+ .ToListAsync();
+ if (quotes.Count() == 0) return null;
+ Quote quote = quotes[date.DayNumber % quotes.Count()];
+
+ return quote;
+ }
+
+ public async Task> GetFavorites(int index, int pageSize, int UserId)
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid && item.Favorite.Where(p => p.Id == UserId) != null)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task> GetInvalidQuote(int index, int pageSize, int lang)
+ {
+ List quotes = _context.quotes.Where(item => !item.IsValid && item.Langage == (LangEnum)lang)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task> GetInvalidQuote(int index, int pageSize)
+ {
+ List quotes = _context.quotes.Where(item => !item.IsValid)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task GetLastQuoteId()
+ {
+ PaginationResult quotes = await GetAllQuote();
+ int lastQuoteId = 0;
+ foreach (Quote quote in quotes.items)
+ {
+ if (quote.Id >= lastQuoteId)
+ {
+ lastQuoteId = quote.Id + 1;
+ }
+ }
+ return lastQuoteId;
+ }
+
+ public async Task GetQuoteById(int id)
+ {
+ Quote? quote = _context.quotes.Where(item => item.Id == id)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .FirstOrDefault();
+
+ return quote;
+ }
+
+ public async Task> GetSomeQuote(int index, int pageSize)
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task> GetSuggestions(int index, int pageSize, int lang) // A changer Suggestion Random
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ //.OrderBy(q=> new Random() )
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task> GetValidQuote(int index, int pageSize)
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid)
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task> SearchByCharacter(string character, int index, int pageSize, int lang)
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid && item.Langage==(LangEnum)lang && (item.Character.Name).Contains(character))
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task> SearchByContent(string content, int index, int pageSize, int lang)
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang && (item.Content).Contains(content))
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+ public async Task> SearchBySource(string source, int index, int pageSize, int lang)
+ {
+ List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang && (item.Source.Title).Contains(source))
+ .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
+ .Skip(index * pageSize).Take(pageSize).ToList();
+
+ return new PaginationResult(quotes.Count, index, pageSize, quotes);
+ }
+
+
+
+
+
+ public async Task RemoveQuote(int quoteId)
+ {
+ var quote = _repo.GetById(quoteId);
+ if (quote == null) throw new KeyNotFoundException();
+ _repo.Delete( quote );
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task UpdateQuote(int quoteId, Quote quote)
+ {
+ //Character
+ var c = await _dbC.GetCharByName(quote.Character.Name);
+ if (c != null)
+ {
+ quote.IdCharacter = c.Id;
+ quote.Character = c;
+ }
+ //Image
+ var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath);
+ if (c != null)
+ {
+ quote.Character.IdImage = i.Id;
+ quote.Character.Images = i;
+ }
+ //Source
+ var s = await _dbS.GetSourceByTitle(quote.Source.Title);
+ if (c != null)
+ {
+ quote.IdSource = s.Id;
+ quote.Source = s;
+ }
+
+ Quote? q = _repo.GetById(quoteId);
+ if (q != null)
+ {
+ bool change = false;
+ if (quote.IdSource != 0)
+ {
+ q.IdSource = quote.IdSource;
+ change = true;
+ }
+ if (quote.IdCharacter != 0)
+ {
+ q.IdCharacter = quote.IdCharacter;
+ change = true;
+ }
+ if (quote.IdSource != 0)
+ {
+ q.IdSource = quote.IdSource;
+ change = true;
+ }
+ if (quote.IdUsersPropose !=0)
+ {
+ q.IdUsersPropose = quote.IdUsersPropose;
+ change = true;
+ }
+ if (quote.Content != null || quote.Content == "")
+ {
+ q.Content = quote.Content;
+ change = true;
+ }
+ if (quote.IsValid != q.IsValid)
+ {
+ q.IsValid = quote.IsValid;
+ change = true;
+ }
+ if (quote.Likes != q.Likes)
+ {
+ q.Likes = quote.Likes;
+ change = true;
+ }
+ if (quote.Langage != q.Langage)
+ {
+ q.Langage = quote.Langage;
+ change = true;
+ }
+
+ _repo.Update(q);
+ if (change) _context.SaveChanges();
+ }
+ return ;
+ }
+
+ public async Task ValidateQuote(int quoteId, bool isValidate)
+ {
+ Quote? q = _repo.GetById(quoteId);
+ if (q != null)
+ {
+ q.IsValid = isValidate;
+ _repo.Update(q);
+ _context.SaveChanges();
+ }
+ return;
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/DbSourceManager.cs b/WF_EF_Api/Contextlib/DbSourceManager.cs
new file mode 100644
index 0000000..e2ed299
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbSourceManager.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Entity;
+using Shared;
+using static System.Runtime.InteropServices.JavaScript.JSType;
+
+namespace Contextlib
+{
+ public class DbSourceManager : ISourceService
+ {
+ private WTFContext _context;
+ private GenericRepository _repo;
+
+ public DbSourceManager(WTFContext context)
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repo = new GenericRepository(_context);
+ }
+
+ public async Task AddSource(Source source)
+ {
+ if (source == null)
+ {
+ throw new ArgumentNullException(nameof(source), "character cannot be null.");
+ }
+ _repo.Insert(source);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task> GetAll()
+ {
+ List srcLst = _repo.GetItems(0, _repo.Count(), []).ToList();
+ return new PaginationResult(srcLst.Count, 0, srcLst.Count, srcLst);
+ }
+
+ public async Task GetLastSourceId()
+ {
+ throw new NotImplementedException();
+ }
+
+ public async Task> GetSomesSource(int page, int count)
+ {
+ var srcLst = _repo.GetItems(page, count, []).ToList();
+ return new PaginationResult(srcLst.Count, 0, srcLst.Count, srcLst);
+ }
+
+ public async Task> GetSourceByDate(int date)
+ {
+
+ var srcLst = _repo.GetItems(item => item.Year == date, 0, _repo.Count(), []).ToList();
+
+ return new PaginationResult(srcLst.Count, 0, srcLst.Count, srcLst);
+ }
+
+ public async Task GetSourceById(int id)
+ {
+ Source? source = _repo.GetById(id, item => item.Id == id, []);
+ if (source == null)
+ {
+ throw new KeyNotFoundException($"Error : No source found with the ID: {id}.");
+ }
+ return source;
+ }
+
+ public async Task GetSourceByTitle(string title)
+ {
+ var source = _repo.GetItems(item => item.Title == title, 0, 1, []).FirstOrDefault();
+
+ return source;
+ }
+
+ public async Task GetSourceByType(int type)
+ {
+ var source = _repo.GetItems(item => item.TypeSrc == (TypeSrcEnum)type, 0, 1, []).FirstOrDefault();
+
+ return source;
+ }
+
+ public async Task RemoveSource(int id)
+ {
+ _repo.Delete(id);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task UpdateSource(int id, Source source)
+ {
+ Source? src = _repo.GetById(id);
+ if (src != null)
+ {
+ bool change = false;
+ if (src.Title != source.Title)
+ {
+ src.Title = source.Title;
+ change = true;
+ }
+ if (src.Year != source.Year)
+ {
+ src.Year = source.Year;
+ change = true;
+ }
+ if (src.TypeSrc != source.TypeSrc)
+ {
+ src.TypeSrc = source.TypeSrc;
+ change = true;
+ }
+ _repo.Update(src);
+ if (change) _context.SaveChanges();
+ }
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/DbUsersManager.cs b/WF_EF_Api/Contextlib/DbUsersManager.cs
new file mode 100644
index 0000000..e10ca69
--- /dev/null
+++ b/WF_EF_Api/Contextlib/DbUsersManager.cs
@@ -0,0 +1,185 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Entity;
+using Microsoft.EntityFrameworkCore;
+using Shared;
+
+namespace Contextlib
+{
+ public class DbUsersManager : IUserService
+ {
+ private WTFContext _context;
+ private GenericRepository _repo;
+
+ public DbUsersManager( WTFContext context )
+ {
+ _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
+ _repo = new GenericRepository(_context);
+ }
+
+
+
+ public async Task AddUser(Users user)
+ {
+ /*if (await ExistEmail(user.Email) || (await ExistUsername(user.UserName)))
+ {
+ throw new ArgumentException("The given Email or Username Already exist");
+ }*/
+ if (user == null) {
+ throw new ArgumentNullException(nameof(user), "user cannot be null.");
+ }
+ var dbI = new DbImagesManager(_context);
+ var image = await dbI.GetImageByPath(user.Images.ImgPath);
+ if(image != null)
+ {
+ user.IdImage = image.Id;
+ user.Images = image;
+ }
+ _repo.Insert(user);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task CountUser()
+ {
+ return _repo.Count();
+ }
+
+ public async Task ExistEmail(string email)
+ {
+ Users? users = await _context.users.Where(u=>u.Email == email).FirstOrDefaultAsync();
+ return users != null;
+ }
+
+ public async Task ExistUsername(string username)
+ {
+ Users? users = await _context.users.Where(u => u.UserName == username).FirstOrDefaultAsync();
+ return users != null;
+ }
+
+ public async Task> GetAllUser()
+ {
+ List users = _repo.GetItems(0,_repo.Count(),[nameof(Users.Images)]).ToList();
+ return new PaginationResult(users.Count,0,users.Count,users);
+ }
+
+ public async Task GetHashPassword(string username)
+ {
+ Users? user = _context.users.Where(u=>u.UserName == username).FirstOrDefault();
+ if (user == null)
+ {
+ return "";
+ }
+ return user.Password;
+ }
+
+ public async Task GetLastUserId()
+ {
+ PaginationResult users = await GetAllUser();
+ int lastUserId = 0;
+ foreach (Users user in users.items)
+ {
+ if (user.Id >= lastUserId)
+ {
+ lastUserId = user.Id + 1;
+ }
+ }
+ return lastUserId;
+ }
+
+ public async Task> GetSomeUser(int index, int pageSize)
+ {
+ List users = _repo.GetItems(index, pageSize, [nameof(Users.Images)]).ToList();
+ return new PaginationResult(users.Count, index, pageSize, users);
+ }
+
+ public async Task GetUserByEmail(string email)
+ {
+ var user = _repo.GetItems(item => item.Email == email, 0, 1, [nameof(Character.Images)]).FirstOrDefault();
+
+ if (user == null)
+ {
+ throw new KeyNotFoundException($"Error : No user found with the email: {email}.");
+ }
+
+ return user;
+ }
+
+ public async Task GetUserById(int id)
+ {
+ Users? user =_repo.GetById(id, item => item.Id == id, nameof(Users.Images));
+ if (user == null)
+ {
+ throw new KeyNotFoundException($"Error : No users found with the ID: {id}.");
+ }
+ return user;
+ }
+
+ public async Task GetUserByUsername(string username)
+ {
+ var user = _repo.GetItems(item => item.UserName == username, 0, 1, [nameof(Character.Images)]).FirstOrDefault();
+
+ if (user == null)
+ {
+ throw new KeyNotFoundException($"Error : No user found with the name: {username}.");
+ }
+
+ return user;
+ }
+
+ public async Task RemoveUser(int id)
+ {
+ Users? user = _repo.GetById(id);
+ if (user == null)
+ {
+ throw new KeyNotFoundException($"Error : No users found with the ID: {id}.");
+ }
+ _repo.Delete(user);
+ await _context.SaveChangesAsync();
+ }
+
+ public async Task SetAdminRole(bool isAdmin)
+ {
+ throw new NotImplementedException();
+ }
+
+ public async Task UpdateUser(int userId, Users user)
+ {
+ Users? u = _repo.GetById(userId, item => item.Id == userId, nameof(Users.Images));
+ if (u != null)
+ {
+ bool change = false;
+ if (user.Images.ImgPath != null)
+ {
+ var dbI = new DbImagesManager(_context);
+ var img = await dbI.GetImageByPath(user.Images.ImgPath);
+ if (img != null)
+ {
+ u.IdImage = dbI.GetImageByPath(user.Images.ImgPath).Id;
+ change = true;
+ }
+ }
+ if (user.UserName != null)
+ {
+ u.UserName = user.UserName;
+ change = true;
+ }
+ if (user.Email != null)
+ {
+ u.Email = user.Email;
+ change = true;
+ }
+ if (user.Password != null)
+ {
+ u.Password = user.Password;
+ change = true;
+ }
+ _repo.Update(u);
+ if (change)_context.SaveChanges();
+ }
+ return u;
+ }
+ }
+}
diff --git a/WF_EF_Api/Contextlib/GenericRepository.cs b/WF_EF_Api/Contextlib/GenericRepository.cs
new file mode 100644
index 0000000..0bee129
--- /dev/null
+++ b/WF_EF_Api/Contextlib/GenericRepository.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
+
+namespace Contextlib
+{
+ public class GenericRepository where T : class
+ {
+ private DbContext Context { get; set; }
+ private DbSet Set { get; set; }
+
+ public GenericRepository(DbContext context)
+ {
+ Context = context;
+ Set = Context.Set();
+ }
+
+ public virtual T? GetById(object id)
+ => Set.Find(id);
+
+ public virtual T? GetById(object id, Expression>? filter = null, params string[] includeProperties)
+ {
+ IQueryable query = Set;
+ if (filter != null)
+ {
+ query = query.Where(filter);
+ }
+ foreach (string includeProperty in includeProperties)
+ {
+ query = query.Include(includeProperty);
+ }
+ return query.FirstOrDefault();
+ }
+
+ public virtual IEnumerable GetItems(Expression>? filter = null,
+ int index = 0, int count = 10,
+ params string[] includeProperties)
+ => GetItems(filter, null, index, count, includeProperties);
+
+ public virtual IEnumerable GetItems(Func, IOrderedQueryable>? orderBy = null,
+ int index = 0, int count = 10,
+ params string[] includeProperties)
+ => GetItems(null, orderBy, index, count, includeProperties);
+
+ public virtual IEnumerable GetItems(int index = 0, int count = 10,
+ params string[] includeProperties)
+ => GetItems(null, null, index, count, includeProperties);
+
+ public virtual IEnumerable GetItems(Expression>? filter = null,
+ Func, IOrderedQueryable>? orderBy = null,
+ int index = 0, int count = 10,
+ params string[] includeProperties)
+ {
+ IQueryable query = Set;
+ if (filter != null)
+ {
+ query = query.Where(filter);
+ }
+ foreach (string includeProperty in includeProperties)
+ {
+ query = query.Include(includeProperty);
+ }
+ if (orderBy != null)
+ {
+ query = orderBy(query);
+ }
+ return query.Skip(index * count)
+ .Take(count)
+ .ToList();
+ }
+
+ public virtual void Insert(T entity)
+ {
+ if (Set.Entry(entity).IsKeySet)
+ return;
+ Set.Add(entity);
+ }
+
+ public virtual void Insert(params T[] entities)
+ {
+ foreach (var entity in entities)
+ {
+ Insert(entity);
+ }
+ }
+
+ public virtual void Delete(object id)
+ {
+ T? entity = Set.Find(id);
+ if (entity == null) return;
+ Delete(entity);
+ }
+
+ public virtual void Delete(T entity)
+ {
+ if (Context.Entry(entity).State == EntityState.Detached)
+ {
+ Set.Attach(entity);
+ }
+ Set.Remove(entity);
+ }
+
+ public virtual void Update(T entity)
+ {
+ Set.Attach(entity);
+ Context.Entry(entity).State = EntityState.Modified;
+ }
+
+ public virtual int Count()
+ {
+ return Set.Count();
+ }
+
+ }
+}
diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs
new file mode 100644
index 0000000..af9c12a
--- /dev/null
+++ b/WF_EF_Api/Contextlib/WTFContext.cs
@@ -0,0 +1,97 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using Entity;
+using Microsoft.EntityFrameworkCore;
+
+namespace Contextlib
+{
+ public class WTFContext : DbContext
+ {
+ //public DbSet admins { get; set; }
+ public DbSet characters { get; set; }
+ public DbSet comments { get; set; }
+ public DbSet favorites { get; set; }
+ public DbSet images { get; set; }
+ public DbSet question { get; set; }
+ public DbSet quizzes { get; set; }
+ //public DbSet quizQuestions { get; set; }
+ public DbSet quotes { get; set; }
+ //public DbSet records { get; set; }
+ public DbSet sources { get; set; }
+ public DbSet users { get; set; }
+ public DbSet admins { get; set; }
+
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ base.OnModelCreating(modelBuilder);
+
+ modelBuilder.Entity()
+ .HasMany(q => q.Favorite)
+ .WithMany(u => u.Favorite)
+ .UsingEntity(
+ l => l.HasOne(f => f.Quote)
+ .WithMany()
+ .OnDelete(DeleteBehavior.ClientCascade)
+ .HasForeignKey(f => f.IdQuote),
+ r => r.HasOne(f => f.Users)
+ .WithMany()
+ .OnDelete(DeleteBehavior.ClientCascade)
+ .HasForeignKey(f => f.IdUsers)
+ );
+
+ modelBuilder.Entity()
+ .HasMany(u => u.Quotes)
+ .WithOne(q => q.User)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasForeignKey(q => q.IdUsersPropose);
+
+ modelBuilder.Entity()
+ .HasMany()
+ .WithMany()
+ .UsingEntity(
+ i => i.HasKey(e => e.Id)
+ );
+
+ modelBuilder.Entity()
+ .HasOne(c => c.User)
+ .WithMany()
+ .HasForeignKey(c => c.IdUser);
+
+ modelBuilder.Entity()
+ .HasMany(q => q.Commentarys)
+ .WithOne(c => c.Quote)
+ .OnDelete(DeleteBehavior.ClientCascade)
+ .HasForeignKey(c => c.IdQuote);
+
+ modelBuilder.Entity()
+ .HasMany(q => q.Questions)
+ .WithMany(u => u.Quizs)
+ .UsingEntity(
+ l => l.HasOne().WithMany().HasForeignKey(q => q.IdQuestion),
+ r => r.HasOne().WithMany().HasForeignKey(u => u.IdQuiz)
+ );
+ //modelBuilder.Entity()
+ // .HasOne(a => a.User)
+ // .WithOne(u => u.admin);
+ }
+
+ public WTFContext()
+ { }
+
+ public WTFContext(DbContextOptions options)
+ : base(options)
+ { }
+
+ protected override void OnConfiguring(DbContextOptionsBuilder options)
+ {
+ if (!options.IsConfigured)
+ {
+ options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Wf-Database.mdf;Trusted_Connection=True;");
+ }
+ }
+ }
+}
diff --git a/WF_EF_Api/DTO/CharacterDTO.cs b/WF_EF_Api/DTO/CharacterDTO.cs
new file mode 100644
index 0000000..00d402c
--- /dev/null
+++ b/WF_EF_Api/DTO/CharacterDTO.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class CharacterDTO
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string imagePath { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/CommentaryDTO.cs b/WF_EF_Api/DTO/CommentaryDTO.cs
new file mode 100644
index 0000000..b901f14
--- /dev/null
+++ b/WF_EF_Api/DTO/CommentaryDTO.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class CommentaryDTO
+ {
+ public int Id { get; set; }
+ public string Comment { get; set; }
+ public DateTime Date { get; set; }
+ public string User { get; set; }
+ public string ImagePath { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/DTO.csproj b/WF_EF_Api/DTO/DTO.csproj
new file mode 100644
index 0000000..99264a0
--- /dev/null
+++ b/WF_EF_Api/DTO/DTO.csproj
@@ -0,0 +1,16 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
diff --git a/WF_EF_Api/DTO/FavoriteDTO.cs b/WF_EF_Api/DTO/FavoriteDTO.cs
new file mode 100644
index 0000000..16173a4
--- /dev/null
+++ b/WF_EF_Api/DTO/FavoriteDTO.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class FavoriteDTO
+ {
+ public int IdUser { get; set; }
+ public int IdQuote { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/ImageDTO.cs b/WF_EF_Api/DTO/ImageDTO.cs
new file mode 100644
index 0000000..2037793
--- /dev/null
+++ b/WF_EF_Api/DTO/ImageDTO.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class ImageDTO
+ {
+ public int IdImage { get; set; }
+ public string ImagePath { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/QuestionDTO.cs b/WF_EF_Api/DTO/QuestionDTO.cs
new file mode 100644
index 0000000..cdf2fb1
--- /dev/null
+++ b/WF_EF_Api/DTO/QuestionDTO.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class QuestionDTO
+ {
+ public int Id { get; set; }
+ public string Question { get; set; }
+ public string AnswerA { get; set; }
+ public string AnswerB { get; set; }
+ public string AnswerC { get; set; }
+ public string AnswerD { get; set; }
+ public string CorrectAnswer { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/QuizDTO.cs b/WF_EF_Api/DTO/QuizDTO.cs
new file mode 100644
index 0000000..abdeb3a
--- /dev/null
+++ b/WF_EF_Api/DTO/QuizDTO.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class QuizDTO
+ {
+ public int Id { get; set; }
+ public int NbQuestion { get; set; }
+ public string ImagePath { get; set; }
+ public string Title { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/QuizQuestionDTO.cs b/WF_EF_Api/DTO/QuizQuestionDTO.cs
new file mode 100644
index 0000000..fe5cf76
--- /dev/null
+++ b/WF_EF_Api/DTO/QuizQuestionDTO.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class QuizQuestionDTO
+ {
+ public int IdQuestion { get; set; }
+ public int IdQuiz { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/QuoteDTO.cs b/WF_EF_Api/DTO/QuoteDTO.cs
new file mode 100644
index 0000000..a60b283
--- /dev/null
+++ b/WF_EF_Api/DTO/QuoteDTO.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class QuoteDTO
+ {
+ public int Id { get; set; }
+ public string Content { get; set; }
+ public string Character { get; set; }
+ public string ImagePath { get; set; }
+ public string TitleSource { get; set; }
+ public int DateSource { get; set; }
+ public int Like { get; set; }
+ public TypeLangageDTO Langage { get; set; }
+ public TypeSrcEnumDTO Type { get; set; }
+ public Boolean IsValide { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/SourceDTO.cs b/WF_EF_Api/DTO/SourceDTO.cs
new file mode 100644
index 0000000..fbb40b7
--- /dev/null
+++ b/WF_EF_Api/DTO/SourceDTO.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class SourceDTO
+ {
+ public int Id { get; set; }
+ public string Title { get; set; }
+ public int Date { get; set; }
+ public TypeSrcEnumDTO Type { get; set; }
+ }
+}
diff --git a/WF_EF_Api/DTO/TypeLangageDTO.cs b/WF_EF_Api/DTO/TypeLangageDTO.cs
new file mode 100644
index 0000000..855168f
--- /dev/null
+++ b/WF_EF_Api/DTO/TypeLangageDTO.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public enum TypeLangageDTO
+ {
+ vo,
+ vf
+ }
+}
diff --git a/WF_EF_Api/DTO/TypeSrcEnumDTO.cs b/WF_EF_Api/DTO/TypeSrcEnumDTO.cs
new file mode 100644
index 0000000..8d5049d
--- /dev/null
+++ b/WF_EF_Api/DTO/TypeSrcEnumDTO.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public enum TypeSrcEnumDTO
+ {
+ movie,
+ serie,
+ book,
+ videogame
+ }
+}
diff --git a/WF_EF_Api/DTO/UserDTO.cs b/WF_EF_Api/DTO/UserDTO.cs
new file mode 100644
index 0000000..a01494b
--- /dev/null
+++ b/WF_EF_Api/DTO/UserDTO.cs
@@ -0,0 +1,12 @@
+namespace DTO
+{
+ public class UserDTO
+ {
+ public int Id { get; set; }
+ public string Pseudo { get; set; }
+ public string Password { get; set; }
+ public string Email { get; set; }
+ public DateTime date { get; set; }
+ public string ImageProfil { get; set; }
+ }
+}
diff --git a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj
new file mode 100644
index 0000000..7455396
--- /dev/null
+++ b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs
new file mode 100644
index 0000000..fcd8407
--- /dev/null
+++ b/WF_EF_Api/Dto2Entities/Extention.cs
@@ -0,0 +1,502 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Entity;
+using DTO;
+using System.Reflection.Metadata;
+
+namespace Dto2Entities
+{
+ public static class Extention
+ {
+ // --------------------------- ToDto --------------------------- \\
+
+ public static CharacterDTO ToDto(this Character item)
+ {
+ if (item == null) return null;
+ CharacterDTO character = new CharacterDTO();
+ character.Id = item.Id;
+ character.Name = item.Name;
+ character.imagePath = item.Images.ImgPath;
+ return character;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List characterDTOs = new List();
+ foreach (Character character in item)
+ {
+ characterDTOs.Add(character.ToDto());
+ }
+ return characterDTOs;
+ }
+
+ public static CommentaryDTO ToDto(this Commentary item)
+ {
+ if (item == null) return null;
+ CommentaryDTO commentary = new CommentaryDTO();
+ commentary.Id = item.Id;
+ commentary.Date = item.DateCommentary;
+ commentary.Comment = item.Comment;
+ commentary.User = item.User.UserName;
+ commentary.ImagePath = item.User.Images.ImgPath;
+ return commentary;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List commentaryDTOs = new List();
+ foreach (Commentary commentary in item)
+ {
+ commentaryDTOs.Add(commentary.ToDto());
+ }
+ return commentaryDTOs;
+ }
+
+ // Surement a refaire car Faoirite Entity modifier sur branche EF
+ public static FavoriteDTO ToDto(this Favorite item)
+ {
+ if (item == null) return null;
+ FavoriteDTO favorite = new FavoriteDTO();
+ favorite.IdUser = item.IdUsers;
+ favorite.IdQuote = item.IdQuote;
+ return favorite;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List favoriteDTOs = new List();
+ foreach (Favorite favorite in item)
+ {
+ favoriteDTOs.Add(favorite.ToDto());
+ }
+ return favoriteDTOs;
+ }
+
+ public static ImageDTO ToDto(this Images item)
+ {
+ if (item == null) return null;
+ ImageDTO image = new ImageDTO();
+ image.IdImage = item.Id;
+ image.ImagePath = item.ImgPath;
+ return image;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List imageDTOs = new List();
+ foreach (Images images in item)
+ {
+ imageDTOs.Add(images.ToDto());
+ }
+ return imageDTOs;
+ }
+
+ public static QuestionDTO ToDto(this Question item)
+ {
+ if (item == null) return null;
+ QuestionDTO question = new QuestionDTO();
+ question.Id = item.Id;
+ question.Question = item.Text;
+ question.AnswerA = item.AnswerA;
+ question.AnswerB = item.AnswerB;
+ question.AnswerC = item.AnswerC;
+ question.AnswerD = item.AnswerD;
+ question.CorrectAnswer = item.CorrectAnswer;
+ return question;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List questionDTOs = new List();
+ foreach (Question question in item)
+ {
+ questionDTOs.Add(question.ToDto());
+ }
+ return questionDTOs;
+ }
+
+ public static QuizDTO ToDto(this Quiz item)
+ {
+ if (item == null) return null;
+ QuizDTO quiz = new QuizDTO();
+ quiz.Id = item.Id;
+ quiz.NbQuestion = item.NbQuestion;
+ quiz.Title = item.Title;
+ quiz.ImagePath = item.Images.ImgPath;
+ return quiz;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List quizDTOs = new List();
+ foreach (Quiz quiz in item)
+ {
+ quizDTOs.Add(quiz.ToDto());
+ }
+ return quizDTOs;
+ }
+
+ // Surement a refaire car QuizQuestion Entity modifier sur branche EF
+ public static QuizQuestionDTO ToDto(this QuizQuestion item)
+ {
+ if (item == null) return null;
+ QuizQuestionDTO quizQuestion = new QuizQuestionDTO();
+ quizQuestion.IdQuiz = item.IdQuiz;
+ quizQuestion.IdQuestion = item.IdQuestion;
+ return quizQuestion;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List quizQuestionDTOs = new List();
+ foreach (QuizQuestion quizQuestion in item)
+ {
+ quizQuestionDTOs.Add(quizQuestion.ToDto());
+ }
+ return quizQuestionDTOs;
+ }
+
+ public static QuoteDTO ToDto(this Quote item)
+ {
+ if (item == null) return null;
+ QuoteDTO quote = new QuoteDTO();
+ quote.Id = item.Id;
+ quote.Content = item.Content;
+ quote.DateSource = item.Source.Year;
+ quote.Character = item.Character.Name;
+ quote.TitleSource = item.Source.Title;
+ quote.Langage = item.Langage.ToDto();
+ quote.ImagePath = item.Character.Images.ImgPath;
+ quote.Like = item.Likes;
+ quote.Type = item.Source.TypeSrc.ToDto();
+ quote.IsValide = item.IsValid;
+ return quote;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List quoteDTOs = new List();
+ foreach (Quote quote in item)
+ {
+ quoteDTOs.Add(quote.ToDto());
+ }
+ return quoteDTOs;
+ }
+
+ public static SourceDTO ToDto(this Source item)
+ {
+ if (item == null) return null;
+ SourceDTO source = new SourceDTO();
+ source.Id = item.Id;
+ source.Date = item.Year;
+ source.Title = item.Title;
+ source.Type = item.TypeSrc.ToDto();
+ return source;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List sourceDTOs = new List();
+ foreach (Source source in item)
+ {
+ sourceDTOs.Add(source.ToDto());
+ }
+ return sourceDTOs;
+ }
+
+ public static UserDTO ToDto(this Users item)
+ {
+ if (item == null) return null;
+ UserDTO user = new UserDTO();
+ user.Id = item.Id;
+ user.Pseudo = item.UserName;
+ user.Password = item.Password;
+ user.Email = item.Email;
+ user.date = item.Created;
+ user.ImageProfil = item.Images.ImgPath;
+ return user;
+ }
+
+ public static List ToDto(this List item)
+ {
+ List users = new List();
+ foreach (Users user in item)
+ {
+ users.Add(user.ToDto());
+ }
+ return users;
+ }
+
+ public static TypeLangageDTO ToDto(this LangEnum item)
+ {
+ switch (item)
+ {
+ case LangEnum.vf: return TypeLangageDTO.vf;
+ case LangEnum.vo: return TypeLangageDTO.vo;
+ default: return TypeLangageDTO.vo;
+ }
+ }
+
+ public static TypeSrcEnumDTO ToDto(this TypeSrcEnum item)
+ {
+ switch (item)
+ {
+ case TypeSrcEnum.movie: return TypeSrcEnumDTO.movie;
+ case TypeSrcEnum.book: return TypeSrcEnumDTO.book;
+ case TypeSrcEnum.series: return TypeSrcEnumDTO.serie;
+ case TypeSrcEnum.videogame: return TypeSrcEnumDTO.videogame;
+ default: return TypeSrcEnumDTO.movie;
+ }
+ }
+
+ // --------------------------- ToEntity --------------------------- \\
+
+
+ public static Character ToEntity(this CharacterDTO item)
+ {
+ if (item == null) return null;
+ Character character = new Character();
+ character.Id = item.Id;
+ character.Name = item.Name;
+ character.Images.ImgPath = item.imagePath ;
+ return character;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List characters = new List();
+ foreach (CharacterDTO character in item)
+ {
+ characters.Add(character.ToEntity());
+ }
+ return characters;
+ }
+
+ public static Commentary ToEntity(this CommentaryDTO item)
+ {
+ if (item == null) return null;
+ Commentary commentary = new Commentary();
+ commentary.Id = item.Id;
+ commentary.DateCommentary = item.Date;
+ commentary.Comment = item.Comment;
+ commentary.User = new Users();
+ commentary.User.UserName = item.User;
+ commentary.User.Images = new Images();
+ commentary.User.Images.ImgPath = item.ImagePath;
+ return commentary;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List commentarys = new List();
+ foreach (CommentaryDTO commentary in item)
+ {
+ commentarys.Add(commentary.ToEntity());
+ }
+ return commentarys;
+ }
+
+ // Surement a refaire car Faoirite Entity modifier sur branche EF
+ public static Favorite ToEntity(this FavoriteDTO item)
+ {
+ if (item == null) return null;
+ Favorite favorite = new Favorite();
+ favorite.IdUsers = item.IdUser;
+ favorite.IdQuote = item.IdQuote;
+ return favorite;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List favorites = new List();
+ foreach (FavoriteDTO favorite in item)
+ {
+ favorites.Add(favorite.ToEntity());
+ }
+ return favorites;
+ }
+
+ public static Images ToEntity(this ImageDTO item)
+ {
+ if (item == null) return null;
+ Images image = new Images();
+ image.Id = item.IdImage;
+ image.ImgPath = item.ImagePath;
+ return image;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List images = new List();
+ foreach (ImageDTO image in item)
+ {
+ images.Add(image.ToEntity());
+ }
+ return images;
+ }
+
+ public static Question ToEntity(this QuestionDTO item)
+ {
+ if (item == null) return null;
+ Question question = new Question();
+ question.Id = item.Id;
+ question.Text = item.Question;
+ question.AnswerA = item.AnswerA;
+ question.AnswerB = item.AnswerB;
+ question.AnswerC = item.AnswerC;
+ question.AnswerD = item.AnswerD;
+ question.CorrectAnswer = item.CorrectAnswer;
+ return question;
+ }
+ public static List ToEntity(this List item)
+ {
+ List questions = new List();
+ foreach (QuestionDTO question in item)
+ {
+ questions.Add(question.ToEntity());
+ }
+ return questions;
+ }
+
+ public static Quiz ToEntity(this QuizDTO item)
+ {
+ if (item == null) return null;
+ Quiz quiz = new Quiz();
+ quiz.Id = item.Id;
+ quiz.NbQuestion = item.NbQuestion;
+ quiz.Title = item.Title;
+ quiz.Images.ImgPath = item.ImagePath;
+ return quiz;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List quizs = new List();
+ foreach (QuizDTO quiz in item)
+ {
+ quizs.Add(quiz.ToEntity());
+ }
+ return quizs;
+ }
+
+ // Surement a refaire car QuizQuestion Entity modifier sur branche EF
+ public static QuizQuestion ToEntity(this QuizQuestionDTO item)
+ {
+ if (item == null) return null;
+ QuizQuestion quizQuestion = new QuizQuestion();
+ quizQuestion.IdQuiz = item.IdQuiz;
+ quizQuestion.IdQuestion = item.IdQuestion;
+ return quizQuestion;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List quizQuestions = new List();
+ foreach (QuizQuestionDTO quizQuestion in item)
+ {
+ quizQuestions.Add(quizQuestion.ToEntity());
+ }
+ return quizQuestions;
+ }
+
+ public static Quote ToEntity(this QuoteDTO item)
+ {
+ if (item == null) return null;
+ Quote quote = new Quote();
+ quote.Id = item.Id;
+ quote.Content = item.Content;
+ quote.Source = new Source();
+ quote.Source.Year = item.DateSource;
+ quote.Character = new Character();
+ quote.Character.Name = item.Character;
+ quote.Source.Title = item.TitleSource;
+ quote.Langage = item.Langage.ToEntity();
+ quote.Character.Images = new Images();
+ quote.Character.Images.ImgPath = item.ImagePath;
+ quote.Likes = item.Like;
+ quote.Source.TypeSrc = item.Type.ToEntity();
+ quote.IsValid = item.IsValide;
+ return quote;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List quotes = new List();
+ foreach (QuoteDTO quote in item)
+ {
+ quotes.Add(quote.ToEntity());
+ }
+ return quotes;
+ }
+
+ public static Source ToEntity(this SourceDTO item)
+ {
+ if (item == null) return null;
+ Source source = new Source();
+ source.Id = item.Id;
+ source.Year = item.Date;
+ source.Title = item.Title;
+ source.TypeSrc = item.Type.ToEntity();
+ return source;
+ }
+
+ public static List ToEntity(this List item)
+ {
+ List