/// <summary>
        /// Saves this instance.
        /// </summary>
        /// <param name="entity">The custom field selection to save.</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(UserCustomFieldSelection entity)
        {
            if (entity.Id > Globals.NEW_ID)
                return (DataProviderManager.Provider.UpdateUserCustomFieldSelection(entity));

            var tempId = DataProviderManager.Provider.CreateNewUserCustomFieldSelection(entity);

            if (tempId <= 0)
                return false;

            entity.Id = tempId;
            return true;
        }
        public override bool UpdateUserCustomFieldSelection(UserCustomFieldSelection customFieldSelectionToUpdate)
        {
            if (customFieldSelectionToUpdate == null) throw new ArgumentNullException("customFieldSelectionToUpdate");

            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                AddParamToSqlCmd(sqlCmd, "@CustomFieldId", SqlDbType.Int, 0, ParameterDirection.Input, customFieldSelectionToUpdate.CustomFieldId);
                AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionId", SqlDbType.Int, 0, ParameterDirection.Input, customFieldSelectionToUpdate.Id);
                AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionName", SqlDbType.NVarChar, 255, ParameterDirection.Input, customFieldSelectionToUpdate.Name);
                AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionValue", SqlDbType.NVarChar, 255, ParameterDirection.Input, customFieldSelectionToUpdate.Value);
                AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionSortOrder", SqlDbType.Int, 0, ParameterDirection.Input, customFieldSelectionToUpdate.SortOrder);

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_USERCUSTOMFIELDSELECTION_UPDATE);
                ExecuteScalarCmd(sqlCmd);
                return ((int)sqlCmd.Parameters["@ReturnValue"].Value == 0);
            }
        }
        public override int CreateNewUserCustomFieldSelection(UserCustomFieldSelection newCustomFieldSelection)
        {
            if (newCustomFieldSelection == null) throw new ArgumentNullException("newCustomFieldSelection");

            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                AddParamToSqlCmd(sqlCmd, "@CustomFieldId", SqlDbType.Int, 0, ParameterDirection.Input, newCustomFieldSelection.CustomFieldId);
                AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionName", SqlDbType.NVarChar, 255, ParameterDirection.Input, newCustomFieldSelection.Name);
                AddParamToSqlCmd(sqlCmd, "@CUstomFieldSelectionValue", SqlDbType.NVarChar, 255, ParameterDirection.Input, newCustomFieldSelection.Value);

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_USERCUSTOMFIELDSELECTION_CREATE);
                ExecuteScalarCmd(sqlCmd);
                return ((int)sqlCmd.Parameters["@ReturnValue"].Value);
            }
        }
Exemple #4
0
 public abstract bool UpdateUserCustomFieldSelection(UserCustomFieldSelection customFieldSelectionToUpdate);
Exemple #5
0
 // User Custom Field Selections
 public abstract int CreateNewUserCustomFieldSelection(UserCustomFieldSelection newCustomFieldSelection);
        /// <summary>
        /// Handles the ItemCommand event of the grdSelectionValues control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdSelectionValues_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            UserCustomFieldSelection cfs;
            var itemIndex = e.Item.ItemIndex;
            int itemId;
            var grid = source as DataGrid;

            switch (e.CommandName)
            {
                case "up":
                    //move row up
                    if (itemIndex == 0)
                        return;
                    itemId = Convert.ToInt32(grid.DataKeys[itemIndex]);
                    cfs = UserCustomFieldSelectionManager.GetById(itemId);
                    cfs.SortOrder -= 1;
                    UserCustomFieldSelectionManager.SaveOrUpdate(cfs);
                    break;
                case "down":
                    //move row down
                    if (itemIndex == grid.Items.Count - 1)
                        return;
                    itemId = Convert.ToInt32(grid.DataKeys[itemIndex]);
                    cfs = UserCustomFieldSelectionManager.GetById(itemId);
                    cfs.SortOrder += 1;
                    UserCustomFieldSelectionManager.SaveOrUpdate(cfs);
                    break;
                case "add":
                    if (Page.IsValid)
                    {
                        var txtAddSelectionName = (TextBox)e.Item.FindControl("txtAddSelectionName");
                        var txtAddSelectionValue = (TextBox)e.Item.FindControl("txtAddSelectionValue");

                        cfs = new UserCustomFieldSelection
                        {
                            CustomFieldId = Convert.ToInt32(e.CommandArgument),
                            Name = txtAddSelectionName.Text.Trim(),
                            Value = txtAddSelectionValue.Text.Trim()
                        };

                        UserCustomFieldSelectionManager.SaveOrUpdate(cfs);
                    }
                    break;
            }

            BindCustomFieldSelections();
        }