예제 #1
0
        public async Task <IActionResult> AddToFav(int id)
        {
            var favBikeStation = new FavBikeStations();

            favBikeStation.idFav = id;
            _context.FavBikeStations.Add(favBikeStation);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> StationListAsync(double latitudeUser = 0f, double longitudeUser = 0f, string ville = "lyon", int idFav = 0)
        {
            List <Stations> StationList = new List <Stations>();

            if (ville == "lyon")
            {
                StationList = await Traitement.FindStation();
            }
            else if (ville == "bordeaux")
            {
                StationList = await Traitement.FindStationBordeaux();
            }

            if (latitudeUser == 0 && longitudeUser == 0)
            {
                StationList.Sort((x, y) => x.name.CompareTo(y.name));
            }
            else
            {
                StationList = StationList.OrderBy(s => s.CompareDistance(latitudeUser, longitudeUser)).ToList();
            }

            if (idFav != 0)
            {
                var a = new FavorisModel();
                a.stationId = idFav;
                context.Add(a);
                await context.SaveChangesAsync();
            }

            ViewBag.Ville = ville;
            return(View(StationList));
        }