GenericRepository + Modification DbManager + Mapper

Relation_EF
Kevin MONDEJAR 4 weeks ago
parent 48a5f9856e
commit d8c91fd73e

@ -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)

@ -18,6 +18,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NLog" Version="5.4.0" />
</ItemGroup>
<ItemGroup>

@ -12,10 +12,12 @@ namespace Contextlib
public class DbCharacterManager : ICharacterService<Character>
{
private WTFContext _context;
private GenericRepository<Character> _repo;
public DbCharacterManager(WTFContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
_repo = new GenericRepository<Character>(_context);
}
/// <summary>
@ -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.
/// </summary>
/// <returns>A task representing the asynchronous operation, with a <see cref="PaginationResult{Character}"/> as its result containing the full list of characters and pagination information.</returns>
public Task<PaginationResult<Character>> GetAll()
public async Task<PaginationResult<Character>> GetAll()
{
List<Character> charLst = _context.characters.Include(i => i.Images).ToList();
return Task.FromResult(new PaginationResult<Character>(charLst.Count, 0, charLst.Count, charLst));
List<Character> charLst = _repo.GetItems(0, _repo.Count(), [nameof(Character.Images)]).ToList();
return new PaginationResult<Character>(charLst.Count, 0, charLst.Count, charLst);
}
/// <summary>
@ -54,15 +54,11 @@ namespace Contextlib
/// <exception cref="KeyNotFoundException">Thrown when no character is found with the given ID.</exception>
public async Task<Character> 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
/// <exception cref="KeyNotFoundException">Thrown when no character is found with the given name.</exception>
public async Task<Character> 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
/// <returns>The highest character ID in the database. 0 if there is no character in the database</returns>
public async Task<int> GetLastCharId()
{
int id = await _context.characters
.OrderByDescending(x => x.Id)
.Select(x => x.Id)
.FirstOrDefaultAsync();
return id;
PaginationResult<Character> characters = await GetAll();
int lastCharId = 0;
foreach (Character character in characters.items)
{
if (character.Id >= lastCharId)
{
lastCharId = character.Id + 1;
}
}
return lastCharId;
}
/// <summary>
@ -107,13 +106,7 @@ namespace Contextlib
/// <exception cref="KeyNotFoundException">Thrown when no character is found with the given ID.</exception>
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
/// <exception cref="KeyNotFoundException">Thrown when no character is found with the given ID.</exception>
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();
}
}
}

@ -13,10 +13,12 @@ namespace Contextlib
public class DbCommentManager : ICommentService<Commentary>
{
private WTFContext _context;
private GenericRepository<Commentary> _repo;
public DbCommentManager(WTFContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
_repo = new GenericRepository<Commentary>(context);
}
/// <summary>
@ -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();
}

@ -13,97 +13,78 @@ namespace Contextlib
public class DbImagesManager : IImagesService<Images>
{
private WTFContext _context;
private GenericRepository<Images> _repository;
public DbImagesManager(WTFContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
_repository = new GenericRepository<Images>(context);
}
public async Task AddImage(Images image)
{
await _context.AddAsync(image);
_repository.Insert(image);
await _context.SaveChangesAsync();
}
public async Task<PaginationResult<Images>> GetAllImage()
{
var images = await _context.images.ToListAsync();
return new PaginationResult<Images>(images.Count, 0, images.Count, images);
return new PaginationResult<Images>(await CountImage(), 0, await CountImage(), _repository.GetItems(0, await CountImage()).ToList());
}
public async Task<Images> 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<int> 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<PaginationResult<Images>> 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>(images.Count(), index, pageSize, images);
}
else
{
return new PaginationResult<Images>(pageSize, index, pageSize, images.Skip(index * pageSize - (((index * pageSize) + pageSize) - images.Count)).Take(pageSize).ToList());
}
}
return new PaginationResult<Images>(images.Count, index, pageSize, images.Skip(index * pageSize).Take(pageSize).ToList());
var images = _repository.GetItems(index, pageSize);
return new PaginationResult<Images>(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<int> CountImage()
{
return await _context.images.CountAsync();
}
}
}

