public async Task <IActionResult> MyTrips(string userId, int page = 1) { var tripsViewModel = await this.tripsService .GetMyTripsAsync <TripViewModel>(userId, TripsPerPage, (page - 1) *TripsPerPage); foreach (var trip in tripsViewModel) { trip.DriverAvatarImageUrl = trip.DriverAvatarImageUrl == null ? "/img/avatar.png" : this.imagePathPrefix + this.driverImageSizing + trip.DriverAvatarImageUrl; } var myTripsCount = await this.tripsService.GetMyTripsCountAsync(userId); var tripsMyViewModel = new TripsViewModel { Title = "My trips:", CurrentPage = page, PagesCount = (int)Math.Ceiling((double)myTripsCount / TripsPerPage), Trips = tripsViewModel, }; if (tripsMyViewModel.PagesCount == 0) { tripsMyViewModel.PagesCount = 1; } return(this.View("All", tripsMyViewModel)); }
public ActionResult Trips() { TripsViewModel model = new TripsViewModel(); DataContext db = new DataContext(); List <Entry> entrieses = db.Entries.OrderByDescending(x => x.CreatedDate).ToList(); model.EntryList = entrieses; return(View(model)); }
public async Task <IActionResult> Index() { var tripView = new TripsViewModel { RangeStart = new DateTime(DateTime.Now.Year, 1, 1), RangeEnd = new DateTime(DateTime.Now.Year, 12, 31), }; tripView.Trips = await GetTrips(tripView.RangeStart, tripView.RangeEnd); tripView.Vehicles = await GetVehicles(); return(View(tripView)); }
public async Task <IActionResult> Post([FromBody] TripsViewModel recievedTrip) { if (ModelState.IsValid) { var newTrip = Mapper.Map <Trip>(recievedTrip); newTrip.UserName = User.Identity.Name; _repository.AddTrip(newTrip); if (await _repository.SaveChangesAsync()) { return(Created($"api/trips/{recievedTrip.Name}", Mapper.Map <TripsViewModel>(newTrip))); } } return(BadRequest("Failed to save the trip")); }
public ActionResult Trips(int id, int?page) { TripsViewModel model; using (ApplicationDbContext dbContext = new ApplicationDbContext()) { var data = from route in dbContext.Routes where route.ProvinceId == id orderby route.RouteId select new Trips { Trip = route, DriverId = route.DriverId, UsersList = route.Users.ToList() }; int pageSize = 5; int pageNumber = (page ?? 1); model = new TripsViewModel { TripsList = data.ToPagedList(pageNumber, pageSize), User = UserInstance(dbContext) }; } ViewBag.Id = id; return(View(model)); }
public IHttpActionResult PostTrip(TripsViewModel trip) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Trip tripdb = new Trip(); tripdb.Bus = db.Buses.First(b => b.Id == trip.busId); tripdb.Date = trip.date; tripdb.ArrivalDate = trip.arrivalDate; List <ClientTrip> clientsDb = new List <ClientTrip>(); foreach (var item in trip.clients) { ClientTrip clientTrip = new ClientTrip(); clientTrip.Client = db.Clients.First(i => i.Id == item.Id); clientTrip.From = db.Cities.First(i => i.Name == item.From); clientTrip.To = db.Cities.First(i => i.Name == item.To); clientTrip.Price = item.Price; clientTrip.IsStayInBus = item.IsStayInBus; clientTrip.HasBaggage = item.HasBaggage; clientTrip.Agent = db.Agents.First(x => x.Id == item.AgentId); clientTrip.AgentPrice = item.AgentPrice; clientTrip.AdditionalExpenses = item.AdditionalExpenses; clientsDb.Add(clientTrip); } tripdb.ClientTrip = clientsDb; tripdb.CityFrom = db.Cities.First(c => c.Id == trip.cityFrom); tripdb.CityTo = db.Cities.First(c => c.Id == trip.cityTo); tripdb.Comments = trip.comments; db.Trips.Add(tripdb); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = tripdb.Id }, trip)); }
public async Task <IActionResult> Search(TripSearchInputModel inputModel, int page = 1) { if (!this.ModelState.IsValid) { return(this.View()); } var userId = this.userManager.GetUserId(this.User); var tripsViewModel = await this.tripsService .ShowSearchResultsAsync <TripViewModel>(inputModel, userId, TripsPerPage, (page - 1) *TripsPerPage); int searchResultsCount = 0; if (tripsViewModel != null) { foreach (var trip in tripsViewModel) { trip.DriverAvatarImageUrl = trip.DriverAvatarImageUrl == null ? "/img/avatar.png" : this.imagePathPrefix + this.driverImageSizing + trip.DriverAvatarImageUrl; } searchResultsCount = await this.tripsService.GetSearchResultsCountAsync(inputModel, userId); } var tripsSearchViewModel = new TripsViewModel { Title = "Search results:", CurrentPage = page, PagesCount = (int)Math.Ceiling((double)(searchResultsCount / TripsPerPage)), Trips = tripsViewModel, }; if (tripsSearchViewModel.PagesCount == 0) { tripsSearchViewModel.PagesCount = 1; } return(this.View("All", tripsSearchViewModel)); }
public ViewModelLocator() { myNavigationService = new MyNavigationService(); appViewModel = new AppViewModel(myNavigationService); logInViewModel = new LogInViewModel(myNavigationService); menyuViewModel = new MenyuViewModel(myNavigationService); tripsViewModel = new TripsViewModel(myNavigationService); registrationViewModel = new RegistrationViewModel(myNavigationService); weatherViewModel = new WeatherViewModel(myNavigationService); ticketsPDFViewModel = new TicketsPDFViewModel(myNavigationService); citiesViewModel = new CitiesViewModel(myNavigationService); introViewModel = new IntroViewModel(myNavigationService); mapViewModel = new MapViewModel(myNavigationService); searchInfoViewModel = new SearchInfoViewModel(myNavigationService); ticketsViewModel = new TicketsViewModel(myNavigationService); myNavigationService.Register <LogInViewModel>(logInViewModel); myNavigationService.Register <MenyuViewModel>(menyuViewModel); myNavigationService.Register <TripsViewModel>(tripsViewModel); myNavigationService.Register <RegistrationViewModel>(registrationViewModel); myNavigationService.Register <WeatherViewModel>(weatherViewModel); myNavigationService.Register <TicketsPDFViewModel>(ticketsPDFViewModel); myNavigationService.Register <CitiesViewModel>(citiesViewModel); myNavigationService.Register <IntroViewModel>(introViewModel); myNavigationService.Register <MapViewModel>(mapViewModel); myNavigationService.Register <SearchInfoViewModel>(searchInfoViewModel); myNavigationService.Register <TicketsViewModel>(ticketsViewModel); //myNavigationService.Register("LogIn", logInViewModel); //myNavigationService.Register("Menyu", menyuViewModel); //myNavigationService.Register("Trips", tripsViewModel); //myNavigationService.Register("Registration", registrationViewModel); //myNavigationService.Navigate<LogInViewModel>(); myNavigationService.Navigate <IntroViewModel>(); //myNavigationService.Navigate<TicketsPDFViewModel>(); //myNavigationService.Navigate<TripsViewModel>(); //myNavigationService.Navigate("LogIn"); }
public TripListFragment() { ViewModel = ServiceLocator.Instance.Get <TripsViewModel>(); ViewModel.ErrorAction = ToastMessage; }
public TripsPage() { InitializeComponent(); BindingContext = viewModel = new TripsViewModel(); }
public TripsCollectionViewController(IntPtr handle) : base(handle) { ViewModel = ServiceLocator.Instance.Get <TripsViewModel>(); }
public async Task <IActionResult> ShowTrips(TripsViewModel tripsView) { tripsView.Trips = await GetTrips(tripsView.RangeStart, tripsView.RangeEnd); return(View("Index", tripsView)); }