Exemple #1
0
        public IHttpActionResult GetWells()
        {
            List <WellDTO> wells = new List <WellDTO>();

            using (SqlConnection connection = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["fracdatasource"].ConnectionString))
            {
                //SqlCommand command = new SqlCommand("select * from well inner join welldata on well.id = welldata.id", connection);
                SqlCommand command = new SqlCommand("select * from well;", connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        WellDTO newWell = new WellDTO()
                        {
                            Id = int.Parse(reader["Id"].ToString()), Name = reader["Name"].ToString()
                        };
                        wells.Add(newWell);
                    }
                }
                finally
                {
                    // Always call Close when done reading.
                    reader.Close();
                }
            }

            return(Ok(wells));
        }
 /// <summary>
 /// All Wells
 /// </summary>
 /// <returns></returns>
 public async Task <WellDTO> GetWellByName(string wellName)
 {
     using (var connection = CreateConnection())
     {
         var well = new WellDTO();
         try
         {
             // Geting data for Wells from database using Store proc
             well = await connection.QuerySingleAsync <WellDTO>(StoredProcedureNames.GET_WELL_BY_NAME, new { WELL_NAME = wellName }, null, null, commandType : CommandType.StoredProcedure).ConfigureAwait(false);
         }
         catch (Exception ex)
         {
         }
         return(well);
     }
 }