public void AddDog(Dog dog) { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @" INSERT INTO Dog ([Name], OwnerId, Breed, Notes, ImageUrl) OUTPUT INSERTED.ID VALUES (@name, @ownerId, @breed, @notes, @imageUrl) "; cmd.Parameters.AddWithValue("@name", dog.Name); cmd.Parameters.AddWithValue("@ownerId", dog.OwnerId); cmd.Parameters.AddWithValue("@breed", dog.Breed); cmd.Parameters.AddWithValue("@notes", ReaderUtils.GetNullableParam(dog.Notes)); cmd.Parameters.AddWithValue("@imageUrl", ReaderUtils.GetNullableParam(dog.ImageUrl)); int id = (int)cmd.ExecuteScalar(); dog.Id = id; } } }
public void UpdateDog(Dog dog) { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @" UPDATE Dog SET [Name] = @name, [OwnerId] = @ownerid, [Breed] = @breed, [Notes] = @notes, [ImageUrl] = @imageurl WHERE Id = @id"; cmd.Parameters.AddWithValue("@id", dog.Id); cmd.Parameters.AddWithValue("@name", dog.Name); cmd.Parameters.AddWithValue("@ownerid", dog.OwnerId); cmd.Parameters.AddWithValue("@breed", dog.Breed); cmd.Parameters.AddWithValue("@notes", ReaderUtils.GetNullableParam(dog.Notes)); cmd.Parameters.AddWithValue("@imageurl", ReaderUtils.GetNullableParam(dog.ImageUrl)); cmd.ExecuteNonQuery(); } } }
public void AddWalker(Walker walker) { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @" INSERT INTO Walker (Name, ImageUrl, NeighborhoodId) OUTPUT INSERTED.ID VALUES (@name, @imageUrl, @neighborhoodId);"; cmd.Parameters.AddWithValue("@name", walker.Name); cmd.Parameters.AddWithValue("imageUrl", ReaderUtils.GetNullableParam(walker.ImageUrl)); cmd.Parameters.AddWithValue("neighborhoodId", ReaderUtils.GetNullableParam(walker.NeighborhoodId)); int id = (int)cmd.ExecuteScalar(); walker.Id = id; } } }