Example #1
0
        public int AddObservation(BirdObservation observation)
        {
            // TODO use date from user
            const string insertStudent = "insert into birdObservation (birdId, userId, latitude, longitude, placeName, population, comment, created) values (@birdId, @userId, @latitude, @longitude, @placeName, @population, @comment, @created)";

            using (SqlConnection databaseConnection = new SqlConnection(ConnectionString))
            {
                databaseConnection.Open();
                using (SqlCommand insertCommand = new SqlCommand(insertStudent, databaseConnection))
                {
                    insertCommand.Parameters.AddWithValue("@birdId", observation.BirdId);
                    insertCommand.Parameters.AddWithValue("@userId", observation.UserId);
                    //insertCommand.Parameters.AddWithValue("@created", observation.Created);
                    DateTime?da = observation.Created;
                    if (da == null)
                    {
                        insertCommand.Parameters.AddWithValue("@created", DateTime.Now.Date);
                    }
                    else
                    {
                        insertCommand.Parameters.AddWithValue("@created", da);
                    }

                    insertCommand.Parameters.AddWithValue("@latitude", observation.Latitude);
                    insertCommand.Parameters.AddWithValue("@longitude", observation.Longitude);
                    SetParameter("placeName", observation.Placename, insertCommand);
                    insertCommand.Parameters.AddWithValue("@population", observation.Population);
                    SetParameter("comment", observation.Comment, insertCommand);
                    int rowsAffected = insertCommand.ExecuteNonQuery();
                    // TODO return new ID, or new object
                    return(rowsAffected);
                }
            }
        }
Example #2
0
 public int UpdateObservation(string id, BirdObservation observation)
 {
     return(0);
 }