Ejemplo n.º 1
0
        public async Task<ActionResult> Search(SubmitData message) {
            Trace.TraceInformation(TraceInfo.ShortTime + "WER >>> Start searching movie");
            if (message.Title == "" & message.Type == null & message.Year == "") {
                //return full list if there is no input
                var result = await dataProvider.ToListAsync();
                Trace.TraceInformation(TraceInfo.ShortTime + "WER >>> Search ended");

                return View();
                
            } else {
                var ret = dataProvider.Search(message);
                
                //Setup model state status
                if (ret.Count == 0){
                  ModelState.AddModelError("NotFound", "Movie not found");
                }
                Trace.TraceInformation(TraceInfo.ShortTime + "WER >>> Search ended");
                return View(ret);
            }
        }
Ejemplo n.º 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;

        }