@ -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<Question>
{
private WTFContext _context;
private GenericRepository<Question> _repository;
public DbQuestionManager(WTFContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null.");
_repository = new GenericRepository<Question>(context);
}
public async Task AddQuestion(Question question)
{
_repository.Insert(question);
await _context.SaveChangesAsync();
}
public async Task<int> CountQuestions()
{
return _repository.Count();
}
public async Task<PaginationResult<Question>> GetAllQuestion()
{
return new PaginationResult<Question>(_repository.Count(), 0, _repository.Count(), _repository.GetItems(0,_repository.Count()).ToList());
}
public async Task<PaginationResult<Question>> GetInvalidQuestion(int index, int pageSize)
{
List<Question> questionList = _repository.GetItems(item => item.IsValid == false, index, pageSize).ToList();
return new PaginationResult<Question>(questionList.Count(), index, pageSize, questionList);
}
public async Task<Question> GetQuestionById(int id)
{
return _repository.GetById(id);
}
public async Task<Question> 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<Question> GetRandomQuestionQuoteToCharacter()
{
//dabord implémenter get random quote
throw new NotImplementedException();
}
public async Task<Question> GetRandomQuestionQuoteToSource()
{
//dabord implémenter get random quote
throw new NotImplementedException();
}
public async Task<PaginationResult<Question>> GetSomeQuestion(int index, int pageSize)
{
List<Question> questionList = _repository.GetItems(item => item.IsValid == false, index, pageSize).ToList();
return new PaginationResult<Question>(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<int> LastId()
{
PaginationResult<Question> questions = await GetAllQuestion();
int id = 1;
foreach (Question question in questions.items)
{
if (question.Id >= id)
{
id = question.Id + 1;
}
}
return id;
}
}
}

@ -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<Question>
{
public Task AddQuestion(Question question)
{
throw new NotImplementedException();
}
public Task<int> CountQuestions()
{
throw new NotImplementedException();
}
public Task<PaginationResult<Question>> GetAllQuestion()
{
throw new NotImplementedException();
}
public Task<PaginationResult<Question>> GetInvalidQuestion(int index, int pageSize)
{
throw new NotImplementedException();
}
public Task<Question> GetQuestionById(int id)
{
throw new NotImplementedException();
}
public Task<Question> GetRandomQuestion()
{
throw new NotImplementedException();
}
public Task<Question> GetRandomQuestionQuoteToCharacter()
{
throw new NotImplementedException();
}
public Task<Question> GetRandomQuestionQuoteToSource()
{
throw new NotImplementedException();
}
public Task<PaginationResult<Question>> 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();
}
}
}

@ -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<T> where T : class
{
private DbContext Context { get; set; }
private DbSet<T> Set { get; set; }
public GenericRepository(DbContext context)
{
Context = context;
Set = Context.Set<T>();
}
public virtual T? GetById(object id)
=> Set.Find(id);
public virtual T? GetById(object id, Expression<Func<T, bool>>? filter = null, params string[] includeProperties)
{
IQueryable<T> query = Set;
if (filter != null)
{
query = query.Where(filter);
}
foreach (string includeProperty in includeProperties)
{
query = query.Include(includeProperty);
}
return query.FirstOrDefault();
}
public virtual IEnumerable<T> GetItems(Expression<Func<T, bool>>? filter = null,
int index = 0, int count = 10,
params string[] includeProperties)
=> GetItems(filter, null, index, count, includeProperties);
public virtual IEnumerable<T> GetItems(Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
int index = 0, int count = 10,
params string[] includeProperties)
=> GetItems(null, orderBy, index, count, includeProperties);
public virtual IEnumerable<T> GetItems(int index = 0, int count = 10,
params string[] includeProperties)
=> GetItems(null, null, index, count, includeProperties);
public virtual IEnumerable<T> GetItems(Expression<Func<T, bool>>? filter = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
int index = 0, int count = 10,
params string[] includeProperties)
{
IQueryable<T> 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();
}
}
}

@ -38,6 +38,9 @@ namespace Entity
[StringLength(1)]
public string CorrectAnswer { get; set; }
[Required]
public bool IsValid { get; set; }
public ICollection<Quiz> Quizs { get; set; } = new List<Quiz>();
}
}

@ -97,16 +97,16 @@ namespace StubbedContextLib
modelBuilder.Entity<Question>().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<Quiz>().HasData(

Loading…
Cancel
Save