Exemplo n.º 1
0
        public ActionResult Create(Station station)
        {
            if (ModelState.IsValid)
            {
                db.Stations.Add(station);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(station);
        }
Exemplo n.º 2
0
        private Station GetClosestStation(string lat, string lng)
        {
            string queryString =
                String.Format(@"SELECT TOP(1) Location.ToString(), Id, StationName, latitude, longitude FROM DivvyStations
                WHERE Location.STDistance(geography::Point(@lat, @lng, 4326)) IS NOT NULL
                ORDER BY Location.STDistance(geography::Point(@lat, @lng, 4326))");

            var station = new Station();

            using (SqlConnection connection =
            new SqlConnection(_connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@lat", lat);
                command.Parameters.AddWithValue("@lng", lng);

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        //Console.WriteLine("\t{0}\t{1}\t{2}",
                        //reader[0], reader[1], reader[2]);
                        station = new Station
                        {
                            id = (int)reader["Id"],
                            stationName = reader["StationName"].ToString(),
                            latitude = (double)reader["latitude"],
                            longitude = (double)reader["longitude"]
                        };

                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return station;
        }
Exemplo n.º 3
0
 public ActionResult Edit(Station station)
 {
     if (ModelState.IsValid)
     {
         db.Entry(station).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(station);
 }