/// <summary> /// Deletes data in the data base using the criteria specified in the AccountCriteria object. /// </summary> /// <param name="criteria">Object of type <see cref="AccountCriteria"/></param> /// <returns></returns> protected void DataPortal_Delete(AccountCriteria criteria, SqlConnection connection) { bool cancel = false; OnDeleting(criteria, connection, ref cancel); if (cancel) { return; } var commandText = String.Format("DELETE FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) { throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } OnDeleted(); }
/// <summary> /// Retrieves data from the data base into a CSLA editable child business object of type <see cref="Account"/> /// using the criteria provided. /// </summary> /// <param name="criteria">Object of type <see cref="AccountCriteria"/></param> /// <returns></returns> private void Child_Fetch(AccountCriteria criteria) { bool cancel = false; OnChildFetching(criteria, ref cancel); if (cancel) { return; } 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()) { Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Account' using the following criteria: {0}.", criteria)); } } } } OnChildFetched(); }
internal static async Task <Account> GetByAccountIdAsync(System.Int32 accountId) { var criteria = new AccountCriteria { AccountId = accountId }; return(await DataPortal.FetchAsync <AsyncChildLoader <Account> >(criteria).ContinueWith(t => t.Result.Child)); }
internal static async Task <Account> GetByUniqueIDAsync(System.Int32 uniqueID) { var criteria = new AccountCriteria { UniqueID = uniqueID }; return(await DataPortal.FetchAsync <AsyncChildLoader <Account> >(criteria).ContinueWith(t => t.Result.Child)); }
/// <summary> /// Returns a <see cref="Account"/> object of the specified criteria. /// </summary> /// <param name="uniqueID">No additional detail available.</param> /// <returns>A <see cref="Account"/> object of the specified criteria.</returns> internal static Account GetByUniqueID(System.Int32 uniqueID) { var criteria = new AccountCriteria { UniqueID = uniqueID }; return(DataPortal.FetchChild <Account>(criteria)); }
/// <summary> /// Returns a <see cref="Account"/> object of the specified criteria. /// </summary> /// <param name="accountId">No additional detail available.</param> /// <returns>A <see cref="Account"/> object of the specified criteria.</returns> internal static Account GetByAccountId(System.Int32 accountId) { var criteria = new AccountCriteria { AccountId = accountId }; return(DataPortal.FetchChild <Account>(criteria)); }
private void Child_Fetch(AccountCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } RaiseListChangedEvents = false; // Fetch Child objects. 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()) { do { this.Add(PetShop.Business.Account.GetAccount(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
/// <summary> /// Determines if a record exists in the Account table in the database for the specified criteria. /// </summary> public static async Task <bool> ExistsAsync(AccountCriteria criteria) { return(await PetShop.Business.ExistsCommand.ExecuteAsync(criteria)); }
/// <summary> /// Determines if a record exists in the Account table in the database for the specified criteria. /// </summary> /// <param name="criteria">The criteria parameter is an <see cref="Account"/> object.</param> /// <returns>A boolean value of true is returned if a record is found.</returns> public static bool Exists(AccountCriteria criteria) { return(PetShop.Business.ExistsCommand.Execute(criteria)); }
/// <summary> /// CodeSmith generated stub method that is called when deleting the child <see cref="Account"/> object. /// </summary> /// <param name="criteria"><see cref="AccountCriteria"/> object containing the criteria of the object to delete.</param> /// <param name="connection"></param> /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param> partial void OnDeleting(AccountCriteria criteria, SqlConnection connection, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when deleting the child <see cref="Account"/> object. /// </summary> /// <param name="criteria"><see cref="AccountCriteria"/> object containing the criteria of the object to delete.</param> /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param> partial void OnDeleting(AccountCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when fetching the child <see cref="Account"/> object. /// </summary> /// <param name="criteria"><see cref="AccountCriteria"/> object containing the criteria of the object to fetch.</param> /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param> partial void OnChildFetching(AccountCriteria criteria, ref bool cancel);
internal static AccountList GetByCriteria(AccountCriteria criteria) { return(DataPortal.Fetch <AccountList>(criteria)); }
/// <summary> /// Determines if a record exists in the Account in the database for the specified criteria. /// </summary> /// <param name="criteria">The criteria parameter is a <see cref="AccountList"/> object.</param> /// <returns>A boolean value of true is returned if a record is found.</returns> public static bool Exists(AccountCriteria criteria) { return(PetShop.Business.Account.Exists(criteria)); }
internal static async Task <AccountList> GetByCriteriaAsync(AccountCriteria criteria) { return(await DataPortal.FetchAsync <AsyncChildLoader <AccountList> >(criteria).ContinueWith(t => t.Result.Child)); }