protected void DataPortal_Delete(SupplierCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Delete]", connection)) { command.CommandType = CommandType.StoredProcedure; 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(); }
public static async Task <Supplier> GetBySuppIdAsync(System.Int32 suppId) { var criteria = new SupplierCriteria { SuppId = suppId }; return(await DataPortal.FetchAsync <Supplier>(criteria)); }
public static async Task DeleteSupplierAsync(System.Int32 suppId) { var criteria = new SupplierCriteria { SuppId = suppId }; await DataPortal.DeleteAsync <Supplier>(criteria); }
/// <summary> /// Returns a <see cref="Supplier"/> object of the specified criteria. /// </summary> /// <param name="suppId">No additional detail available.</param> /// <returns>A <see cref="Supplier"/> object of the specified criteria.</returns> public static Supplier GetBySuppId(System.Int32 suppId) { var criteria = new SupplierCriteria { SuppId = suppId }; return(DataPortal.Fetch <Supplier>(criteria)); }
public static void DeleteSupplier(System.Int32 suppId) { var criteria = new SupplierCriteria { SuppId = suppId }; DataPortal.Delete <Supplier>(criteria); }
internal static async Task <SupplierList> GetBySuppIdAsync(System.Int32 suppId) { var criteria = new SupplierCriteria { SuppId = suppId }; return(await DataPortal.FetchAsync <AsyncChildLoader <SupplierList> >(criteria).ContinueWith(t => t.Result.Child)); }
/// <summary> /// Returns a <see cref="SupplierList"/> object of the specified criteria. /// </summary> /// <param name="suppId">No additional detail available.</param> /// <returns>A <see cref="SupplierList"/> object of the specified criteria.</returns> internal static SupplierList GetBySuppId(System.Int32 suppId) { var criteria = new SupplierCriteria { SuppId = suppId }; return(DataPortal.FetchChild <SupplierList>(criteria)); }
private void Child_Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } RaiseListChangedEvents = false; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { this.Add(PetShop.Tests.StoredProcedures.Supplier.GetSupplier(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
protected void DataPortal_Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); 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.Supplier' using the following criteria: {0}.", criteria)); } } } } OnFetched(); }
protected override void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) { return; } if (OriginalSuppId != SuppId) { // Insert new child. Supplier item = new Supplier { SuppId = SuppId, Name = Name, Status = Status, Addr1 = Addr1, Addr2 = Addr2, City = City, State = State, Zip = Zip, Phone = Phone }; item = item.Save(); // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships. foreach (Item itemToUpdate in Items) { itemToUpdate.Supplier = SuppId; } // Create a new connection. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); FieldManager.UpdateChildren(this, connection); } // Delete the old. var criteria = new SupplierCriteria { SuppId = OriginalSuppId }; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalSuppId = SuppId; OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalSuppId", this.OriginalSuppId); command.Parameters.AddWithValue("@p_SuppId", this.SuppId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Status", this.Status); command.Parameters.AddWithValue("@p_Addr1", ADOHelper.NullCheck(this.Addr1)); command.Parameters.AddWithValue("@p_Addr2", ADOHelper.NullCheck(this.Addr2)); command.Parameters.AddWithValue("@p_City", ADOHelper.NullCheck(this.City)); command.Parameters.AddWithValue("@p_State", ADOHelper.NullCheck(this.State)); command.Parameters.AddWithValue("@p_Zip", ADOHelper.NullCheck(this.Zip)); command.Parameters.AddWithValue("@p_Phone", ADOHelper.NullCheck(this.Phone)); //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(_originalSuppIdProperty, this.SuppId); } FieldManager.UpdateChildren(this, connection); } OnUpdated(); }
/// <summary> /// Determines if a record exists in the Supplier table in the database for the specified criteria. /// </summary> public static async Task <bool> ExistsAsync(SupplierCriteria criteria) { return(await PetShop.Tests.StoredProcedures.ExistsCommand.ExecuteAsync(criteria)); }
/// <summary> /// Determines if a record exists in the Supplier table in the database for the specified criteria. /// </summary> /// <param name="criteria">The criteria parameter is an <see cref="Supplier"/> object.</param> /// <returns>A boolean value of true is returned if a record is found.</returns> public static bool Exists(SupplierCriteria criteria) { return(PetShop.Tests.StoredProcedures.ExistsCommand.Execute(criteria)); }
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Supplier"/> object. /// </summary> /// <param name="criteria"><see cref="SupplierCriteria"/> 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(SupplierCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when fetching the <see cref="Supplier"/> object. /// </summary> /// <param name="criteria"><see cref="SupplierCriteria"/> 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(SupplierCriteria criteria, ref bool cancel);
internal static async Task <SupplierList> GetByCriteriaAsync(SupplierCriteria criteria) { return(await DataPortal.FetchAsync <AsyncChildLoader <SupplierList> >(criteria).ContinueWith(t => t.Result.Child)); }
internal static SupplierList GetByCriteria(SupplierCriteria criteria) { return(DataPortal.Fetch <SupplierList>(criteria)); }