コード例 #1
0
        public HttpResponseMessage GetAll()
        {
            try
            {
                List <Amigo> lstAmigos = new List <Amigo>();
                Amigo        amigo     = new Amigo();
                lstAmigos = amigo.listarTodos();

                //using (SqlConnection connection = new SqlConnection(this.ConnectionString))
                //{
                //    connection.Open();

                //    using (SqlCommand command = new SqlCommand())
                //    {
                //        command.Connection = connection;
                //        command.CommandText = "select nome, latitude, longitude from amigo";

                //        SqlDataReader reader = command.ExecuteReader();

                //        while (reader.Read())
                //        {
                //            Amigo amigo = new Amigo()
                //            {
                //                nome = reader["nome"] == DBNull.Value ? string.Empty : reader["nome"].ToString(),
                //                longitude = reader["longitude"] == DBNull.Value ? 0: float.Parse(reader["longitude"].ToString()),
                //                latitude = reader["latitude"] == DBNull.Value ? 0 : float.Parse(reader["longitude"].ToString())
                //            };

                //            lstAmigos.Add(amigo);
                //        }
                //    }

                //    connection.Close();
                //}

                return(Request.CreateResponse(HttpStatusCode.OK, lstAmigos.ToArray()));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }