protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess) return;

            if (txtName.Text.Trim().Length == 0)
            {
                MessageBox.Show(Lang.TransA("Please enter category name!"), Misc.MessageType.Error);
                return;
            }

            Category category = null;

            if (EditedCategory == null)
            {
                category = new Category();
            }
            else
            {
                category = EditedCategory;
            }

            category.Name = txtName.Text.Trim();
            category.UsersCanCreateGroups = cbUsersCanCreateGroups.Checked;
            category.Save();

            populateDataGrid();

            mvCategories.SetActiveView(viewCategories);
        }
Example #2
0
        /// <summary>
        /// Fetches all categories from DB by group ID.
        /// If there are no categories in DB for specified group ID it returns an empty array.
        /// </summary>
        /// <param name="groupID">The group ID.</param>
        /// <returns>Category array or an emptry array if there are no categories in DB for specified group ID.</returns>
        public static Category[] FetchCategoriesByGroup(int groupID)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchCategoriesByGroup", groupID);

                List<Category> categories = new List<Category>();

                while (reader.Read())
                {
                    Category category = new Category();

                    category.id = (int)reader["ID"];
                    category.name = (string)reader["Name"];
                    category.order = (int)reader["Order"];
                    category.usersCanCreateGroups = (bool)reader["UsersCanCreateGroups"];

                    categories.Add(category);
                }

                return categories.ToArray();
            }
        }