Files
webzine/Webzine.Repository/DbEntityRepository.cs
2026-03-26 15:02:34 +01:00

63 lines
2.0 KiB
C#

// <copyright file="DbEntityRepository.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Repository
{
using Webzine.EntitiesContext;
using Webzine.Entity;
using Webzine.Entity.Fixtures;
using Webzine.Repository.Fake;
public class DbEntityRepository
{
private readonly WebzineDbContext context;
public DbEntityRepository(WebzineDbContext context)
{
this.context = context;
}
public void SeedBaseDeDonnees(
int nbArtistes = 100,
int nbTitres = 500,
int minStyles = 15,
int maxStyles = 20,
int minCommentairesParTitre = 0,
int maxCommentairesParTitre = 5)
{
if (this.context.Artistes.Any() ||
this.context.Titres.Any() ||
this.context.Styles.Any() ||
this.context.Commentaires.Any())
{
return;
}
List<Artiste> artistes = ArtisteFactory.CreerListeArtiste(nbArtistes);
List<Style> styles = StyleFactory.CreerListeStyle(minStyles, maxStyles);
this.context.Artistes.AddRange(artistes);
this.context.Styles.AddRange(styles);
this.context.SaveChanges();
List<Titre> titres = TitreFactory.CreerListeTitre(nbTitres, artistes, styles);
this.context.Titres.AddRange(titres);
this.context.SaveChanges();
List<Commentaire> commentaires = new List<Commentaire>();
foreach (Titre titre in titres)
{
commentaires.AddRange(
CommentaireFactory.CreerListeCommentaire(
titre,
minCommentairesParTitre,
maxCommentairesParTitre));
}
this.context.Commentaires.AddRange(commentaires);
this.context.SaveChanges();
}
}
}