コード例 #1
0
        // [HttpPost]
        public ActionResult SearchResult(SearchBus searchBus)
        {
            ViewBag.BusOperatorList = new SelectList(context.BusOperators, "Id", "Name");
            ViewBag.LocationList    = new SelectList(context.Locations, "Id", "Location");

            //ViewBag.LocationList = context.Locations.ToList();
            var routeList = rps.GetRoute(searchBus.From, searchBus.To);
            var from      = ls.GetById(searchBus.From);
            var to        = ls.GetById(searchBus.To);

            foreach (var item in routeList)
            {
                if (tbs.GetTripByRouteId(item) != null)
                {
                    tripBases.AddRange(tbs.GetTripByRouteId(item));
                }
            }
            //var orderedTripbase = tripBases.OrderBy(a => a.DepartureTime);
            foreach (var item in tripBases)
            {
                if (dws.GetDateWiseByTrip(item.Id, searchBus.DepartureDate) != null)
                {
                    dateWiseTrips.AddRange(dws.GetDateWiseByTrip(item.Id, searchBus.DepartureDate));
                }
            }
            foreach (var item in dateWiseTrips)
            {
                if (item.Date >= DateTime.Now.Date)
                {
                    if (item.Date == DateTime.Now.Date)
                    {
                        if (item.TripBase.DepartureTime.TimeOfDay > DateTime.Now.AddHours(2).TimeOfDay)
                        {
                            NewDateWise.Add(item);
                        }
                    }
                    else
                    {
                        NewDateWise.Add(item);
                    }
                }
            }
            orderedDateWise = NewDateWise.OrderBy(a => a.TripBase.DepartureTime.TimeOfDay).ToList();

            foreach (var item in orderedDateWise)
            {
                availableSeat.Add(bts.GetAvailableSeatByDateWise(item.Id));
            }


            SearchBus s = new SearchBus
            {
                GetDateWiseTrip   = orderedDateWise,
                FromLocation      = from.Location,
                ToLocation        = to.Location,
                noOfAvailableSeat = availableSeat
            };

            return(View(s));
        }
コード例 #2
0
        public ActionResult AddRouteView(RouteView routeView)
        {
            ViewBag.BusOperatorList   = new SelectList(context.BusOperators, "Id", "Name");
            ViewBag.LocationList      = new SelectList(context.Locations, "Id", "Location");
            ViewBag.ExistingRouteList = new SelectList(context.Routes, "Id", "RouteName");

            if (routeView.RouteId.HasValue)
            {
                #region for selected existing route
                OperatorRouteMap op = new OperatorRouteMap
                {
                    RouteId       = routeView.RouteId.Value,
                    BusOperatorId = routeView.BusOperatorId
                };
                response = orm.Save(op);
                #endregion
            }
            else
            {
                #region New Route Adding
                List <string> Routes       = new List <string>();
                var           FromLocation = ls.GetById(routeView.From);
                Routes.Add(FromLocation.Location);

                if (routeView.Via != null)
                {
                    foreach (var item in routeView.Via)
                    {
                        var ViaLocation = ls.GetById(item);
                        Routes.Add(ViaLocation.Location);
                    }
                }

                var ToLocation = ls.GetById(routeView.To);
                Routes.Add(ToLocation.Location);

                var   name = string.Join("-", Routes);
                Route r    = new Route()
                {
                    RouteName = name.ToString()
                };
                rs.Save(r);
                #region IsReverse is true
                if (routeView.IsReverse == true)
                {
                    Routes.Reverse();
                    var   nameReverse = string.Join("-", Routes);
                    Route rr          = new Route()
                    {
                        RouteName = nameReverse.ToString(),
                        ReverseId = r.Id
                    };
                    rs.Save(rr);

                    OperatorRouteMap opReverse = new OperatorRouteMap
                    {
                        RouteId       = rr.Id,
                        BusOperatorId = routeView.BusOperatorId
                    };
                    orm.Save(opReverse);
                    int k = 1;
                    rps.Save(new RoutePoints()
                    {
                        RouteId = rr.Id, LocationId = routeView.To, SequenceId = k, IsFrom = true
                    });
                    if (routeView.Via != null)
                    {
                        foreach (var item in routeView.Via.Reverse <int>())
                        {
                            k++;
                            rps.Save(new RoutePoints()
                            {
                                RouteId = rr.Id, LocationId = (int)item, SequenceId = k
                            });
                        }
                    }

                    rps.Save(new RoutePoints()
                    {
                        RouteId = rr.Id, LocationId = routeView.From, SequenceId = ++k, IsTo = true
                    });
                }
                #endregion
                OperatorRouteMap op = new OperatorRouteMap
                {
                    RouteId       = r.Id,
                    BusOperatorId = routeView.BusOperatorId
                };
                response = orm.Save(op);

                int j = 1;
                rps.Save(new RoutePoints()
                {
                    RouteId = r.Id, LocationId = routeView.From, SequenceId = j, IsFrom = true
                });

                if (routeView.Via != null)
                {
                    foreach (var item in routeView.Via)
                    {
                        j++;
                        rps.Save(new RoutePoints()
                        {
                            RouteId = r.Id, LocationId = (int)item, SequenceId = j
                        });
                    }
                }

                rps.Save(new RoutePoints()
                {
                    RouteId = r.Id, LocationId = routeView.To, SequenceId = ++j, IsTo = true
                });
                #endregion
            }

            switch (response.Success)
            {
            case true:
                ViewBag.Message = successMessage;
                break;

            case false:
                ViewBag.Message = failureMessage;
                break;
            }

            return(View());
        }