Ejemplo n.º 1
0
        /// <summary>
        /// Ajoute un Titre dans le set de données
        /// </summary>
        /// <param name="titre">Titre à ajouter</param>
        void ITitreRepository.Add(Titre titre)
        {
            Artiste artisteContext = _dbContext.Artistes.FirstOrDefault(x => x.IdArtiste == titre.IdArtiste);

            titre.IdArtiste = artisteContext.IdArtiste;
            titre.Artiste   = artisteContext;

            List <LienStyle> liensStyle = new List <LienStyle>();

            foreach (var newStyle in titre.LienStyle)
            {
                Style style = _dbContext.Styles.FirstOrDefault(styleContext => styleContext.IdStyle == newStyle.IdStyle);
                liensStyle.Add(new LienStyle {
                    IdStyle = style.IdStyle, Style = style, IdTitre = titre.IdTitre, Titre = titre
                });;
            }
            titre.LienStyle.Clear();
            titre.LienStyle = liensStyle;

            _dbContext.Titres.Add(titre);
            _dbContext.SaveChanges();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Méthode pour ajouter un nouveau commentaire.
 /// </summary>
 /// <param name="commentaire">Le commentaire à ajouter.</param>
 public void Add(Commentaire commentaire)
 {
     context.Commentaires.Add(commentaire);
     context.SaveChanges();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Méthode pour supprimer un titre.
 /// </summary>
 /// <param name="titre">Le titre à supprimer.</param>
 public void Delete(Titre titre)
 {
     context.Titres.Remove(titre);
     context.SaveChanges();
 }
Ejemplo n.º 4
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            // Si le fichier de config contient
            if (Configuration["DataSource"] == "factory")
            {
                // StaticFactory
                StaticFactory.UpdateBinavigabilite();
            }

            else if (Configuration["DataSource"] == "local")
            {
                using (var client = new WebzineDbContext())
                {
                    if (Configuration["ResetDb"] == "true")
                    {
                        client.Database.EnsureDeleted();
                        client.Database.EnsureCreated();

                        // Load data in database
                        LocalSeeder seeder = new LocalSeeder(client, StaticFactory.Styles, StaticFactory.Titres, StaticFactory.Artistes, StaticFactory.Commentaires, StaticFactory.LienStyles, StaticFactory.Pays);
                        seeder.LoadData();
                        client.SaveChanges();
                    }

                    else
                    {
                        client.Database.EnsureCreated();
                    }
                }
            }

            else if (Configuration["DataSource"] == "spotify")
            {
                // sqlite
                using (var client = new WebzineDbContext())
                {
                    client.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
                    if (Configuration["ResetDb"] == "true")
                    {
                        client.Database.EnsureDeleted();
                        client.Database.EnsureCreated();

                        SpotifySeeder spotify = new SpotifySeeder("1a3478c9f18842bc9fee8692aa574973", "943d3a231566443ba543d0e20a673d44");

                        var    playlist = spotify.GetPlaylist(Configuration["SpotifyPlaylistId"]);
                        Seeder seed     = spotify.SeedFromPlaylist(client, playlist);

                        client.SaveChanges();

                        var spotifyStyle    = client.Styles.FirstOrDefault();
                        List <LienStyle> ls = new List <LienStyle>();
                        client.Titres.ToList().ForEach(t => ls.Add(new LienStyle {
                            IdStyle = spotifyStyle.IdStyle, IdTitre = t.IdTitre
                        }));

                        ls.ForEach(l => client.LienStyles.Add(l));

                        client.SaveChanges();
                    }

                    else
                    {
                        client.Database.EnsureCreated();
                    }
                }
            }
            else
            {
                // erreur mise de factory par default
                StaticFactory.UpdateBinavigabilite();
            }
        }