/// <summary> /// Flight Search Action of Home Controller /// Call by ajax request from Index page /// Return a Partial view with flights available for one way /// </summary> /// <param name="fromcity"></param> /// <param name="tocity"></param> /// <param name="fromDate"></param> /// <param name="noofPeople"></param> /// <param name="travelClass"></param> /// <returns></returns> public ActionResult FlightSearch(int fromcity, int tocity, string fromDate, int noofPeople, string travelClass) { Session["frmcity"] = fromcity; Session["tocity"] = tocity; Session["fromdate"] = fromDate; Session["noofpeople"] = noofPeople; Session["travelClass"] = travelClass; List <Schedule> schedules = scheduleMgr.GetSchedule().ToList <Schedule>(); List <Schedule> sch = new List <Schedule>(); if (fromcity != null && tocity != null && fromDate != null && noofPeople != null && travelClass != null) { foreach (var s in schedules) { s.Route.FromCity = scheduleMgr.FindCity(s.Route.FromCityId); s.Route.ToCity = scheduleMgr.FindCity(s.Route.ToCityId); } //Get Direct Schedules Route route = scheduleMgr.GetAllRoute().FirstOrDefault(p => p.FromCityId == fromcity && p.ToCityId == tocity); sch = scheduleMgr.GetSchedule().Where(p => p.RouteId == route.RouteID).ToList <Schedule>(); //Get Connected Schedules List <Route> ConnectedToRoute = (scheduleMgr.GetAllRoute().Where(p => p.ToCityId == tocity)).ToList <Route>(); List <Route> ConnectedFromRoute = (scheduleMgr.GetAllRoute().Where(p => p.FromCityId == fromcity)).ToList <Route>(); List <Schedule> connectedSch = new List <Schedule>(); List <Schedule> connectedToSch = new List <Schedule>(); foreach (var item in ConnectedToRoute) { foreach (var a in ConnectedFromRoute) { if (item.FromCityId == a.ToCityId) { connectedSch.AddRange(scheduleMgr.GetSchedule().Where(p => p.RouteId == a.RouteID).ToList <Schedule>()); connectedToSch.AddRange(scheduleMgr.GetSchedule().Where(p => p.RouteId == item.RouteID).ToList <Schedule>()); } } } ViewBag.ConnectedSchedule = connectedSch; ViewBag.ConnectedToSch = connectedToSch; //return PartialView("SearchPartial", sch); } return(PartialView("SearchPartial", sch)); }