public bool EditCMSCategory(CMSCategoryViewModel viewModel) { try { var category = _cmsCategoryRepository.Find(viewModel.Id); if (category != null) { category.ParentId = viewModel.ParentId; category.Title = viewModel.Title; category.Description = viewModel.Description; category.Url = viewModel.Url; category.SortOrder = viewModel.SortOrder; category.Status = viewModel.Status; category.ModifiedDate = DateTime.Now; _cmsCategoryRepository.Save(); return(true); } return(false); } catch (Exception ex) { throw ex; } }
public static IList <CMSCategoryViewModel> GetCategoryBreadCrumb(CMSCategoryViewModel category, IList <CMSCategoryViewModel> allCategories) { if (category == null) { throw new ArgumentNullException("category"); } var result = new List <CMSCategoryViewModel>(); //used to prevent circular references var alreadyProcessedCategoryIds = new List <int>(); while (category != null && //not null !alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references { result.Add(category); alreadyProcessedCategoryIds.Add(category.Id); category = (from c in allCategories where c.Id == category.ParentId select c).FirstOrDefault(); } result.Reverse(); return(result); }
public static cms_Categories ConvertCMSCategoryViewModelToCMSCategory(CMSCategoryViewModel viewModel) { return(new cms_Categories { ParentId = viewModel.ParentId, Title = viewModel.Title, Description = viewModel.Description, Url = viewModel.Url, SortOrder = viewModel.SortOrder, Status = (int)Define.Status.Active, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }); }
public bool AddCMSCategory(CMSCategoryViewModel viewModel) { try { var category = CMSCategoryMapper.ConvertCMSCategoryViewModelToCMSCategory(viewModel); _cmsCategoryRepository.Add(category); _cmsCategoryRepository.Save(); return(true); } catch (Exception ex) { throw ex; } }
public static string GetFormattedBreadCrumb(CMSCategoryViewModel category, ICMSCategoryService categoryService, string separator = ">>") { string result = string.Empty; var breadcrumb = GetCategoryBreadCrumb(category, categoryService); for (int i = 0; i <= breadcrumb.Count - 1; i++) { var categoryName = breadcrumb[i].Title; result = String.IsNullOrEmpty(result) ? categoryName : string.Format("{0} {1} {2}", result, separator, categoryName); } return(result); }
public ActionResult Create(CMSCategoryViewModel model) { if (ModelState.IsValid) { try { _cmsCategoryService.AddCMSCategory(model); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } ViewBag.AvailableCategories = PrepareAllCategoriesModel(); return(View(model)); }
public ActionResult Edit(CMSCategoryViewModel model) { if (ModelState.IsValid) { try { _cmsCategoryService.EditCMSCategory(model); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } ViewBag.AvailableCategories = PrepareAllCategoriesModel(model.Id); PopulateStatusDropDownList((Define.Status)model.Status); return(View(model)); }
public static IList <CMSCategoryViewModel> GetCategoryBreadCrumb(CMSCategoryViewModel category, ICMSCategoryService categoryService) { if (category == null) { throw new ArgumentNullException("category"); } var result = new List <CMSCategoryViewModel>(); //used to prevent circular references var alreadyProcessedCategoryIds = new List <int>(); while (category != null && //not null !alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references { result.Add(category); alreadyProcessedCategoryIds.Add(category.Id); category = categoryService.GetCMSCategoryById(category.ParentId); } result.Reverse(); return(result); }