public TimeTableIndexWithRoutesViewModel GetModelWithEditRoute(int?id) { var route = this.Db.Routes.Where(x => x.Id == id).Include(x => x.Line).FirstOrDefault(); if (route == null) { return(null); } var routemodel = new EditRouteInputModel { Id = route.Id, Day = route.DayType.ToString(), RouteName = route.RouteName }; var model = new TimeTableIndexWithRoutesViewModel { EditRoute = routemodel, LineId = route.LineId, Tab = "1", Day = route.DayType.ToString(), Direction = route.Direction.ToString(), }; return(model); }
public TimeTableIndexWithRoutesViewModel GetModelWithRoutes(Direction direction, DayType day, int?lineId) { var line = this.Db.Lines .Where(x => x.Id == lineId) .Include(x => x.Routes) .FirstOrDefault(); if (line == null) { return(null); } var model = new TimeTableIndexWithRoutesViewModel { Day = day.ToString(), Direction = direction.ToString(), LineId = line.Id, Tab = "0" }; var routes = line.Routes .Where(x => x.Direction == direction && x.DayType == day) .Select(x => new RouteViewModel { Id = x.Id, RouteName = x.RouteName }).ToList(); model.Routes = routes; return(model); }
public TimeTableIndexWithRoutesViewModel GetModelWithRouteStops(int?id) { var route = this.Db.Routes .Where(x => x.Id == id) .Include(x => x.Line) .Include(x => x.TimeTables) .FirstOrDefault(); if (route == null) { return(null); } var allStations = this.Db.Stations.ToList(); var timeTables = route.TimeTables.Select(x => new TimeTableViewModel { Id = x.Id, StationName = allStations.FirstOrDefault(s => s.Id == x.StationId).StationName, DepartureTime = x.DepartureTime }).ToList(); //TODO: GET ONLY STATIONS THAT LINE HAVE var stations = allStations .Select(x => new SelectListItem { Text = x.StationName, Value = x.StationName }) .ToList(); var createStopModel = new CreateStopInputModel { RouteId = route.Id, Stations = stations }; var orderTimeTables = timeTables.OrderBy(x => x.DepartureTime).ToList(); var model = new TimeTableIndexWithRoutesViewModel { LineId = route.LineId, Tab = "2", Day = route.DayType.ToString(), Direction = route.Direction.ToString(), TimeTables = orderTimeTables, CreateStop = createStopModel }; return(model); }
public IActionResult Index(int?id) { List <SelectListItem> directionTypes, dayTypes; GetCardTypesAndValidityCards(out directionTypes, out dayTypes); var model = this.TimeTableService.GetModelWIthoutRoutes(id); if (model == null) { this.TempData.Put(MessageConstants.Name, new MessageModel { Type = MessageType.Danger, Message = MessageConstants.InvalidLineId }); return(this.RedirectToAction(nameof(LineController.Index), "Line")); } if (!model.HasRoutes) { model.CreateRoute.DirectionTypes = directionTypes; model.CreateRoute.DayTypes = dayTypes; return(this.View(model)); } var modelWithRoutes = new TimeTableIndexWithRoutesViewModel { DirectionTypes = directionTypes, DayTypes = dayTypes, LineId = id.Value, CreateRoute = model.CreateRoute, Tab = "0" }; return(this.View("IndexWithRoutes", modelWithRoutes)); }