public virtual GiftCard UpdateGiftCard(GiftCard entity) { if (entity.IsTransient()) { return(entity); } GiftCard other = GetGiftCard(entity.GiftCardId); if (entity.Equals(other)) { return(entity); } string sql = @"Update GiftCard set [GiftCardGUID]=@GiftCardGUID , [SerialNumber]=@SerialNumber , [PurchasedByCustomerID]=@PurchasedByCustomerID , [OrderNumber]=@OrderNumber , [ShoppingCartRecID]=@ShoppingCartRecID , [ProductID]=@ProductID , [VariantID]=@VariantID , [InitialAmount]=@InitialAmount , [Balance]=@Balance , [StartDate]=@StartDate , [ExpirationDate]=@ExpirationDate , [GiftCardTypeID]=@GiftCardTypeID , [EMailName]=@EMailName , [EMailTo]=@EMailTo , [EMailMessage]=@EMailMessage , [ValidForCustomers]=@ValidForCustomers , [ValidForProducts]=@ValidForProducts , [ValidForManufacturers]=@ValidForManufacturers , [ValidForCategories]=@ValidForCategories , [ValidForSections]=@ValidForSections , [DisabledByAdministrator]=@DisabledByAdministrator , [ExtensionData]=@ExtensionData , [CreatedOn]=@CreatedOn where GiftCardID=@GiftCardID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@GiftCardID", entity.GiftCardId) , new SqlParameter("@GiftCardGUID", entity.GiftCardGuid) , new SqlParameter("@SerialNumber", entity.SerialNumber ?? (object)DBNull.Value) , new SqlParameter("@PurchasedByCustomerID", entity.PurchasedByCustomerId) , new SqlParameter("@OrderNumber", entity.OrderNumber) , new SqlParameter("@ShoppingCartRecID", entity.ShoppingCartRecId) , new SqlParameter("@ProductID", entity.ProductId) , new SqlParameter("@VariantID", entity.VariantId) , new SqlParameter("@InitialAmount", entity.InitialAmount) , new SqlParameter("@Balance", entity.Balance) , new SqlParameter("@StartDate", entity.StartDate) , new SqlParameter("@ExpirationDate", entity.ExpirationDate) , new SqlParameter("@GiftCardTypeID", entity.GiftCardTypeId ?? (object)DBNull.Value) , new SqlParameter("@EMailName", entity.EmailName ?? (object)DBNull.Value) , new SqlParameter("@EMailTo", entity.EmailTo ?? (object)DBNull.Value) , new SqlParameter("@EMailMessage", entity.EmailMessage ?? (object)DBNull.Value) , new SqlParameter("@ValidForCustomers", entity.ValidForCustomers ?? (object)DBNull.Value) , new SqlParameter("@ValidForProducts", entity.ValidForProducts ?? (object)DBNull.Value) , new SqlParameter("@ValidForManufacturers", entity.ValidForManufacturers ?? (object)DBNull.Value) , new SqlParameter("@ValidForCategories", entity.ValidForCategories ?? (object)DBNull.Value) , new SqlParameter("@ValidForSections", entity.ValidForSections ?? (object)DBNull.Value) , new SqlParameter("@DisabledByAdministrator", entity.DisabledByAdministrator) , new SqlParameter("@ExtensionData", entity.ExtensionData ?? (object)DBNull.Value) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetGiftCard(entity.GiftCardId)); }
public virtual GiftCard InsertGiftCard(GiftCard entity) { GiftCard other = new GiftCard(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into GiftCard ( [GiftCardGUID] ,[SerialNumber] ,[PurchasedByCustomerID] ,[OrderNumber] ,[ShoppingCartRecID] ,[ProductID] ,[VariantID] ,[InitialAmount] ,[Balance] ,[StartDate] ,[ExpirationDate] ,[GiftCardTypeID] ,[EMailName] ,[EMailTo] ,[EMailMessage] ,[ValidForCustomers] ,[ValidForProducts] ,[ValidForManufacturers] ,[ValidForCategories] ,[ValidForSections] ,[DisabledByAdministrator] ,[ExtensionData] ,[CreatedOn] ) Values ( @GiftCardGUID , @SerialNumber , @PurchasedByCustomerID , @OrderNumber , @ShoppingCartRecID , @ProductID , @VariantID , @InitialAmount , @Balance , @StartDate , @ExpirationDate , @GiftCardTypeID , @EMailName , @EMailTo , @EMailMessage , @ValidForCustomers , @ValidForProducts , @ValidForManufacturers , @ValidForCategories , @ValidForSections , @DisabledByAdministrator , @ExtensionData , @CreatedOn ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@GiftCardID", entity.GiftCardId) , new SqlParameter("@GiftCardGUID", entity.GiftCardGuid) , new SqlParameter("@SerialNumber", entity.SerialNumber ?? (object)DBNull.Value) , new SqlParameter("@PurchasedByCustomerID", entity.PurchasedByCustomerId) , new SqlParameter("@OrderNumber", entity.OrderNumber) , new SqlParameter("@ShoppingCartRecID", entity.ShoppingCartRecId) , new SqlParameter("@ProductID", entity.ProductId) , new SqlParameter("@VariantID", entity.VariantId) , new SqlParameter("@InitialAmount", entity.InitialAmount) , new SqlParameter("@Balance", entity.Balance) , new SqlParameter("@StartDate", entity.StartDate) , new SqlParameter("@ExpirationDate", entity.ExpirationDate) , new SqlParameter("@GiftCardTypeID", entity.GiftCardTypeId ?? (object)DBNull.Value) , new SqlParameter("@EMailName", entity.EmailName ?? (object)DBNull.Value) , new SqlParameter("@EMailTo", entity.EmailTo ?? (object)DBNull.Value) , new SqlParameter("@EMailMessage", entity.EmailMessage ?? (object)DBNull.Value) , new SqlParameter("@ValidForCustomers", entity.ValidForCustomers ?? (object)DBNull.Value) , new SqlParameter("@ValidForProducts", entity.ValidForProducts ?? (object)DBNull.Value) , new SqlParameter("@ValidForManufacturers", entity.ValidForManufacturers ?? (object)DBNull.Value) , new SqlParameter("@ValidForCategories", entity.ValidForCategories ?? (object)DBNull.Value) , new SqlParameter("@ValidForSections", entity.ValidForSections ?? (object)DBNull.Value) , new SqlParameter("@DisabledByAdministrator", entity.DisabledByAdministrator) , new SqlParameter("@ExtensionData", entity.ExtensionData ?? (object)DBNull.Value) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray); if (identity == DBNull.Value) { throw new DataException("Identity column was null as a result of the insert operation."); } return(GetGiftCard(Convert.ToInt32(identity))); } return(entity); }