Exemple #1
0
 public static IList<Person> GetAllWriters()
 {
     using (MovieCollectionEntities entity = new MovieCollectionEntities())
     {
         return
             entity.PersonFilmIndexes.Where(pfi => pfi.RoleID == FilmRole.WriterRole.RoleID).Select(
                 pfi => pfi.Person).Distinct().ToList();
     }
 }
        public static IList<Film> RunSearch(
        string paramActorLast = null,
        string paramActorFirst = null,
        string paramWriterLast = null,
        string paramWriterFirst = null,
        string paramDirectorLast = null,
        string paramDirectorFirst = null,
        List<string> paramGenres = null,
        List<string> paramRatings = null,
        int paramMax = 0,
        int paramMin = 0)
        {
            using (MovieCollectionEntities context = new MovieCollectionEntities())
            {
                IQueryable<Film> mq = context.Films.Include("Rating")
                                                    .Include("GenreFilmIndexes.Genre")
                                                    .Include("PersonFilmIndexes.Person")
                                                    .Select(o => o);
                if (paramRatings != null && paramRatings.Count > 0) mq = mq.Where(o => paramRatings.Contains(o.Rating.MPAARating));
                if (paramMin > 0) mq = mq.Where(o => o.Length >= paramMin);
                if (paramMax > 0) mq = mq.Where(o => o.Length <= paramMax);
                if (paramGenres != null && paramGenres.Count > 0)
                    mq = mq.Where(o => paramGenres.Any(gn => (o.GenreFilmIndexes
                    .Select(gfi => gfi.Genre.Name)).Contains(gn)));

                mq = mq.SearchByPersonNameAndRole(paramActorFirst, FilmRole.ActorRole.RoleID, true);
                mq = mq.SearchByPersonNameAndRole(paramActorLast, FilmRole.ActorRole.RoleID);

                mq = mq.SearchByPersonNameAndRole(paramWriterFirst, FilmRole.ActorRole.RoleID, true);
                mq = mq.SearchByPersonNameAndRole(paramWriterLast, FilmRole.ActorRole.RoleID);

                mq = mq.SearchByPersonNameAndRole(paramDirectorFirst, FilmRole.DirectorRole.RoleID, true);
                mq = mq.SearchByPersonNameAndRole(paramDirectorLast, FilmRole.DirectorRole.RoleID);

                return mq.Distinct().ToList();

            }
        }
 public static void SaveAndRefreshDBConnection()
 {
     Context.SaveChanges();
     Context = new MovieCollectionEntities();
 }
 public static void InitializeDBConnection()
 {
     if (Context == null)
     {
         Context = new MovieCollectionEntities();
     }
 }