public List <Genre> GetGenres()
        {
            var context = VideothequeDbContext.GetCurrent().Result;
            var genres  = context.Genres.ToList();

            if (genres.Count == 0)
            {
                context.Genres.Add(new Genre {
                    Nom = "Horreur"
                });
                context.Genres.Add(new Genre {
                    Nom = "SF"
                });
                context.Genres.Add(new Genre {
                    Nom = "Aventure"
                });
                context.Genres.Add(new Genre {
                    Nom = "Action"
                });
                context.Genres.Add(new Genre {
                    Nom = "Policer"
                });
                context.Genres.Add(new Genre {
                    Nom = "Animation"
                });
                context.Genres.Add(new Genre {
                    Nom = "Romantique"
                });
                context.SaveChanges();
                return(GetGenres());
            }
            return(genres);
        }
        public async Task RemoveMediaGenre(List <MediaGenre> mediaGenre)
        {
            var context = await VideothequeDbContext.GetCurrent();

            context.RemoveRange(mediaGenre);
            await context.SaveChangesAsync();
        }
        public async Task Preter(MediaPersonne mp)
        {
            var context = await VideothequeDbContext.GetCurrent();

            context.Add(mp);
            await context.SaveChangesAsync();
        }
        public async Task Rendre(MediaPersonne mp)
        {
            var context = await VideothequeDbContext.GetCurrent();

            context.Remove(mp);
            await context.SaveChangesAsync();
        }
        public async Task RemoveAmi(Personne ami)
        {
            var context = await VideothequeDbContext.GetCurrent();

            context.Remove(ami);
            await context.SaveChangesAsync();
        }
예제 #6
0
        public async Task UpdateFilm(Film film)
        {
            var context = await VideothequeDbContext.GetCurrent();

            context.Update(film);
            await context.SaveChangesAsync();
        }
        public async Task <List <Personne> > GetAmis()
        {
            var context = await VideothequeDbContext.GetCurrent();

            var amis = context.Personnes;

            return(amis.ToList());
        }
        public List <MediaParGenre> GetMediaParGenre()
        {
            var context = VideothequeDbContext.GetCurrent().Result;
            List <MediaParGenre> mpd = context.MediasParGenre
                                       .FromSql("select g.Nom NomGenre, count(m.Id) NombreMedia from Genres g " +
                                                "inner join MediaGenre mg on g.Id = mg.IdGenre " +
                                                "inner join Media m on mg.IdMedia = m.Id " +
                                                "group by g.Nom").ToList();

            return(mpd);
        }
예제 #9
0
        public async Task <List <Film> > GetFilm()
        {
            var context = await VideothequeDbContext.GetCurrent();

            List <Film> films = new List <Film>();
            await Task.Run(() => {
                films = context.Films.ToList();
                foreach (Film f in films)
                {
                    f.MediaGenres = context.MediaGenre.Where(x => x.IdMedia == f.Id).ToList();
                    f.Genre       = context.Genres.First(x => x.Id == f.MediaGenres.First().IdGenre);
                }
            });

            return(films);
        }
예제 #10
0
        public async Task <List <Film> > GetDispo()
        {
            var context = await VideothequeDbContext.GetCurrent();

            List <Film> films = new List <Film>();
            await Task.Run(() => {
                films = context.Films.FromSql(@"select m.Id, m.Titre, m.Statut, m.DateCreation, m.Note, m.Commentaire, m.Synopsis, m.AgeMinimum, 
                                                m.LangueVO, m.LangueMedia, m.SousTitre, m.AudioDescription, m.SupportPhysique, m.SupportNumerique, m.Duree
                                                , m.Discriminator, m.Photo
                                                from Media m 
                                                left join MediaPersonne mp on m.Id = mp.IdMedia 
                                                where m.SupportPhysique = 1 and mp.IdPersonne is null").ToList();
                foreach (Film f in films)
                {
                    f.MediaGenres = context.MediaGenre.Where(x => x.IdMedia == f.Id).ToList();
                    f.Genre       = context.Genres.First(x => x.Id == f.MediaGenres.First().IdGenre);
                }
            });

            return(films);
        }