Exemplo n.º 1
0
        public static List <Sighting> GetSightingsList()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            List <Sighting> allSightings = new List <Sighting>();

            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM sightings ORDER BY date_time ASC LIMIT 10";

            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int      id          = rdr.GetInt32(0);
                string   description = rdr.GetString(1);
                string   type        = rdr.GetString(2);
                DateTime time        = rdr.GetDateTime(3);
                string   address     = rdr.GetString(4);
                string   city        = rdr.GetString(5);
                string   state       = rdr.GetString(6);

                Sighting newSighting = new Sighting(description, type, time, address, city, state, id);
                allSightings.Add(newSighting);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(allSightings);
        }
Exemplo n.º 2
0
        public List <Sighting> GetAllUserSightings()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM sightings WHERE user_id = @UserId;";

            cmd.Parameters.AddWithValue("@UserId", Id);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            List <Sighting> allSightings = new List <Sighting>()
            {
            };

            while (rdr.Read())
            {
                int      id          = rdr.GetInt32(0);
                string   description = rdr.GetString(1);
                string   type        = rdr.GetString(2);
                DateTime time        = rdr.GetDateTime(3);
                string   address     = rdr.GetString(4);
                string   city        = rdr.GetString(5);
                string   state       = rdr.GetString(6);
                double   lat         = rdr.GetDouble(7);
                double   lng         = rdr.GetDouble(8);
                int      userId      = rdr.GetInt32(9);

                Sighting newSighting = new Sighting(description, type, time, address, city, state, lat, lng, userId, id);
                allSightings.Add(newSighting);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(allSightings);
        }
Exemplo n.º 3
0
        public override bool Equals(System.Object otherSighting)
        {
            if (!(otherSighting is Sighting))
            {
                return(false);
            }
            else
            {
                Sighting newSighting         = (Sighting)otherSighting;
                bool     idEquality          = (this.Id == newSighting.Id);
                bool     descriptionEquality = (this.Description == newSighting.Description);
                bool     typeEquality        = (this.Type == newSighting.Type);
                bool     timeEquality        = (this.Time == newSighting.Time);
                bool     addressEquality     = (this.Address == newSighting.Address);
                bool     cityEquality        = (this.City == newSighting.City);
                bool     stateEquality       = (this.State == newSighting.State);
                bool     latEquality         = (this.Lat == newSighting.Lat);
                bool     lngEquality         = (this.Lng == newSighting.Lng);
                bool     UserIdEquality      = (this.UserId == newSighting.UserId);

                return(idEquality && descriptionEquality && typeEquality && timeEquality && addressEquality && cityEquality && stateEquality && latEquality && lngEquality && UserIdEquality);
            }
        }