Database Reference
In-Depth Information
_bushMobilePhone = new Phone
{
Number = "212 333-3333",
PhoneType = "Bush Mobile Phone",
// set tracking state to 'Add' to generate a SQL Insert statement
TrackingState = TrackingState.Add,
};
_bush.Phones.Add(_whiteHousePhone);
_bush.Phones.Add(_bushMobilePhone);
}
private async Task AddCustomerAsync()
{
// construct call to invoke UpdateCustomer action method in Web API service
_response = await _client.PostAsync("api/customer/updatecustomer/", _bush,
new JsonMediaTypeFormatter());
if (_response.IsSuccessStatusCode)
{
// capture newly created customer entity from service, which will include
// database-generated Ids for all entities
_bush = await _response.Content.ReadAsAsync<Customer>();
_whiteHousePhone = _bush.Phones.FirstOrDefault(x => x.CustomerId == _bush.CustomerId);
_bushMobilePhone = _bush.Phones.FirstOrDefault(x => x.CustomerId == _bush.CustomerId);
Console.WriteLine("Successfully created Customer {0} and {1} Phone Numbers(s)",
_bush.Name, _bush.Phones.Count);
foreach (var phoneType in _bush.Phones)
{
Console.WriteLine("Added Phone Type: {0}", phoneType.PhoneType);
}
}
else
Console.WriteLine("{0} ({1})", (int) _response.StatusCode, _response.ReasonPhrase);
}
private void CreateSecondCustomer()
{
// create customer #2 and phone numbers
_obama = new Customer
{
Name = "Barack Obama",
Company = "President",
// set tracking state to 'Add' to generate a SQL Insert statement
TrackingState = TrackingState.Add,
};
Search WWH ::




Custom Search