示例#1
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("HttpError404", "Error"));
            }
            var category = _categoriesStorage.GetCategory((int)id);

            if (category != null)
            {
                return(View(category));
            }
            else
            {
                return(RedirectToAction("HttpError404", "Error"));
            }
        }
示例#2
0
        private void Apply_Click(object sender, EventArgs e)
        {
            var allCategories = _categories.GetCategories();

            // get the text and clean it up
            var text = textName.Text;

            text = text.Trim();

            // is it empty?
            if (text.Length == 0)
            {
                MessageBox.Show("The category name cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // does it already exist?
            var item = allCategories.Where(c => string.Equals(c.Value, text, StringComparison.CurrentCultureIgnoreCase))
                       .Select(f => new { Key = f.Key, Value = f.Value })
                       .FirstOrDefault();

            if (item != null)
            {
                if (GivenCategory == null          // Given category is null, no we are trying to create a duplicate.
                    ||
                    (item.Key != GivenCategory.Id) // the new string matches an existing string.
                    )
                {
                    MessageBox.Show("The category name given already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // Get the selected folder id.
            // We want to allow the user to select nothing, maybe they just want to
            // classify the post and do nothing else with it.
            var folderId = GetSelectedFolderId();

            // did we change anything at all?
            if (GivenCategory != null && GivenCategory == new Category(text, GivenCategory.Id, folderId))
            {
                //  just ignore this.
                DialogResult = DialogResult.Ignore;
                Close();
                return;
            }

            //  we are updating a value
            if (GivenCategory != null)
            {
                //  change the name of the category.
                _categories.RenameCategory(GivenCategory.Name, text);
            }
            else
            {
                // add the category
                _categories.GetCategory(text);
            }

            // save the id of the folder.
            _config.SetConfig(Categories.GetConfigName(text), folderId);

            // and we are dome
            DialogResult = DialogResult.OK;
            Close();
        }