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 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 AddWalker(Walker walker) { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"INSERT INTO Walker([Name], Email, ImageUrl, NeighborhoodId) OUTPUT INSERTED.ID VALUES (@name, @email, @imageUrl, @neighborhoodId); "; cmd.Parameters.AddWithValue("@name", walker.Name); cmd.Parameters.AddWithValue("@email", walker.Email); cmd.Parameters.AddWithValue("@imageUrl", ReaderUtils.GetNullableParam(walker.ImageUrl)); cmd.Parameters.AddWithValue("@neighborhoodId", walker.NeighborhoodId); int id = (int)cmd.ExecuteScalar(); walker.Id = id; } } }
public void UpdateWalker(Walker walker) { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"UPDATE Walker SET [Name] = @name, Email = @email, ImageUrl = @imageUrl, NeighborhoodId = @neighborhoodId WHERE Id = @id"; cmd.Parameters.AddWithValue("@id", walker.Id); cmd.Parameters.AddWithValue("@name", walker.Name); cmd.Parameters.AddWithValue("@email", walker.Email); cmd.Parameters.AddWithValue("@imageUrl", ReaderUtils.GetNullableParam(walker.ImageUrl)); cmd.Parameters.AddWithValue("@neighborhoodId", walker.NeighborhoodId); cmd.ExecuteNonQuery(); } } }