/// <summary> /// Fetch Account. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Account Fetch(AccountCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Account item; string commandText = String.Format("SELECT [AccountId], [UniqueID], [Email], [FirstName], [LastName], [Address1], [Address2], [City], [State], [Zip], [Country], [Phone] FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { item = Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Account' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }
/// <summary> /// Fetch SupplierList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public SupplierList Fetch(SupplierCriteria criteria) { SupplierList item = (SupplierList)Activator.CreateInstance(typeof(SupplierList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new SupplierFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }