63 lines
2.2 KiB
C#
63 lines
2.2 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;
|
|
|
|
public class DbEntityRepository
|
|
{
|
|
private readonly WebzineDbContext context;
|
|
|
|
public DbEntityRepository(WebzineDbContext context)
|
|
{
|
|
this.context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Seed la base de donnée à l'aide de SeedDataLocal.
|
|
/// </summary>
|
|
/// <param name="nbArtistes">Nombre d'artiste.</param>
|
|
/// <param name="nbTitres">Nombre de titre.</param>
|
|
/// <param name="minStyles">Nombre min de style.</param>
|
|
/// <param name="maxStyles">Nombre mac de style.</param>
|
|
public void SeedBaseDeDonnees(
|
|
int nbArtistes = 100,
|
|
int nbTitres = 500,
|
|
int minStyles = 15,
|
|
int maxStyles = 20)
|
|
{
|
|
if (this.context.Artistes.Any() ||
|
|
this.context.Titres.Any() ||
|
|
this.context.Styles.Any() ||
|
|
this.context.Commentaires.Any())
|
|
{
|
|
return;
|
|
}
|
|
|
|
List<Artiste> artistes = SeedDataLocal.GenererListeArtiste(nbArtistes);
|
|
List<Style> styles = SeedDataLocal.GenererListeStyle(minStyles, maxStyles);
|
|
|
|
this.context.Artistes.AddRange(artistes);
|
|
this.context.Styles.AddRange(styles);
|
|
this.context.SaveChanges();
|
|
|
|
List<string> albums = SeedDataLocal.GenererListeAlbums(3);
|
|
List<Titre> titres = SeedDataLocal.GenererListeTitre(nbTitres, artistes, styles, albums);
|
|
|
|
int commentaireIdStart = 1;
|
|
foreach (var titre in titres)
|
|
{
|
|
var commentairesDuTitre = SeedDataLocal.GenererListeCommentaire(titre, 0, 5, commentaireIdStart);
|
|
titre.Commentaires.AddRange(commentairesDuTitre);
|
|
commentaireIdStart += commentairesDuTitre.Count;
|
|
}
|
|
|
|
this.context.Titres.AddRange(titres);
|
|
this.context.SaveChanges();
|
|
}
|
|
}
|
|
} |