// GET: FordonModels
        public ActionResult Index(string searchString, string sortOrder, string currentFilter, int? page, string typeFilter, string idag)
        {
            // SIDOHANTERING
            ViewBag.CurrentSort = sortOrder;

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewBag.CurrentFilter = searchString;

            var bilar = from s in db.Fordon
                        select s;

            // SÖK
            if (!String.IsNullOrEmpty(searchString) || !String.IsNullOrEmpty(typeFilter))
            {
                if (typeFilter != "Alla" && !String.IsNullOrEmpty(searchString))
                {
                    bilar = bilar.Where(s =>
                        s.Regnr == searchString
                        || s.Ägare == searchString
                        && s.Fordontyp.ToString() == typeFilter);
                }
                else if (String.IsNullOrEmpty(typeFilter) || typeFilter == "Alla")
                {
                    bilar = bilar.Where(s =>
                    s.Regnr == searchString
                    || s.Ägare == searchString);
                }
                else
                    bilar = bilar.Where(s => s.Fordontyp.ToString() == typeFilter);
            }

            if (idag == "true")
            {
                DateTime today = DateTime.Now;
                bilar = bilar.Where(s => s.Parkerad.Year == today.Year && s.Parkerad.Month == today.Month && s.Parkerad.Day == today.Day);
            }

            // SORTERING
            ViewBag.FärgSortParm = String.IsNullOrEmpty(sortOrder) ? "färg_desc" : "";
            ViewBag.MärkeSortParm = String.IsNullOrEmpty(sortOrder) ? "märke_desc" : "";
            ViewBag.ModellSortParm = String.IsNullOrEmpty(sortOrder) ? "modell_desc" : "";
            ViewBag.ÄgareSortParm = String.IsNullOrEmpty(sortOrder) ? "ägare_desc" : "";
            ViewBag.TypSortParm = String.IsNullOrEmpty(sortOrder) ? "typ_desc" : "";
            ViewBag.RegnrSortParm = String.IsNullOrEmpty(sortOrder) ? "regnr_desc" : "";
            ViewBag.DateSortParm = sortOrder == "Parkerad" ? "park_desc" : "Parkerad";

            // sorterar de klickbara tabellrubrikerna från störst till minst
            switch (sortOrder)
            {
                case "märke_desc":
                    bilar = bilar.OrderByDescending(s => s.Märke);
                    break;
                case "regnr_desc":
                    bilar = bilar.OrderByDescending(s => s.Regnr);
                    break;
                case "modell_desc":
                    bilar = bilar.OrderByDescending(s => s.Modell);
                    break;
                case "ägare_desc":
                    bilar = bilar.OrderByDescending(s => s.Ägare);
                    break;
                case "typ_desc":
                    bilar = bilar.OrderByDescending(s => s.Fordontyp);
                    break;
                case "färg_desc":
                    bilar = bilar.OrderByDescending(s => s.Färg);
                    break;
                case "Parkerad":
                    bilar = bilar.OrderBy(s => s.Parkerad);
                    break;
                case "park_desc":
                    bilar = bilar.OrderByDescending(s => s.Parkerad);
                    break;
                default:
                    bilar = bilar.OrderBy(s => s.Fordontyp).ThenBy(s => s.Parkerad);
                    break;

            }

            int pageSize = 5;

            int pageNumber = (page ?? 1);

            var model = new Garage.Models.FordonModelPagedList();

            model.list = bilar.ToPagedList(pageNumber, pageSize);

            return View(model);
        }
        // GET: FordonModels
        public ActionResult Index(string searchString, string sortOrder, string currentFilter, int?page, string typeFilter, string idag)
        {
            // SIDOHANTERING
            ViewBag.CurrentSort = sortOrder;

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewBag.CurrentFilter = searchString;


            var bilar = from s in db.Fordon
                        select s;

            // SÖK
            if (!String.IsNullOrEmpty(searchString) || !String.IsNullOrEmpty(typeFilter))
            {
                if (typeFilter != "Alla" && !String.IsNullOrEmpty(searchString))
                {
                    bilar = bilar.Where(s =>
                                        s.Regnr == searchString ||
                                        s.Ägare == searchString &&
                                        s.Fordontyp.ToString() == typeFilter);
                }
                else if (String.IsNullOrEmpty(typeFilter) || typeFilter == "Alla")
                {
                    bilar = bilar.Where(s =>
                                        s.Regnr == searchString ||
                                        s.Ägare == searchString);
                }
                else
                {
                    bilar = bilar.Where(s => s.Fordontyp.ToString() == typeFilter);
                }
            }



            if (idag == "true")
            {
                DateTime today = DateTime.Now;
                bilar = bilar.Where(s => s.Parkerad.Year == today.Year && s.Parkerad.Month == today.Month && s.Parkerad.Day == today.Day);
            }

            // SORTERING
            ViewBag.FärgSortParm   = String.IsNullOrEmpty(sortOrder) ? "färg_desc" : "";
            ViewBag.MärkeSortParm  = String.IsNullOrEmpty(sortOrder) ? "märke_desc" : "";
            ViewBag.ModellSortParm = String.IsNullOrEmpty(sortOrder) ? "modell_desc" : "";
            ViewBag.ÄgareSortParm  = String.IsNullOrEmpty(sortOrder) ? "ägare_desc" : "";
            ViewBag.TypSortParm    = String.IsNullOrEmpty(sortOrder) ? "typ_desc" : "";
            ViewBag.RegnrSortParm  = String.IsNullOrEmpty(sortOrder) ? "regnr_desc" : "";
            ViewBag.DateSortParm   = sortOrder == "Parkerad" ? "park_desc" : "Parkerad";


            // sorterar de klickbara tabellrubrikerna från störst till minst
            switch (sortOrder)
            {
            case "märke_desc":
                bilar = bilar.OrderByDescending(s => s.Märke);
                break;

            case "regnr_desc":
                bilar = bilar.OrderByDescending(s => s.Regnr);
                break;

            case "modell_desc":
                bilar = bilar.OrderByDescending(s => s.Modell);
                break;

            case "ägare_desc":
                bilar = bilar.OrderByDescending(s => s.Ägare);
                break;

            case "typ_desc":
                bilar = bilar.OrderByDescending(s => s.Fordontyp);
                break;

            case "färg_desc":
                bilar = bilar.OrderByDescending(s => s.Färg);
                break;

            case "Parkerad":
                bilar = bilar.OrderBy(s => s.Parkerad);
                break;

            case "park_desc":
                bilar = bilar.OrderByDescending(s => s.Parkerad);
                break;

            default:
                bilar = bilar.OrderBy(s => s.Fordontyp).ThenBy(s => s.Parkerad);
                break;
            }



            int pageSize = 5;

            int pageNumber = (page ?? 1);

            var model = new Garage.Models.FordonModelPagedList();

            model.list = bilar.ToPagedList(pageNumber, pageSize);


            return(View(model));
        }