public ActionResult Create(CategoriesCreateViewModel model) { try { if (ModelState.IsValid) { // TODO: Add insert logic here CategoriesHelper categoryHelper = new CategoriesHelper(); if (!categoryHelper.Exits(model.Name)) { Category category = new Category() { Name = model.Name.Trim() }; categoryHelper.Add(category); } else { //TODO: Look the alerts } return RedirectToAction("Index"); } return View(model); } catch { return View(); } }
/// <summary> /// Fill dropdown lists /// </summary> private void FillForm() { ViewComboBox.Items.Add(new RadComboBoxItem(LocalizeString("NoneSelectedText"), string.Empty)); ViewComboBox.AppendDataBoundItems = true; ViewComboBox.DataSource = DnnPathHelper.GetViewNames("Category"); ViewComboBox.DataBind(); var allCats = HccApp.CatalogServices.Categories.FindAllSnapshotsPaged(1, 5000); var categories = CategoriesHelper.ListFullTreeWithIndentsForComboBox(allCats, false); CategoryComboBox.Items.Add(new RadComboBoxItem(LocalizeString("NoneSelectedText"), string.Empty)); CategoryComboBox.AppendDataBoundItems = true; CategoryComboBox.DataSource = categories; CategoryComboBox.DataTextField = "Text"; CategoryComboBox.DataValueField = "Value"; CategoryComboBox.DataBind(); var columns = HccApp.ContentServices.Columns.FindAll(); FillComboBox(ddlPreContentColumnId, columns, "DisplayName", "Bvin", Convert.ToString(ModuleSettings["DefaultPreContentColumnId"])); FillComboBox(ddlPostContentColumnId, columns, "DisplayName", "Bvin", Convert.ToString(ModuleSettings["DefaultPostContentColumnId"])); FillSortingCheckboxList(); }
public override void LoadQualification() { var allCats = HccApp.CatalogServices.Categories.FindAll(); var available = CategoriesHelper.ListFullTreeWithIndents(allCats, true); var displayData = new List <FriendlyBvinDisplay>(); foreach (var bvin in TypedQualification.CurrentCategoryIds()) { var item = new FriendlyBvinDisplay(); item.bvin = bvin; item.DisplayName = bvin; var t = available.FirstOrDefault(y => y.Value == bvin); if (t != null) { item.DisplayName = t.Text; available.Remove(t); } displayData.Add(item); } lstProductCategories.Items.Clear(); foreach (var li in available) { lstProductCategories.Items.Add(li); } gvProductCategories.DataSource = displayData; gvProductCategories.DataBind(); }
private void PopulateCategories(string currentBvin = null) { // get a collection of categories to bind to the DLL (filtered to not allow assignment to children of current parent) var categories = HccApp.CatalogServices.Categories.FindAllSnapshotsPaged(1, int.MaxValue) .Where(x => currentBvin == null || x.ParentId != currentBvin) .ToList(); var parents = CategoriesHelper.ListFullTreeWithIndents(categories, true); ParentCategoryDropDownList.Items.Clear(); // iterate through each category and add to the DDL foreach (var category in parents) { // update the category name if it's empty category.Text = Regex.IsMatch(category.Text, EMPTY_CATEGORY_PATTERN) ? string.Concat(category.Text, NO_NAME_TEXT) : category.Text; // let the merchant know visually that this is the current category they're editing if (category.Value == currentBvin) { // change the name to reflect this category.Text = string.Concat(CURRENT_CATEGORY_TEXT, category.Text); } // create a new DLL item ParentCategoryDropDownList.Items.Add(category); } // add a default option for making the category a top-level category ParentCategoryDropDownList.Items.Insert(0, new ListItem(TOP_LEVEL_CATEGORY_TEXT, string.Empty)); }
private void PopulateCategories() { var tree = CategoriesHelper.ListFullTreeWithIndents(HccApp.CatalogServices.Categories); CategoryFilter.Items.Clear(); foreach (var li in tree) { CategoryFilter.Items.Add(li); } CategoryFilter.Items.Insert(0, new ListItem("- Any Category -", string.Empty)); }
// GET: Categories/Details/5 public ActionResult Details(int id) { CategoriesHelper categoryHelper = new CategoriesHelper(); Category category = categoryHelper.FindById(id); CategoriesEditViewModel model = new CategoriesEditViewModel() { Name = category.Name }; return View(model); }
private void PopulateCategories() { var tree = CategoriesHelper.ListFullTreeWithIndents(HccApp.CatalogServices.Categories); ddlCategoryFilter.Items.Clear(); foreach (var li in tree) { var item = new RadComboBoxItem(li.Text, li.Value); ddlCategoryFilter.Items.Add(item); } ddlCategoryFilter.Items.Insert(0, new RadComboBoxItem(Localization.GetString("AnyCategory"), string.Empty)); }
public ActionResult GetCategories() { try { var categoriesList = new CategoriesHelper().GetCategoriesList(); return(Json(categoriesList, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(false, JsonRequestBehavior.AllowGet)); } }
// GET: Categories/Edit/5 public ActionResult Edit(int id) { if (id > 0) { CategoriesHelper categoryHelper = new CategoriesHelper(); Category category = categoryHelper.FindById(id); CategoriesEditViewModel model = new CategoriesEditViewModel() { Id = id, Name = category.Name }; return View(model); } return RedirectToAction("Index"); }
private void RenderCategoryTree() { var sb = new StringBuilder(); var allCats = HccApp.CatalogServices.Categories.FindAllSnapshotsPaged(1, 5000); lstParents.Items.Clear(); lstParents.Items.Add(new RadComboBoxItem("(Root)", string.Empty)); var parents = CategoriesHelper.ListFullTreeWithIndents(allCats, true); foreach (var li in parents) { lstParents.Items.Add(new RadComboBoxItem(li.Text, li.Value)); } RenderChildren(string.Empty, allCats, sb); litMain.Text = sb.ToString(); }
private async void ReloadData() { _userRepository = new UserRepository(); var userId = Domain.Constants.Constants.TestUserId; var user = await _userRepository.GetById(userId); textBox1.Text = user.Card.FormatMoney(); textBox2.Text = user.Cash.FormatMoney(); categoriesList.Items.Clear(); var categoriesHelper = new CategoriesHelper(new CategoriesRepository()); var categories = await categoriesHelper .GetUserCategories(Domain.Constants.Constants.TestUserId); foreach (var category in categories) { var item = new ListViewItem(category.Id.ToString()); item.SubItems.Add(category.Name); categoriesList.Items.Add(item); } }
public override void LoadQualification() { if (ddlCalcMode.Items.Count == 0) { ddlCalcMode.Items.Add(new ListItem(Localization.GetString("TotalPrice"), "0")); ddlCalcMode.Items.Add(new ListItem(Localization.GetString("TotalCount"), "1")); } var allCats = HccApp.CatalogServices.Categories.FindAll(); var available = CategoriesHelper.ListFullTreeWithIndents(allCats, true); var displayData = new List <FriendlyBvinDisplay>(); foreach (var bvin in TypedQualification.CategoryIds()) { var item = new FriendlyBvinDisplay(); item.bvin = bvin; item.DisplayName = bvin; var t = available.FirstOrDefault(y => y.Value == bvin); if (t != null) { item.DisplayName = t.Text; available.Remove(t); } displayData.Add(item); } lstLineItemCategories.Items.Clear(); foreach (var li in available) { lstLineItemCategories.Items.Add(li); } ddlCalcMode.SelectedValue = ((int)TypedQualification.CalculationMode).ToString(); txtSumOrCount.Text = TypedQualification.SumAmount.ToString(); gvLineItemCategories.DataSource = displayData; gvLineItemCategories.DataBind(); }
private async void createCategory_Click(object sender, System.EventArgs e) { if (string.IsNullOrEmpty(newCategoryInput.Text)) { warningLabel.Text = "Input Field cannot be empty"; } else { var helper = new CategoriesHelper(new CategoriesRepository()); var newCategory = new Category { Name = newCategoryInput.Text, UserId = Domain.Constants.Constants.TestUserId }; await helper.AddNewCategory(newCategory); newCategoryInput.Text = string.Empty; warningLabel.Text = string.Empty; ReloadData(); } }
private void LoadCategories() { chkCategories.Items.Clear(); var t = HccApp.CatalogServices.FindCategoriesForProduct(Request.QueryString["ID"]); var tree = CategoriesHelper.ListFullTreeWithIndents(HccApp.CatalogServices.Categories, true); foreach (var li in tree) { chkCategories.Items.Add(li); } foreach (var ca in t) { foreach (ListItem l in chkCategories.Items) { if (l.Value == ca.Bvin) { l.Selected = true; } } } }
// GET: Categories public ActionResult Index() { CategoriesHelper categoryHelper = new CategoriesHelper(); List<CategoriesIndexModel> model = categoryHelper.GetData().Select(x => new CategoriesIndexModel() { Id = x.Id, Name = x.Name }).ToList(); return View(model); }
public void BindCategories() { CategoriesGridView.DataSource = CategoriesHelper.ListFullTreeWithIndents(HccApp.CatalogServices.Categories); CategoriesGridView.DataKeyNames = new[] { "value" }; CategoriesGridView.DataBind(); }
public CategoryTreeViewModel Execute(Guid categoryTreeId) { if (categoryTreeId.HasDefaultValue()) { var categorizableItems = Repository.AsQueryable <CategorizableItem>().ToList(); return(new CategoryTreeViewModel() { ShowMacros = CmsConfiguration.EnableMacros, CategorizableItems = categorizableItems .Select(i => new CategorizableItemViewModel { Id = i.Id, Name = i.Name, IsSelected = true }) .OrderBy(i => i.Name) .ToList() }); } var categorizableItemsFuture = Repository.AsQueryable <CategorizableItem>().ToFuture(); var selectedCategorizableItemsFuture = Repository.AsQueryable <CategoryTreeCategorizableItem>() .Where(i => i.CategoryTree.Id == categoryTreeId) .ToFuture(); IQueryable <CategoryTree> sitemapQuery = Repository.AsQueryable <CategoryTree>() .Where(map => map.Id == categoryTreeId) .FetchMany(map => map.Categories); var categoryTree = sitemapQuery.Distinct().ToFuture().ToList().First(); var selectedItems = selectedCategorizableItemsFuture.ToList(); var model = new CategoryTreeViewModel { Id = categoryTree.Id, Version = categoryTree.Version, Title = categoryTree.Title, Macro = categoryTree.Macro, RootNodes = CategoriesHelper.GetCategoryTreeNodesInHierarchy( CmsConfiguration.EnableMultilanguage, categoryTree.Categories.Distinct().Where(f => f.ParentCategory == null).ToList(), categoryTree.Categories.Distinct().ToList(), null), ShowMacros = CmsConfiguration.EnableMacros // CategorizableItems = categorizableItemsFuture.ToList() // .Select(i => new CategorizableItemViewModel { Id = i.Id, Name = i.Name, IsSelected = selectedItems.Any(s => s.CategorizableItem.Id == i.Id) }) // .OrderBy(i => i.Name) // .ToList() }; model.CategorizableItems = categorizableItemsFuture.ToList() .Select(i => new CategorizableItemViewModel { Id = i.Id, Name = i.Name, IsSelected = selectedItems.Any(s => s.CategorizableItem.Id == i.Id), }) .OrderBy(i => i.Name) .ToList(); Dictionary <string, IFutureValue <int> > countFutures = new Dictionary <string, IFutureValue <int> >(); // Collect futures foreach (var categorizableItem in model.CategorizableItems) { var name = categorizableItem.Name; var accessor = CategoryAccessors.Accessors.First(ca => ca.Name == name); countFutures.Add(name, accessor.CheckIsUsed(repository, categoryTree)); } // Evaluate futures foreach (var countFuture in countFutures) { var name = countFuture.Key; var categorizableItem = model.CategorizableItems.First(c => c.Name == name); categorizableItem.IsDisabled = categorizableItem.IsSelected && countFuture.Value.Value > 0; } return(model); }
//// GET: Categories/Delete/5 //public ActionResult Delete(int id) //{ // return View(); //} //// POST: Categories/Delete/5 //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Delete(int id, FormCollection collection) //{ // try // { // // TODO: Add delete logic here // return RedirectToAction("Index"); // } // catch // { // return View(); // } //} private List<SelectListItem> GetCategoriesSelectedItems() { var category = new CategoriesHelper(); var lst = category.GetListItem(); return lst.Select(x => new SelectListItem() { Value = x.Value, Text = x.Text }).ToList(); }
public ActionResult Edit(int id, CategoriesEditViewModel model) { try { // TODO: Add update logic here if (ModelState.IsValid) { CategoriesHelper categoryHelper = new CategoriesHelper(); Category category = categoryHelper.FindById(id); category.Name = model.Name.Trim(); categoryHelper.Update(category); return RedirectToAction("Index"); } return View(model); } catch { return View(); } }