public async Task <PersonPhone> GetPersonPhone(int id) { PersonPhone phone; var command = new SqlCommand("GetPersonPhone", connection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@id", id); using (var ts = new TransactionScope()) { var reader = command.ExecuteReader(); await reader.ReadAsync(); var businessEntityID = reader.GetFieldValueAsync <int>(0); var typeId = reader.GetFieldValueAsync <int>(2); phone = new PersonPhone { PhoneNumber = await reader.GetFieldValueAsync <string>(1), ModifiedDate = await reader.GetFieldValueAsync <DateTime>(3) }; reader.Close(); phone.BusinessEntity = await GetBusinessEntity(businessEntityID.Result); phone.PhoneNumberType = await GetPhoneNumberType(typeId.Result); ts.Complete(); } return(phone); }
public PersonPhone GetPhoneById(int id) { PersonPhone ans = null; var command = new SqlCommand(GET_PHONE_PROC, connection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("idArg", id)); using (var scope = new TransactionScope()) { var list = Map <PersonPhone>(command.ExecuteReader(), config); scope.Complete(); if (list.Count == 0) { ans = new PersonPhone(); } else { ans = list.First(); } } return(ans); }