示例#1
0
 public void Save(Temblor temblor)
 {
     if (temblor.Id != 0)
         repository.Update(temblor);
     else
         repository.Add(temblor);
 }
示例#2
0
        public void Save(Temblor temblor)
        {
            SqlCommand command = new SqlCommand(temblor.Id != 0 ? insertTemblor : updateTemblor , connection as SqlConnection);
            command.Parameters.AddWithValue("@magnitud", temblor.Magnitud);
            command.Parameters.AddWithValue("@profundidad", temblor.Profundidad);
            command.Parameters.AddWithValue("@latitud", temblor.Latitud);
            command.Parameters.AddWithValue("@longitud", temblor.Longitud);
            command.Parameters.AddWithValue("@fecha", temblor.Fecha);
            command.CommandType = CommandType.Text;

            if (temblor.Id != 0)
            {
                command.Parameters.AddWithValue("@id", temblor.Id);
                command.ExecuteNonQuery();
            }else
            {
                int id = (int) command.ExecuteScalar();
                temblor.Id = id;
            }
        }
示例#3
0
        Temblor[] LoadTemblores(SqlCommand command)
        {
            List<Temblor> temblores = new List<Temblor>();

            using(SqlDataReader reader = command.ExecuteReader()) {
                if(reader.HasRows) {
                    while (reader.Read()) {

                        Temblor temblor = new Temblor
                                              {
                                                  Id = reader.GetInt32(0),
                                                  Fecha = reader.GetDateTime(1),
                                                  Latitud = reader.GetDouble(2),
                                                  Longitud = reader.GetDouble(3),
                                                  Magnitud = reader.GetDouble(4),
                                                  Profundidad = reader.GetDouble(5)
                                              };

                        temblores.Add(temblor);
                    }
                }
            }
            return temblores.ToArray();
        }