protected void DataPortal_Delete(InventoryCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) { return; } string commandText = String.Format("DELETE FROM [dbo].[Inventory] {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)); //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(); }
protected void DataPortal_Fetch(InventoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } string commandText = String.Format("SELECT [ItemId], [Qty] FROM [dbo].[Inventory] {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.Inventory' using the following criteria: {0}.", criteria)); } } } } OnFetched(); }
public static async Task DeleteInventoryAsync(System.String itemId) { var criteria = new InventoryCriteria { ItemId = itemId }; await DataPortal.DeleteAsync <Inventory>(criteria); }
public static async Task <Inventory> GetByItemIdAsync(System.String itemId) { var criteria = new InventoryCriteria { ItemId = itemId }; return(await DataPortal.FetchAsync <Inventory>(criteria)); }
public static void DeleteInventory(System.String itemId) { var criteria = new InventoryCriteria { ItemId = itemId }; DataPortal.Delete <Inventory>(criteria); }
/// <summary> /// Returns a <see cref="Inventory"/> object of the specified criteria. /// </summary> /// <param name="itemId">No additional detail available.</param> /// <returns>A <see cref="Inventory"/> object of the specified criteria.</returns> public static Inventory GetByItemId(System.String itemId) { var criteria = new InventoryCriteria { ItemId = itemId }; return(DataPortal.Fetch <Inventory>(criteria)); }
protected override void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) { return; } if (OriginalItemId != ItemId) { // Insert new child. Inventory item = new Inventory { ItemId = ItemId, Qty = Qty }; item = item.Save(); // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships. // Create a new connection. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); FieldManager.UpdateChildren(this, connection); } // Delete the old. var criteria = new InventoryCriteria { ItemId = OriginalItemId }; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalItemId = ItemId; OnUpdated(); return; } const string commandText = "UPDATE [dbo].[Inventory] SET [ItemId] = @p_ItemId, [Qty] = @p_Qty WHERE [ItemId] = @p_OriginalItemId; SELECT [ItemId] FROM [dbo].[Inventory] WHERE [ItemId] = @p_OriginalItemId"; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@p_OriginalItemId", this.OriginalItemId); command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_Qty", this.Qty); //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."); } LoadProperty(_originalItemIdProperty, this.ItemId); } } OnUpdated(); }
/// <summary> /// Determines if a record exists in the Inventory table in the database for the specified criteria. /// </summary> public static async Task <bool> ExistsAsync(InventoryCriteria criteria) { return(await PetShop.Business.ExistsCommand.ExecuteAsync(criteria)); }
/// <summary> /// Determines if a record exists in the Inventory table in the database for the specified criteria. /// </summary> /// <param name="criteria">The criteria parameter is an <see cref="Inventory"/> object.</param> /// <returns>A boolean value of true is returned if a record is found.</returns> public static bool Exists(InventoryCriteria criteria) { return(PetShop.Business.ExistsCommand.Execute(criteria)); }
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Inventory"/> object. /// </summary> /// <param name="criteria"><see cref="InventoryCriteria"/> 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(InventoryCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when fetching the <see cref="Inventory"/> object. /// </summary> /// <param name="criteria"><see cref="InventoryCriteria"/> 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 OnFetching(InventoryCriteria criteria, ref bool cancel);