コード例 #1
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));
        }
コード例 #2
0
        public async Task <IActionResult> AlertBike([Bind("numberBike, message")] AlertBike alertBike)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(alertBike);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(alertBike));
        }