public List <Film> GetAll() { using (var db = new FilmEntities()) { return(db.Film.ToList()); } }
public static Film FilmEntitiesToFilmModele(FilmEntities film) { List <Personne> tmp = new List <Personne>(); foreach (PersonneEntities p in film.Acteurs) { Personne p1 = new Personne(p.Nom, p.Prenom); p1.DateNaissance = new Date(p.DateNaissance.Annee, p.DateNaissance.Mois, p.DateNaissance.Jour); p1.Photo = p.Photo; tmp.Add(p1); } return(new Film { Titre = film.Titre, TitreFrancais = film.TitreFrancais, Pays = film.Pays, Budget = film.Budget, Source = film.Source, Note = film.Note, Realisateur = new Personne(film.Realisateur.Nom, film.Realisateur.Prenom), Duree = film.Duree, DateSortie = film.DateSortie, Synopsis = film.Synopsis, Acteurs = new ObservableCollection <Personne>(tmp) }); }
public Point Get(int userId, int filmId) { using (var db = new FilmEntities()) { var p = db.Point.Where(x => x.UserId == userId && x.FilmId == filmId).SingleOrDefault(); return(p); } }
public List <Film> GetFilms(int pageNumber, int pageLenth) { using (var db = new FilmEntities()) { var p = db.Film.OrderByDescending(x => x.popularity).Skip(pageNumber * pageLenth).Take(pageLenth).ToList(); return(p); } }
public void AddRange(List <Film> list) { using (var db = new FilmEntities()) { db.Film.AddRange(list); db.SaveChanges(); } }
public async Task <User> ValidateUser(string userName, string password) { using (var db = new FilmEntities()) { var k = await db.User.Where(x => x.username == userName && x.password == password).SingleOrDefaultAsync(); return(k); } }
public void Update(int userId, int filmId, int point) { using (var db = new FilmEntities()) { var p = db.Point.Where(x => x.UserId == userId && x.FilmId == filmId).SingleOrDefault(); p.point1 = point; db.SaveChanges(); } }
public void Add(int userId, int filmId, string note) { using (var db = new FilmEntities()) { db.Comment.Add(new Comment() { FilmId = filmId, UserId = userId, note = note }); db.SaveChanges(); } }
public User GetById(int userId) { using (var db = new FilmEntities()) { var k = db.User.Include(x => x.Comment). Include(x => x.Point). Where(x => x.Id == userId).Single(); return(k); } }
public Film GetById(int filmId) { using (var db = new FilmEntities()) { var p = db.Film.Where(x => x.Id == filmId).SingleOrDefault(); if (p == null) { throw new Exception("Film Id is not valid"); } return(p); } }
public void Add(int userId, int filmId, int point) { try { using (var db = new FilmEntities()) { db.Point.Add(new Point() { FilmId = filmId, UserId = userId, point1 = point }); db.SaveChanges(); } } catch (Exception) { throw new Exception("Film Id is not valid"); } }
public void Update(List <Film> list) { using (var db = new FilmEntities()) { var t = list.Select(x => x.Id).ToList(); var p = db.Film.Where(x => t.Contains(x.Id)).ToList(); foreach (var f in p) { var h = list.Where(x => x.Id == f.Id).Single(); f.popularity = h.popularity; f.vote_average = h.vote_average; f.vote_count = h.vote_count; } db.SaveChanges(); } }
public static List <FilmEntities> lectureFichier(List <FilmEntities> listFilm) { StreamReader streamReader = new StreamReader(@System.IO.Directory.GetParent(@Application.ResourceAssembly.Location).ToString() + "/films.txt"); string ligne = streamReader.ReadLine(); int nbfilm; List <PersonneEntities> acteurs = new List <PersonneEntities>(); if (ligne == null) { nbfilm = 0; } else { nbfilm = int.Parse(ligne); } for (int i = 0; i < nbfilm; i++) { string s_nbacteurs = streamReader.ReadLine(); int nbacteurs = 0; int.TryParse(s_nbacteurs, out nbacteurs); string titre = streamReader.ReadLine(); string titreFrancais = streamReader.ReadLine(); string pays = streamReader.ReadLine(); int budget; int.TryParse(streamReader.ReadLine(), out budget); PersonneEntities realisateur = new PersonneEntities(streamReader.ReadLine(), streamReader.ReadLine()); int duree; int.TryParse(streamReader.ReadLine(), out duree); int annee; int.TryParse(streamReader.ReadLine(), out annee); int mois; int.TryParse(streamReader.ReadLine(), out mois); int jour; int.TryParse(streamReader.ReadLine(), out jour); Uri source = new Uri(@System.IO.Directory.GetParent(@Application.ResourceAssembly.Location).ToString() + streamReader.ReadLine()); int note; int.TryParse(streamReader.ReadLine(), out note); string synopsis = streamReader.ReadLine(); for (int j = 0; j < nbacteurs; j++) { PersonneEntities p = new PersonneEntities(streamReader.ReadLine(), streamReader.ReadLine()); int anneeP; int.TryParse(streamReader.ReadLine(), out anneeP); int moisP; int.TryParse(streamReader.ReadLine(), out moisP); int jourP; int.TryParse(streamReader.ReadLine(), out jourP); p.DateNaissance = new Date(anneeP, moisP, jourP); p.Photo = new Uri(@System.IO.Directory.GetParent(@Application.ResourceAssembly.Location).ToString() + streamReader.ReadLine()); acteurs.Add(p); } FilmEntities film = new FilmEntities() { Titre = titre, TitreFrancais = titreFrancais, Pays = pays, Budget = budget, Duree = duree, Realisateur = realisateur, DateSortie = new Date(annee, mois, jour), Source = source, Note = note, Synopsis = synopsis, Acteurs = acteurs }; listFilm.Add(film); acteurs = new List <PersonneEntities>(); } streamReader.Close(); return(listFilm); }