public async Task <IActionResult> PlanATrip(StopSearchViewModel welcome) { var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var bikerInfo = await _context.BikerInfos .FirstOrDefaultAsync(biker => biker.UserId == userId); var coordsStart = await _stopHandler.GetCoordinatesByAddress(welcome.AddressStart); var trip = new Trip() { TripName = welcome.TripName, TripDate = welcome.TripDate, StartingLat = coordsStart.results[0].geometry.location.lat, StartingLong = coordsStart.results[0].geometry.location.lng, BikerInfoId = bikerInfo.Id }; _context.Add(trip); await _context.SaveChangesAsync(); welcome.TripId = trip.Id; return(RedirectToAction("SearchForBarOrHotel", "Stops", welcome)); }
// [Authorize] public IActionResult Welcome(StopSearchViewModel stopSearchViewModel) { var getTrip = _applicationDbContext.Trips.LastOrDefault(); var coords = _stopHandler.GetCoordinatesByAddress(stopSearchViewModel.AddressStart).GetAwaiter().GetResult(); var homeStop = new Stop() { Address = stopSearchViewModel.AddressStart, IsHotel = false, StopOrderNumber = 1, StartingLatitiude = coords.results[0].geometry.location.lat, StartingLongitude = coords.results[0].geometry.location.lng }; getTrip.Stops.Add(homeStop); _applicationDbContext.Add(getTrip); _applicationDbContext.SaveChangesAsync(); return(View()); }
public async Task <IActionResult> SearchForBarOrHotel(StopSearchViewModel requestViewModel) { List <Stop> stops = null; if (string.Equals(requestViewModel.StopType, "brewery", StringComparison.InvariantCultureIgnoreCase)) { stops = await _stopHandler.GetStopByAddress(requestViewModel.AddressStart, requestViewModel.MaxMiles, "brewery"); stops.Select(stop => stop.TripId = requestViewModel.TripId).ToList(); } else if (string.Equals(requestViewModel.StopType, "hotel", StringComparison.InvariantCultureIgnoreCase)) { stops = await _stopHandler.GetStopByAddress(requestViewModel.AddressStart, requestViewModel.MaxMiles, "hotel"); stops.Select(stop => stop.TripId = requestViewModel.TripId).ToList(); } return(View("StopSelection", stops)); }