Beispiel #1
0
        // GET: Information
        public ActionResult Index()
        {
            var information = db.Information.ToList();
            List <InformationView> model = new List <InformationView>();

            foreach (var item in information)
            {
                InformationView driver = new InformationView();
                driver.MapDataToViewModel(item);
                model.Add(driver);
            }
            return(View(model.OrderBy(s => s.FillUpDate)));
        }
        public ActionResult Index(string searchName, string searchModel, DateTime?startDate, DateTime?endDate)
        {
            var information = from m in db.Information.ToList() select m;
            List <InformationView> model = new List <InformationView>();


            foreach (var item in information)
            {
                InformationView driver = new InformationView();
                driver.MapDataToViewModel(item);
                model.Add(driver);
            }

            var fueler = from f in model select f;

            if (startDate != null)
            {
                fueler = fueler.Where(s => s.FillUpDate >= startDate);
            }
            if (endDate != null)
            {
                fueler = fueler.Where(s => s.FillUpDate <= endDate);
            }
            if (!string.IsNullOrEmpty(searchModel))
            {
                fueler = fueler.Where(s => s.CarModel.ToLower().Contains(searchModel.ToLower()));
            }
            if (!string.IsNullOrEmpty(searchName))
            {
                fueler = fueler.Where(s => s.LName.ToLower().Contains(searchName.ToLower()) || s.FName.ToLower().Contains(searchName.ToLower()));
            }
            try
            {
                ViewBag.AverageMPG = Math.Round(fueler.Average(s => s.MilesPerGallon), 2);
            }
            catch (Exception)
            {
                ViewBag.AverageMPG = 0;
            }
            return(View(fueler.OrderByDescending(s => s.FillUpDate).ThenBy(s => s.LName).ThenBy(s => s.CarModel)));
        }
        // GET: Information2
        public ActionResult Index()
        {
            var information = from m in db.Information.ToList() select m;
            List <InformationView> model = new List <InformationView>();


            foreach (var item in information)
            {
                InformationView driver = new InformationView();
                driver.MapDataToViewModel(item);
                model.Add(driver);
            }
            try
            {
                ViewBag.AverageMPG = Math.Round(model.Average(s => s.MilesPerGallon), 2);
            }
            catch (Exception)
            {
                ViewBag.AverageMPG = 0;
            }
            return(View(model.OrderByDescending(s => s.FillUpDate).ThenBy(s => s.LName).ThenBy(s => s.CarModel)));
        }