public bool AddCMSCategory(CMSCategoryView categoryView) { try { using (var db = new OnlineStoreMVCEntities()) { var category = new cms_Categories { ParentId = categoryView.ParentId, Title = categoryView.Title, Description = categoryView.Description, Url = categoryView.Url, SortOrder = categoryView.SortOrder, Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Active, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; db.cms_Categories.Add(category); db.SaveChanges(); return true; } } catch (Exception ex) { throw ex; } }
public static IList <CMSCategoryView> GetCategoryBreadCrumb(CMSCategoryView category, IList <CMSCategoryView> allCategories) { if (category == null) { throw new ArgumentNullException("category"); } var result = new List <CMSCategoryView>(); //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 ActionResult Create(CMSCategoryView model) { if (ModelState.IsValid) { try { if (User.IsInRole("Administrator")) { model.Status = (int)Define.Status.Active; } else { model.Status = (int)Define.Status.WaitingCreate; } model.CreatedBy = User.Identity.GetUserName(); _cmsCategoryService.AddCMSCategory(model); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } ViewBag.AvailableCategories = PrepareAllCategoriesModel(); return(View(model)); }
public bool EditCMSCategory(CMSCategoryView categoryView) { try { if (categoryView.ParentId == null) { categoryView.ParentId = 0; } using (var db = new OnlineStoreMVCEntities()) { var category = db.cms_Categories.Find(categoryView.Id); category.ParentId = categoryView.ParentId; category.Title = categoryView.Title; category.Description = categoryView.Description; category.Url = categoryView.Url; category.SortOrder = categoryView.SortOrder; category.Status = categoryView.Status; category.ModifiedDate = DateTime.Now; db.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public bool AddCMSCategory(CMSCategoryView categoryView) { try { if (categoryView.ParentId == null) { categoryView.ParentId = 0; } using (var db = new OnlineStoreMVCEntities()) { var category = new cms_Categories { ParentId = categoryView.ParentId, Title = categoryView.Title, Description = categoryView.Description, Url = categoryView.Url, SortOrder = categoryView.SortOrder, Status = categoryView.Status, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, CreateByTy = categoryView.CreatedBy, }; db.cms_Categories.Add(category); db.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public static string GetFormattedBreadCrumb(CMSCategoryView 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(CMSCategoryView 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(CMSCategoryView model) { if (ModelState.IsValid) { try { _cmsCategoryService.EditCMSCategory(model); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } ViewBag.AvailableCategories = PrepareAllCategoriesModel(model.Id); PopulateStatusDropDownList((Portal.Infractructure.Utility.Define.Status)model.Status); return(View(model)); }
public static IList <CMSCategoryView> GetCategoryBreadCrumb(CMSCategoryView category, ICMSCategoryService categoryService) { if (category == null) { throw new ArgumentNullException("category"); } var result = new List <CMSCategoryView>(); //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.GetCategoryById(category.ParentId); } result.Reverse(); return(result); }