예제 #1
0
 public DataProvider(Dictionary<string, string> cons) {
     //Create movie context
     dbConnString = cons["SqlConnString"];
     db = new MoviesContext(dbConnString);
     Movies = db.Movies;
     
 }
예제 #2
0
        //SEARCH MOVIES BASE ON COMBO CONDITION OF TITLE, YEAR, & TYPE
        public List<Movie> Search(SubmitData message){
            //get input values from client
            string title = (message.Title == null) ? "" : message.Title.Trim();
            string year = (message.Year == null) ? "" : message.Year.Trim();
            string type = (message.Type == null) ? "" : message.Type.Trim();

            List<Movie> retResult = new List<Movie>();
            //get movie type
            var sType = GetMovieType(type);

            //LINQ query to get result
            using (var context = new MoviesContext()){
                //all matched movies --> query
                var query =
                    from movie in context.Movies
                    where (title == "" | movie.Title.Contains(title)) &&
                          (year == "" | movie.Year == year) &&
                          (type == "" | movie.Type == sType)
                    select movie;

                //add movies to the return list
                foreach (var m in query){
                    retResult.Add(m);
                }
            }


            return retResult;

        }