/// <summary> /// Retrieves data from the data base into a CSLA editable child business object of type <see cref="Cart"/> /// using the criteria provided. /// </summary> /// <param name="criteria">Object of type <see cref="CartCriteria"/></param> /// <returns></returns> private void Child_Fetch(CartCriteria criteria) { bool cancel = false; OnChildFetching(criteria, ref cancel); if (cancel) return; string commandText = String.Format("SELECT [CartId], [UniqueID], [ItemId], [Name], [Type], [Price], [CategoryId], [ProductId], [IsShoppingCart], [Quantity] FROM [dbo].[Cart] {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.Cart' using the following criteria: {0}.", criteria)); } } } OnChildFetched(); }
/// <summary> /// This call to delete is for immediate deletion and doesn't keep track of any entity state. /// </summary> /// <param name="criteria">The Criteria.</param> private void DoDelete(CartCriteria 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_Cart_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(); }
private void Child_Fetch(CartCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; RaiseListChangedEvents = false; // Fetch Child objects. string commandText = String.Format("SELECT [CartId], [UniqueID], [ItemId], [Name], [Type], [Price], [CategoryId], [ProductId], [IsShoppingCart], [Quantity] FROM [dbo].[Cart] {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.Cart.GetCart(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
/// <summary> /// Fetch CartList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CartList Fetch(CartCriteria criteria) { CartList item = (CartList)Activator.CreateInstance(typeof(CartList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. string commandText = String.Format("SELECT [CartId], [UniqueID], [ItemId], [Name], [Type], [Price], [CategoryId], [ProductId], [IsShoppingCart], [Quantity] FROM [dbo].[Cart] {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 CartFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return item; }
/// <summary> /// Fetch CartList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CartList Fetch(CartCriteria criteria) { CartList item = (CartList)Activator.CreateInstance(typeof(CartList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Cart_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { item.Add(new CartFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return item; }
private Cart Create(CartCriteria criteria) { var item = (Cart)Activator.CreateInstance(typeof(Cart), true); bool cancel = false; OnCreating(ref cancel); if (cancel) return item; var resource = Fetch(criteria); using (BypassPropertyChecks(item)) { item.ItemId = resource.ItemId; item.Name = resource.Name; item.Type = resource.Type; item.Price = resource.Price; item.CategoryId = resource.CategoryId; item.ProductId = resource.ProductId; item.IsShoppingCart = resource.IsShoppingCart; item.Quantity = resource.Quantity; } CheckRules(item); MarkNew(item); MarkAsChild(item); OnCreated(); return item; }
private Cart Create(CartCriteria criteria) { var item = (Cart)Activator.CreateInstance(typeof(Cart), true); bool cancel = false; OnCreating(ref cancel); if (cancel) { return(item); } var resource = Fetch(criteria); using (BypassPropertyChecks(item)) { item.ItemId = resource.ItemId; item.Name = resource.Name; item.Type = resource.Type; item.Price = resource.Price; item.CategoryId = resource.CategoryId; item.ProductId = resource.ProductId; item.IsShoppingCart = resource.IsShoppingCart; item.Quantity = resource.Quantity; } CheckRules(item); MarkNew(item); MarkAsChild(item); OnCreated(); return(item); }
protected void DoDelete(ref Cart item) { // If we're not dirty then don't update the database. if (!item.IsDirty) { return; } // If we're new then don't call delete. if (item.IsNew) { return; } var criteria = new CartCriteria { CartId = item.CartId }; DoDelete(criteria); MarkNew(item); }
/// <summary> /// Fetch Cart. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Cart Fetch(CartCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Cart item; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Cart_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; 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.Cart' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }
/// <summary> /// Fetch CartList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CartList Fetch(CartCriteria criteria) { CartList item = (CartList)Activator.CreateInstance(typeof(CartList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Cart_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new CartFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }
/// <summary> /// Fetch CartList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CartList Fetch(CartCriteria criteria) { CartList item = (CartList)Activator.CreateInstance(typeof(CartList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. string commandText = String.Format("SELECT [CartId], [UniqueID], [ItemId], [Name], [Type], [Price], [CategoryId], [ProductId], [IsShoppingCart], [Quantity] FROM [dbo].[Cart] {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 CartFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }
/// <summary> /// Fetch Cart. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Cart Fetch(CartCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Cart item; string commandText = String.Format("SELECT [CartId], [UniqueID], [ItemId], [Name], [Type], [Price], [CategoryId], [ProductId], [IsShoppingCart], [Quantity] FROM [dbo].[Cart] {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.Cart' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Cart"/> object. /// </summary> /// <param name="criteria"><see cref="CartCriteria"/> 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(CartCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when fetching the <see cref="Cart"/> object. /// </summary> /// <param name="criteria"><see cref="CartCriteria"/> 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(CartCriteria criteria, ref bool cancel);
/// <summary> /// This call to delete is for immediate deletion and doesn't keep track of any entity state. /// </summary> /// <param name="criteria">The Criteria.</param> private void DoDelete(CartCriteria 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_Cart_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(); }
protected void DoDelete(ref Cart item) { // If we're not dirty then don't update the database. if (!item.IsDirty) return; // If we're new then don't call delete. if (item.IsNew) return; var criteria = new CartCriteria{CartId = item.CartId}; DoDelete(criteria); MarkNew(item); }
public void Delete(CartCriteria criteria) { //Note: this call to delete is for immediate deletion and doesn't keep track of any entity state. DoDelete(criteria); }
public void Delete(CartCriteria criteria) { //Note: this call to delete is for immediate deletion and doesn't keep track of any entity state. DoDelete(criteria); }
/// <summary> /// CodeSmith generated stub method that is called when fetching the <see cref="Cart"/> object. /// </summary> /// <param name="criteria"><see cref="CartCriteria"/> 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(CartCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Cart"/> object. /// </summary> /// <param name="criteria"><see cref="CartCriteria"/> 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(CartCriteria criteria, ref bool cancel);
/// <summary> /// Fetch Cart. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Cart Fetch(CartCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return null; Cart item; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Cart_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; 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.Cart' using the following criteria: {0}.", criteria)); } } } MarkOld(item); MarkAsChild(item); OnFetched(); return item; }
/// <summary> /// Deletes data in the data base using the criteria specified in the CartCriteria object. /// </summary> /// <param name="criteria">Object of type <see cref="CartCriteria"/></param> /// <returns></returns> protected void DataPortal_Delete(CartCriteria criteria, SqlConnection connection) { bool cancel = false; OnDeleting(criteria, connection, ref cancel); if (cancel) return; var commandText = String.Format("DELETE FROM [dbo].[Cart] {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(); }