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); }
//Associations.Where(a => a.AssociationType == AssociationType.ManyToOne || a.AssociationType == AssociationType.ManyToZeroOrOne) private static void Update_Profile_Profile_FK_Cart_Profiles(ref Cart item) { item.Profile.UniqueID = item.UniqueID; new ProfileFactory().Update(item.Profile, true); }
private void DoUpdate(ref Cart item, bool stopProccessingChildren) { bool cancel = false; OnUpdating(ref cancel); if (cancel) return; // Don't update if the item isn't dirty. if (item.IsDirty) { using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand("[dbo].[CSLA_Cart_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_CartId", item.CartId); command.Parameters["@p_CartId"].Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@p_UniqueID", item.UniqueID); command.Parameters.AddWithValue("@p_ItemId", item.ItemId); command.Parameters.AddWithValue("@p_Name", item.Name); command.Parameters.AddWithValue("@p_Type", item.Type); command.Parameters.AddWithValue("@p_Price", item.Price); command.Parameters.AddWithValue("@p_CategoryId", item.CategoryId); command.Parameters.AddWithValue("@p_ProductId", item.ProductId); command.Parameters.AddWithValue("@p_IsShoppingCart", item.IsShoppingCart); command.Parameters.AddWithValue("@p_Quantity", item.Quantity); //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."); item.CartId = (System.Int32)command.Parameters["@p_CartId"].Value; } } } MarkOld(item); CheckRules(item); if(!stopProccessingChildren) { // Update Child Items. Update_Profile_Profile_FK_Cart_Profiles(ref item); } OnUpdated(); }
public Cart Update(Cart item, bool stopProccessingChildren) { if(item.IsDeleted) { DoDelete(ref item); MarkNew(item); } else if(item.IsNew) { DoInsert(ref item, stopProccessingChildren); } else { DoUpdate(ref item, stopProccessingChildren); } return item; }
public Cart Update(Cart item) { return Update(item, false); }
private void DoInsert(ref Cart item, bool stopProccessingChildren) { // Don't update if the item isn't dirty. if (!item.IsDirty) return; bool cancel = false; OnInserting(ref cancel); if (cancel) return; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand("[dbo].[CSLA_Cart_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_CartId", item.CartId); command.Parameters["@p_CartId"].Direction = ParameterDirection.Output; command.Parameters.AddWithValue("@p_UniqueID", item.UniqueID); command.Parameters.AddWithValue("@p_ItemId", item.ItemId); command.Parameters.AddWithValue("@p_Name", item.Name); command.Parameters.AddWithValue("@p_Type", item.Type); command.Parameters.AddWithValue("@p_Price", item.Price); command.Parameters.AddWithValue("@p_CategoryId", item.CategoryId); command.Parameters.AddWithValue("@p_ProductId", item.ProductId); command.Parameters.AddWithValue("@p_IsShoppingCart", item.IsShoppingCart); command.Parameters.AddWithValue("@p_Quantity", item.Quantity); command.ExecuteNonQuery(); item.CartId = (System.Int32)command.Parameters["@p_CartId"].Value; } } MarkOld(item); CheckRules(item); if(!stopProccessingChildren) { // Update Child Items. Update_Profile_Profile_FK_Cart_Profiles(ref item); } OnInserted(); }
partial void OnAddNewCore(ref Cart item, ref bool cancel);