public ActionResult Navigation(int?id = null)
        {
            IList <Prompt>   _promptlist   = _prompt.GetCategoryItemsByID(UserID, id);
            IList <Category> _categorylist = _getcategory.GetCategories(id);
            int?previousList = null;

            try
            {
                previousList = _categorylist[0].ParentCategory.ParentCategory.ID;
            }
            catch
            { }
            ModelCategoriesWithPrompts modelCategoriesWithPrompts = new ModelCategoriesWithPrompts();

            if (_categorylist.Count != 0)
            {
                modelCategoriesWithPrompts.CategoryList   = _categorylist;
                modelCategoriesWithPrompts.PromptList     = _promptlist;
                modelCategoriesWithPrompts.previousListID = previousList;
            }
            else
            {
                return(RedirectToAction("HttpError404", "Error"));
            }
            return(View(modelCategoriesWithPrompts));
        }
        /// <summary>
        /// Get the sumary of the selected category/
        /// </summary>
        /// <param name="category"></param>
        /// <returns>String the sumary code for the selected category</returns>
        private string GetSummary(int category)
        {
            var categories = _categories?.GetCategories() ?? new Dictionary <int, string>();

            if (!categories.Any())
            {
                return(GetParagraph("Summary", "No categories listed!"));
            }

            if (!categories.ContainsKey(category))
            {
                return(GetParagraph("Summary", $"Could not find a valid category."));
            }

            var cr = $"cr{category}";

            return(GetParagraph("Summary", $"Selected category <span class='{cr}'>{categories[category]}({category})</span>"));
        }
        public IActionResult GetCategories()
        {
            try
            {
                var resp = _mapper.Map <List <CategoriesDTO> >(_categoryServices.GetCategories());

                if (resp == null)
                {
                    return(NotFound(resp));
                }

                return(Ok(resp));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message }));
            }
        }
Beispiel #4
0
 public async Task <IEnumerable <Categories> > GetCategories()
 {
     return(await icategories.GetCategories());
 }
 public IEnumerable <Category> Get()
 {
     return(_categoriesRepository.GetCategories());
 }
Beispiel #6
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();
        }