From d8c91fd73e29fc8a29182a2ca1501ed4f2ddbec4 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 25 Mar 2025 16:36:44 +0100 Subject: [PATCH] GenericRepository + Modification DbManager + Mapper --- WF_EF_Api/ConsoleTest/Program.cs | 6 +- WF_EF_Api/Contextlib/Contextlib.csproj | 1 + WF_EF_Api/Contextlib/DbCharacterManager.cs | 84 ++++------ WF_EF_Api/Contextlib/DbCommentaryManager.cs | 11 +- WF_EF_Api/Contextlib/DbImagesManager.cs | 87 ++++------ WF_EF_Api/Contextlib/DbQuestionManager.cs | 155 ++++++++++++++++++ WF_EF_Api/Contextlib/DbQuestionSerice.cs | 73 --------- WF_EF_Api/Contextlib/GenericRepository.cs | 120 ++++++++++++++ WF_EF_Api/Entity/Question.cs | 3 + WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 18 +- 10 files changed, 364 insertions(+), 194 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbQuestionManager.cs delete mode 100644 WF_EF_Api/Contextlib/DbQuestionSerice.cs create mode 100644 WF_EF_Api/Contextlib/GenericRepository.cs diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs index 7a36b87..4c4c4f5 100644 --- a/WF_EF_Api/ConsoleTest/Program.cs +++ b/WF_EF_Api/ConsoleTest/Program.cs @@ -22,8 +22,8 @@ using (var _context = new StubWTFContext(options)) var imageManager = new DbImagesManager(_context); - await imageManager.AddImage(new Images() { Id = 11, 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 = 12, 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" }); + 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) @@ -82,7 +82,7 @@ using (var _context = new StubWTFContext(options)) var characterManager = new DbCharacterManager(_context); - await characterManager.AddCharacter(new Character() { Id = 11, Name = "Vipélière", IdImage = 11 }); + 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) diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj index d2b9100..960e394 100644 --- a/WF_EF_Api/Contextlib/Contextlib.csproj +++ b/WF_EF_Api/Contextlib/Contextlib.csproj @@ -18,6 +18,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs index e0d75e1..9b36686 100644 --- a/WF_EF_Api/Contextlib/DbCharacterManager.cs +++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs @@ -12,10 +12,12 @@ 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); } /// @@ -28,10 +30,9 @@ namespace Contextlib { if (character == null) { - throw new ArgumentNullException(nameof(character), "Character cannot be null."); + throw new ArgumentNullException(nameof(character), "character cannot be null."); } - - await _context.AddAsync(character); + _repo.Insert(character); await _context.SaveChangesAsync(); } @@ -39,11 +40,10 @@ namespace Contextlib /// 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 Task> GetAll() + public async Task> GetAll() { - List charLst = _context.characters.Include(i => i.Images).ToList(); - - return Task.FromResult(new PaginationResult(charLst.Count, 0, charLst.Count, charLst)); + List charLst = _repo.GetItems(0, _repo.Count(), [nameof(Character.Images)]).ToList(); + return new PaginationResult(charLst.Count, 0, charLst.Count, charLst); } /// @@ -54,15 +54,11 @@ namespace Contextlib /// Thrown when no character is found with the given ID. public async Task GetCharById(int id) { - Character? character = await _context.characters - .Include(i => i.Images) - .FirstOrDefaultAsync(x => x.Id == 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; } @@ -74,9 +70,7 @@ namespace Contextlib /// Thrown when no character is found with the given name. public async Task GetCharByName(string name) { - var character = await _context.characters - .Where(c => EF.Functions.Like(c.Name, name)) - .FirstOrDefaultAsync(); + var character = _repo.GetItems(item => item.Name == name,0,1, [nameof(Character.Images)]).FirstOrDefault(); if (character == null) { @@ -92,11 +86,16 @@ namespace Contextlib /// The highest character ID in the database. 0 if there is no character in the database public async Task GetLastCharId() { - int id = await _context.characters - .OrderByDescending(x => x.Id) - .Select(x => x.Id) - .FirstOrDefaultAsync(); - return id; + PaginationResult characters = await GetAll(); + int lastCharId = 0; + foreach (Character character in characters.items) + { + if (character.Id >= lastCharId) + { + lastCharId = character.Id + 1; + } + } + return lastCharId; } /// @@ -107,13 +106,7 @@ namespace Contextlib /// Thrown when no character is found with the given ID. public async Task RemoveCharacter(int id) { - Character? character = await _context.characters.FirstOrDefaultAsync(x => x.Id == id); - if (character == null) - { - throw new KeyNotFoundException($"Error : Unable to delete, no character found with the ID: {id}."); - } - - _context.characters.Remove(character); + _repo.Delete(id); await _context.SaveChangesAsync(); } @@ -127,29 +120,22 @@ namespace Contextlib /// Thrown when no character is found with the given ID. public async Task UpdateCharacter(int id, Character character) { - if (character == null) - { - throw new ArgumentNullException(nameof(character), "The updated character data cannot be null."); - } - var modif = false; - Character? charUpdated = await _context.characters.FirstOrDefaultAsync(x => x.Id == id); - if (charUpdated == null) - { - throw new KeyNotFoundException($"Error : Unable to update, no character found with the ID: {id} ."); - } - if (character.IdImage != 0) - { - charUpdated.IdImage = character.IdImage; - modif = true; - } - if (character.Name != null) - { - charUpdated.Name = character.Name; - modif = true; - } - if (modif) + Character? charac = _repo.GetById(id); + if (charac != null && charac != null) { - await _context.SaveChangesAsync(); + 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 index e5bde4f..c498637 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -13,10 +13,12 @@ namespace Contextlib public class DbCommentManager : ICommentService { private WTFContext _context; + private GenericRepository _repo; public DbCommentManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(context); } /// @@ -32,7 +34,7 @@ namespace Contextlib throw new ArgumentNullException(nameof(comment), "Comment cannot be null."); } - await _context.comments.AddAsync(comment); + _repo.Insert(comment); await _context.SaveChangesAsync(); } @@ -144,12 +146,7 @@ namespace Contextlib public async Task RemoveComment(int id) { - var comment = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (comment == null) - { - throw new KeyNotFoundException($"No comments found with the given ID: {id}."); - } - _context.comments.Remove(comment); + _repo.Delete(id); await _context.SaveChangesAsync(); } diff --git a/WF_EF_Api/Contextlib/DbImagesManager.cs b/WF_EF_Api/Contextlib/DbImagesManager.cs index ad51785..999f546 100644 --- a/WF_EF_Api/Contextlib/DbImagesManager.cs +++ b/WF_EF_Api/Contextlib/DbImagesManager.cs @@ -13,97 +13,78 @@ 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) { - await _context.AddAsync(image); + _repository.Insert(image); await _context.SaveChangesAsync(); } public async Task> GetAllImage() { - var images = await _context.images.ToListAsync(); - return new PaginationResult(images.Count, 0, images.Count, images); + return new PaginationResult(await CountImage(), 0, await CountImage(), _repository.GetItems(0, await CountImage()).ToList()); } public async Task GetImageById(int id) { - var image = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (image == null) - { - throw new KeyNotFoundException($"No image found with the given ID: {id}."); - } - return image; + return _repository.GetById(id); } public async Task GetLastImageId() { - var last = await _context.images.OrderByDescending(x => x.Id).FirstOrDefaultAsync(); - if (last == null) + var last = await GetAllImage(); + int id = 1; { - return 0; + foreach (Images image in last.items) + { + if(image.Id >= id) + id = image.Id + 1; + } } - return last.Id; + return id; } public async Task> GetSomeImage(int index, int pageSize) { - var images = await _context.images.ToListAsync(); - if (!images.Any()) - { - throw new KeyNotFoundException($"No images found"); - } - if ((index * pageSize + pageSize) > images.Count) - { - if (pageSize > images.Count) - { - return new PaginationResult(images.Count(), index, pageSize, images); - } - else - { - return new PaginationResult(pageSize, index, pageSize, images.Skip(index * pageSize - (((index * pageSize) + pageSize) - images.Count)).Take(pageSize).ToList()); - } - } - return new PaginationResult(images.Count, index, pageSize, images.Skip(index * pageSize).Take(pageSize).ToList()); + var images = _repository.GetItems(index, pageSize); + return new PaginationResult(images.Count(),index,pageSize,images.ToList()); } public async Task RemoveImage(int id) { - var image = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (image == null) - { - throw new KeyNotFoundException($"No image found with the given ID: {id}."); - } - _context.images.Remove(image); + _repository.Delete(id); await _context.SaveChangesAsync(); } public async Task UpdateImage(int id, Images image) { + var img = _repository.GetById(id); var modif = false; - var img = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (image == null) + if (image != null && img != null) { - throw new ArgumentNullException(nameof(image), "The updated image data cannot be null."); - } - if (img == null) - { - throw new KeyNotFoundException($"No image found with the given ID: {id}."); - } - if (image.ImgPath != null) - { - img.ImgPath = image.ImgPath; - modif = true; - } - if (modif) - { - await _context.SaveChangesAsync(); - } + 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(); } } } 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/DbQuestionSerice.cs b/WF_EF_Api/Contextlib/DbQuestionSerice.cs deleted file mode 100644 index 010f38c..0000000 --- a/WF_EF_Api/Contextlib/DbQuestionSerice.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Entity; -using Shared; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Contextlib -{ - public class DbQuestionSerice : IQuestionService - { - public Task AddQuestion(Question question) - { - throw new NotImplementedException(); - } - - public Task CountQuestions() - { - throw new NotImplementedException(); - } - - public Task> GetAllQuestion() - { - throw new NotImplementedException(); - } - - public Task> GetInvalidQuestion(int index, int pageSize) - { - throw new NotImplementedException(); - } - - public Task GetQuestionById(int id) - { - throw new NotImplementedException(); - } - - public Task GetRandomQuestion() - { - throw new NotImplementedException(); - } - - public Task GetRandomQuestionQuoteToCharacter() - { - throw new NotImplementedException(); - } - - public Task GetRandomQuestionQuoteToSource() - { - throw new NotImplementedException(); - } - - public Task> GetSomeQuestion(int index, int pageSize) - { - throw new NotImplementedException(); - } - - public Task RemoveQuestion(int id) - { - throw new NotImplementedException(); - } - - public Task UpdateQuestion(int id, Question question) - { - throw new NotImplementedException(); - } - - public Task ValidateQuestion(int id, bool isvalid) - { - throw new NotImplementedException(); - } - } -} 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/Entity/Question.cs b/WF_EF_Api/Entity/Question.cs index b2e37e9..19c211b 100644 --- a/WF_EF_Api/Entity/Question.cs +++ b/WF_EF_Api/Entity/Question.cs @@ -38,6 +38,9 @@ namespace Entity [StringLength(1)] public string CorrectAnswer { get; set; } + [Required] + public bool IsValid { get; set; } + public ICollection Quizs { get; set; } = new List(); } } diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 7c04527..7381211 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -97,16 +97,16 @@ namespace StubbedContextLib modelBuilder.Entity().HasData( - new Question() { Id = 1, Text = "Qui est le leader de la Communauté de l'Anneau ?", AnswerA = "Gimli", AnswerB = "Aragorn", AnswerC = "Frodon", AnswerD = "Gandalf", CorrectAnswer = "B" }, + new Question() { Id = 1, Text = "Qui est le leader de la Communauté de l'Anneau ?", AnswerA = "Gimli", AnswerB = "Aragorn", AnswerC = "Frodon", AnswerD = "Gandalf", CorrectAnswer = "B", IsValid = true }, new Question() { Id = 2, Text = "Dans quelle maison Harry Potter est-il ?", AnswerA = "Serdaigle", AnswerB = "Gryffondor", AnswerC = "Serpentard", AnswerD = "Poufsouffle", CorrectAnswer = "B" }, - new Question() { Id = 3, Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?", AnswerA = "Saroumane", AnswerB = "Sauron", AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B" }, - new Question() { Id = 4, Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?", AnswerA = "Han Solo", AnswerB = "Princesse Leia", AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A" }, - new Question() { Id = 5, Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?", AnswerA = "Reine Jadis", AnswerB = "Aslan", AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B" }, - new Question() { Id = 6, Text = "Quel est le nom du dragon dans Le Hobbit ?", AnswerA = "Smaug", AnswerB = "Falkor", AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A" }, - new Question() { Id = 7, Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?", AnswerA = "Bella Swan", AnswerB = "Edward Cullen", AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A" }, - new Question() { Id = 8, Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?", AnswerA = "Obi-Wan Kenobi", AnswerB = "Yoda", AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A" }, - new Question() { Id = 9, Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?", AnswerA = "Dr. Ellie Sattler", AnswerB = "Alan Grant", AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B" }, - new Question() { Id = 10, Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?", AnswerA = "Cersei Lannister", AnswerB = "Arya Stark", AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C" } + new Question() { Id = 3, Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?", AnswerA = "Saroumane", AnswerB = "Sauron", AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B", IsValid = true }, + new Question() { Id = 4, Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?", AnswerA = "Han Solo", AnswerB = "Princesse Leia", AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 5, Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?", AnswerA = "Reine Jadis", AnswerB = "Aslan", AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B", IsValid = true }, + new Question() { Id = 6, Text = "Quel est le nom du dragon dans Le Hobbit ?", AnswerA = "Smaug", AnswerB = "Falkor", AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 7, Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?", AnswerA = "Bella Swan", AnswerB = "Edward Cullen", AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 8, Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?", AnswerA = "Obi-Wan Kenobi", AnswerB = "Yoda", AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 9, Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?", AnswerA = "Dr. Ellie Sattler", AnswerB = "Alan Grant", AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B", IsValid = true }, + new Question() { Id = 10, Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?", AnswerA = "Cersei Lannister", AnswerB = "Arya Stark", AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C", IsValid = true } ); modelBuilder.Entity().HasData(