public ActionResult List(int?Skupina, DateTime?DateFrom, DateTime?DateTo, int?Zakaznik, int?Status, bool send) { Session["List_Skupina"] = Skupina; Session["List_DateFrom"] = DateFrom.ToString(); Session["List_DateTo"] = DateTo.ToString(); Session["List_Status"] = Status; //string abc = Session["Test"].ToString(); RevizeListInput rl = new RevizeListInput(); //Create a list of select list items - this will be returned as your select list List <SelectListItem> newList = new List <SelectListItem> { new SelectListItem() { Value = "0", Text = "Vše" }, new SelectListItem() { Value = "1", Text = "Česká Republika" }, new SelectListItem() { Value = "2", Text = "Polsko" }, new SelectListItem() { Value = "3", Text = "Slovensko a Maďarsko" }, new SelectListItem() { Value = "4", Text = "Ostatní" } }; //Add select list item to list of selectlistitems rl.DateFrom = DateFrom; rl.DateTo = DateTo; //Return the list of selectlistitems as a selectlist ViewBag.Skupina = new SelectList(newList, "Value", "Text", Skupina); ViewBag.Zakaznik = new SelectList(db.Zakaznik.ToList(), "Id", "NazevZakaznika", Zakaznik); ViewBag.Status = new SelectList(db.StatusRevize.ToList(), "Id", "NazevStatusuRevize", Status); var x = db.Revize .Include(r => r.Provoz) .Include(r => r.RevizeSC) .Include(r => r.StatusRevize) .Include(r => r.Umisteni); if (DateFrom != null) { x = x.Where(r => r.DatumRevize >= DateFrom); } if (DateTo != null) { x = x.Where(r => r.DatumRevize <= DateTo); } if (Zakaznik != null) { x = x.Where(r => r.Provoz.ZakaznikId == Zakaznik); } if (Status != null) { x = x.Where(r => r.StatusRevizeId == Status); } if (Skupina != null && Skupina != 0) { x = x.Where(r => r.Provoz.Zakaznik.Region.Skupina == Skupina); } // var listrevizi = x.ToList(); listrevizi = Revize.LoopRevizeAndUpdateBatery(listrevizi); rl.Revize = listrevizi; ViewBag.ListDateFrom = DateFrom; ViewBag.ListDateTo = DateTo; ViewBag.ListStatus = db.StatusRevize.Where(r => r.Id == Status).Select(r => r.NazevStatusuRevize).FirstOrDefault(); if (Skupina == 0) { ViewBag.ListRegion = "Vše"; } if (Skupina == 1) { ViewBag.ListRegion = "Česká Republika"; } if (Skupina == 2) { ViewBag.ListRegion = "Polsko"; } if (Skupina == 3) { ViewBag.ListRegion = "Slovensko a Maďarsko"; } if (Skupina == 4) { ViewBag.ListRegion = "Ostatní"; } return(View(rl)); }
public ActionResult List(int?Skupina, DateTime?DateFrom, DateTime?DateTo, int?Zakaznik, int?Status) { string ListRegion = null; DateTime?ListDateFrom = null; DateTime?ListDateTo = null; string ListStatus = null; try { ListRegion = Session["List_Skupina"].ToString(); } catch (Exception ex) { log.Debug("List - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); } try { var xListDateFrom = Session["List_DateFrom"].ToString(); DateTime xx = Convert.ToDateTime(xListDateFrom); ListDateFrom = xx; } catch (Exception ex) { log.Debug("List - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); } try { var ListDateTox = Session["List_DateTo"].ToString(); DateTime xx = Convert.ToDateTime(ListDateTox); ListDateTo = xx; } catch (Exception ex) { log.Debug("List - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); } try { ListStatus = Session["List_Status"].ToString(); } catch (Exception ex) { log.Debug("List - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); } RevizeListInput rl = new RevizeListInput(); //Create a list of select list items - this will be returned as your select list List <SelectListItem> newList = new List <SelectListItem> { new SelectListItem() { Value = "0", Text = "Vše" }, new SelectListItem() { Value = "1", Text = "Česká Republika" }, new SelectListItem() { Value = "2", Text = "Polsko" }, new SelectListItem() { Value = "3", Text = "Slovensko a Maďarsko" }, new SelectListItem() { Value = "4", Text = "Ostatní" } }; //Return the list of selectlistitems as a selectlist if (ListRegion != null) { ViewBag.Skupina = new SelectList(newList, "Value", "Text", ListRegion); } else { ViewBag.Skupina = new SelectList(newList, "Value", "Text", null); } if (ListStatus != null) { ViewBag.Status = new SelectList(db.StatusRevize.ToList(), "Id", "NazevStatusuRevize", ListStatus); } else { ViewBag.Status = new SelectList(db.StatusRevize.ToList(), "Id", "NazevStatusuRevize", null); } var x = db.Revize .Include(r => r.Provoz) .Include(r => r.RevizeSC) .Include(r => r.StatusRevize) .Include(r => r.Umisteni); //.Include(r => r.); if (DateFrom != null) { x = x.Where(r => r.DatumRevize >= DateFrom); } else { if (ListDateFrom != null) { x = x.Where(r => r.DatumRevize >= ListDateFrom); } } if (DateTo != null) { x = x.Where(r => r.DatumRevize <= DateTo); } else { if (ListDateTo != null) { x = x.Where(r => r.DatumRevize >= ListDateTo); } } if (Zakaznik != null) { x = x.Where(r => r.Provoz.ZakaznikId == Zakaznik); } if (Status != null) { x = x.Where(r => r.StatusRevizeId == Status); } if (Skupina != null && Skupina != 0) { x = x.Where(r => r.Provoz.Zakaznik.Region.Skupina == Skupina); } var listrevizi = x.ToList(); listrevizi = Revize.LoopRevizeAndUpdateBatery(listrevizi); rl.Revize = listrevizi; if (DateFrom != null) { ViewBag.ListDateFrom = DateFrom; rl.DateFrom = DateFrom; } else { if (ListDateFrom != null) { ViewBag.ListDateFrom = ListDateFrom; rl.DateFrom = ListDateFrom; } } if (DateTo != null) { ViewBag.ListDateTo = DateTo; rl.DateTo = DateTo; } else { if (ListDateTo != null) { ViewBag.ListDateTo = ListDateTo; rl.DateTo = ListDateTo; } } ViewBag.ListStatus = db.StatusRevize.Where(r => r.Id == Status).Select(r => r.NazevStatusuRevize).FirstOrDefault(); if (ListRegion == "0") { ViewBag.Region = "Vše"; } if (ListRegion == "1") { ViewBag.Region = "Česká Republika"; } if (ListRegion == "2") { ViewBag.Region = "Polsko"; } if (ListRegion == "3") { ViewBag.Region = "Slovensko a Maďarsko"; } if (ListRegion == "4") { ViewBag.Region = "Ostatní"; } return(View(rl)); }