// GET: MoviesReportAjax
        public ActionResult Index()
        {
            IQueryable <MovieReportLeftOuterJoinModel> leftOuterJoinQuery;
            List <MovieReportLeftOuterJoinModel>       leftOuterJoinList = null;

            leftOuterJoinQuery = movieReportService.GetLeftOuterJoinquery();

            leftOuterJoinList = leftOuterJoinQuery.ToList();

            List <SelectListItem> selects = new List <SelectListItem>();

            for (int year = DateTime.Now.Year + 1; year >= 1930; year--)
            {
                selects.Add(new SelectListItem()
                {
                    Value = year.ToString(),
                    Text  = year.ToString()
                });
            }

            MoviesReportAjaxIndexViewModel viewModel = new MoviesReportAjaxIndexViewModel()
            {
                LeftOuterJoinList             = leftOuterJoinList,
                ProductionYearMultiSelectList = new MultiSelectList(selects, "Value", "Text")
            };

            return(View(viewModel));
        }
예제 #2
0
        // GET: MoviesReport
        //public ActionResult Index(int? OnlyMatchedValue = null)
        public ActionResult Index(MoviesReportIndexViewModel moviesReport)
        {
            IQueryable <MovieReportsInnerJoinModel>    innerJoinQuery;
            IQueryable <MovieReportLeftOuterJoinModel> leftOuterJoinQuery;
            List <MovieReportsInnerJoinModel>          innerJoinList     = null;
            List <MovieReportLeftOuterJoinModel>       leftOuterJoinList = null;

            if (moviesReport.OnlyMatchedValue == 1)
            {
                innerJoinQuery = movieReportService.GetInnerJoinQuery();
                if (!string.IsNullOrWhiteSpace(moviesReport.MovieName))
                {
                    innerJoinQuery = innerJoinQuery.Where(model => model.MovieName.ToUpper().Contains(moviesReport.MovieName.ToUpper().Trim()));
                }
                if (moviesReport.ProductionYears != null && moviesReport.ProductionYears.Count > 0)
                {
                    innerJoinQuery = innerJoinQuery.Where(model => moviesReport.ProductionYears.Contains(model.MovieProductionYear));
                }
                double boxOfficeReturn1;
                double boxOfficeReturn2;
                if (!string.IsNullOrWhiteSpace(moviesReport.BoxOfficeReturn1))
                {
                    if (double.TryParse(moviesReport.BoxOfficeReturn1.Trim().Replace(",", "."), NumberStyles.Any, new CultureInfo("en"), out boxOfficeReturn1))
                    {
                        innerJoinQuery = innerJoinQuery.Where(model => model.MovieBoxOfficeReturnValue >= boxOfficeReturn1);
                    }
                }
                if (!string.IsNullOrWhiteSpace(moviesReport.BoxOfficeReturn2))
                {
                    if (double.TryParse(moviesReport.BoxOfficeReturn2.Trim().Replace(",", "."), NumberStyles.Any, new CultureInfo("en"), out boxOfficeReturn2))
                    {
                        innerJoinQuery = innerJoinQuery.Where(model => model.MovieBoxOfficeReturnValue <= boxOfficeReturn2);
                    }
                }
                DateTime reviewDate1;
                DateTime reviewDate2;

                if (!string.IsNullOrWhiteSpace(moviesReport.ReviewDate1))
                {
                    reviewDate1    = DateTime.Parse(moviesReport.ReviewDate1, new CultureInfo("en"));
                    innerJoinQuery = innerJoinQuery.Where(model => model.ReviewDateValue >= reviewDate1);
                }
                if (!string.IsNullOrWhiteSpace(moviesReport.ReviewDate2))
                {
                    reviewDate2    = DateTime.Parse(moviesReport.ReviewDate2, new CultureInfo("en"));
                    innerJoinQuery = innerJoinQuery.Where(model => model.ReviewDateValue <= reviewDate2);
                }

                innerJoinList = innerJoinQuery.ToList();
            }
            else
            {
                leftOuterJoinQuery = movieReportService.GetLeftOuterJoinquery();
                if (!string.IsNullOrWhiteSpace(moviesReport.MovieName))
                {
                    leftOuterJoinQuery = leftOuterJoinQuery.Where(model => model.MovieName.ToUpper().Contains(moviesReport.MovieName.ToUpper().Trim()));
                }
                if (moviesReport.ProductionYears != null && moviesReport.ProductionYears.Count > 0)
                {
                    leftOuterJoinQuery = leftOuterJoinQuery.Where(model => moviesReport.ProductionYears.Contains(model.MovieProductionYear));
                }
                double boxOfficeReturn1;
                double boxOfficeReturn2;
                if (!string.IsNullOrWhiteSpace(moviesReport.BoxOfficeReturn1))
                {
                    if (double.TryParse(moviesReport.BoxOfficeReturn1.Trim().Replace(",", "."), NumberStyles.Any, new CultureInfo("en"), out boxOfficeReturn1))
                    {
                        leftOuterJoinQuery = leftOuterJoinQuery.Where(model => model.MovieBoxOfficeReturnValue >= boxOfficeReturn1);
                    }
                }
                if (!string.IsNullOrWhiteSpace(moviesReport.BoxOfficeReturn2))
                {
                    if (double.TryParse(moviesReport.BoxOfficeReturn2.Trim().Replace(",", "."), NumberStyles.Any, new CultureInfo("en"), out boxOfficeReturn2))
                    {
                        leftOuterJoinQuery = leftOuterJoinQuery.Where(model => model.MovieBoxOfficeReturnValue <= boxOfficeReturn2);
                    }
                }
                DateTime reviewDate1;
                DateTime reviewDate2;
                if (!string.IsNullOrWhiteSpace(moviesReport.ReviewDate1))
                {
                    reviewDate1        = DateTime.Parse(moviesReport.ReviewDate1, new CultureInfo("en"));
                    leftOuterJoinQuery = leftOuterJoinQuery.Where(model => model.ReviewDateValue >= reviewDate1);
                }
                if (!string.IsNullOrWhiteSpace(moviesReport.ReviewDate2))
                {
                    reviewDate2        = DateTime.Parse(moviesReport.ReviewDate2, new CultureInfo("en"));
                    leftOuterJoinQuery = leftOuterJoinQuery.Where(model => model.ReviewDateValue <= reviewDate2);
                }

                leftOuterJoinList = leftOuterJoinQuery.ToList();
            }



            List <SelectListItem> onlyMatchedSelectListItems = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Value = "1",
                    Text  = "Yes"
                },
                new SelectListItem()
                {
                    Value = "0",
                    Text  = "No"
                }
            };

            List <SelectListItem> productionYearSelectListItems = new List <SelectListItem>();

            for (int year = DateTime.Now.Year + 1; year >= 1930; year--)
            {
                productionYearSelectListItems.Add(new SelectListItem()
                {
                    Value = year.ToString(), Text = year.ToString()
                });
            }

            moviesReport.InnerJoinList                 = innerJoinList;
            moviesReport.LeftOuterJoinList             = leftOuterJoinList;
            moviesReport.OnlyMatchedSelectList         = new SelectList(onlyMatchedSelectListItems, "Value", "Text");
            moviesReport.ProductionYearMultiSelectList = new MultiSelectList(productionYearSelectListItems, "Value", "Text");

            if (Session["MoviesReport"] != null)
            {
                Session.Remove("MoviesReport");
            }
            Session["MoviesReport"] = moviesReport;

            return(View(moviesReport));
        }