public ActionResult Edit(int id = 0) { var item = InfrastructureCategoryDbContext.getInstance().findCategoryByID(id); ViewBag.parentItemID = getParentItemsForSelect(item.parentItemID, item.ItemID); return(View(item)); }
public ActionResult List(int?parentItemID = null) { if (parentItemID != null) { var rootItem = InfrastructureCategoryDbContext.getInstance().findCategoryByID(parentItemID); if (rootItem != null) { ViewBag.subcategory = rootItem; if (rootItem.parentItem != null && rootItem.parentItem.ItemID > 0) { ViewBag.parentItemName = rootItem.parentItem.name_en; ViewBag.parentItemID = rootItem.parentItem.ItemID; } } } if (TempData["Message"] != null) { ViewBag.Message = TempData["Message"]; } if (TempData["ErrorMessage"] != null) { ViewBag.ErrorMessage = TempData["ErrorMessage"]; } var items = InfrastructureCategoryDbContext.getInstance().findCategorysByParentID(parentItemID); return(View(items)); }
MultiSelectList getAccessibleCategories(string selectedIDs = null) { var parentItemsForSelect = InfrastructureCategoryDbContext.getInstance().findCategorysInTreeExcept(0, null); parentItemsForSelect.Insert(0, new Category { ItemID = -1, url = "" }); foreach (var cat in parentItemsForSelect) { for (int i = 0; i < cat.itemLevel; i++) { cat.url = " > " + cat.url; } } List <int> ids = new List <int>(); if (selectedIDs != null) { var selIDs = selectedIDs.Split(','); for (int i = 0; i < selIDs.Count(); i++) { var id = selIDs.ElementAt(i); if (!id.Equals("")) { ids.Add(Convert.ToInt32(selIDs.ElementAt(i))); } } } return(new MultiSelectList(parentItemsForSelect, "ItemID", "url", ids.ToArray())); }
SelectList getCategoriesForSelect(int?selectedID = null) { var items = InfrastructureCategoryDbContext.getInstance().findAllCategorysContentPagesAsNoTracking(); items.Insert(0, new Models.Infrastructure.Category { ItemID = -1, name_en = "" }); return(new SelectList(items, "ItemID", "name_en", selectedID)); }
public ActionResult Create( Category item, HttpPostedFileBase icon, HttpPostedFileBase thumb, HttpPostedFileBase image) { if (ModelState.IsValid) { if (icon != null) { string ImageName = Path.GetFileName(icon.FileName); string[] FileNames = ImageName.Split('\\'); string FileName = FileNames[FileNames.Length - 1]; string path = System.IO.Path.Combine(Server.MapPath("~" + Settings.Default.MS_IMAGE_UPLOAD_SRC), FileName); icon.SaveAs(path); item.iconPath = FileName; } if (thumb != null) { string ImageName = Path.GetFileName(thumb.FileName); string[] FileNames = ImageName.Split('\\'); string FileName = FileNames[FileNames.Length - 1]; string path = System.IO.Path.Combine(Server.MapPath("~" + Settings.Default.MS_IMAGE_UPLOAD_SRC), FileName); thumb.SaveAs(path); item.thumbPath = FileName; } if (image != null) { string ImageName = Path.GetFileName(image.FileName); string[] FileNames = ImageName.Split('\\'); string FileName = FileNames[FileNames.Length - 1]; string path = System.IO.Path.Combine(Server.MapPath("~" + Settings.Default.MS_IMAGE_UPLOAD_SRC), FileName); image.SaveAs(path); item.imagePath = FileName; } InfrastructureCategoryDbContext.getInstance().create(item); ModelState.Clear(); ViewBag.Message = item.GetName() + " successfully created."; } else { ViewBag.parentItemID = getParentItemsForSelect(); return(View()); } TempData["Message"] = "'" + item.GetName() + "' successfully created."; if (item.parentItemID == null) { return(RedirectToAction("List")); } else { return(RedirectToAction("List", new { parentItemID = item.parentItemID })); } }
public ActionResult Delete(int id = 0) { var item = InfrastructureCategoryDbContext.getInstance().findCategoryByID(id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
public ActionResult Edit( Category item, HttpPostedFileBase icon, HttpPostedFileBase thumb, HttpPostedFileBase image) { if (ModelState.IsValid) { if (icon != null) { string ImageName = Path.GetFileName(icon.FileName); string[] FileNames = ImageName.Split('\\'); string FileName = FileNames[FileNames.Length - 1]; string path = System.IO.Path.Combine(Server.MapPath("~" + Settings.Default.MS_IMAGE_UPLOAD_SRC), FileName); icon.SaveAs(path); item.iconPath = FileName; } if (thumb != null) { string ImageName = Path.GetFileName(thumb.FileName); string[] FileNames = ImageName.Split('\\'); string FileName = FileNames[FileNames.Length - 1]; string path = System.IO.Path.Combine(Server.MapPath("~" + Settings.Default.MS_IMAGE_UPLOAD_SRC), FileName); thumb.SaveAs(path); item.thumbPath = FileName; } if (image != null) { string ImageName = Path.GetFileName(image.FileName); string[] FileNames = ImageName.Split('\\'); string FileName = FileNames[FileNames.Length - 1]; string path = System.IO.Path.Combine(Server.MapPath("~" + Settings.Default.MS_IMAGE_UPLOAD_SRC), FileName); image.SaveAs(path); item.imagePath = FileName; } ViewBag.Message = "Edit '" + item.GetName() + "' successfully"; InfrastructureCategoryDbContext.getInstance().edit(item); ModelState.Clear(); ViewBag.parentItemID = getParentItemsForSelect(item.parentItemID, item.ItemID); return(View(item)); } else { ViewBag.parentItemID = getParentItemsForSelect(item.parentItemID, item.ItemID); return(View(item)); } }
SelectList getCategoriesForSelect(int?selectedID = null) { var items = InfrastructureCategoryDbContext.getInstance().findCategorysInTreeExcept(); items.Insert(0, new Models.Infrastructure.Category { ItemID = -1, url = "" }); foreach (var cat in items) { for (int i = 0; i < cat.itemLevel; i++) { cat.url = " > " + cat.url; } } return(new SelectList(items, "ItemID", "url", selectedID)); }
SelectList getParentItemsForSelect(int?selectedID = null, int?excludeID = null) { var parentItemsForSelect = InfrastructureCategoryDbContext.getInstance().findCategorysInTreeExcept(0, excludeID); parentItemsForSelect.Insert(0, new Category { ItemID = -1, url = "" }); foreach (var cat in parentItemsForSelect) { for (int i = 0; i < cat.itemLevel; i++) { cat.url = " > " + cat.url; } } return(new SelectList(parentItemsForSelect, "ItemID", "url", selectedID)); }
public static Menu fillMenuLink(Menu item, Lang lang, Category _cat) { var hasArticles = WebApplication2.Context.ArticlePublishedDbContext.getInstance().hasArticlesPublishedByCategory(_cat, lang.lang); if (hasArticles) { item.is_has_published_content = true; } else if (item.submenu != null) { foreach (Menu m in item.submenu) { var subCat = InfrastructureCategoryDbContext.getInstance().findCategoryByID(m.category.categoryItemID); var subHasArticles = false; if (subCat != null) { subHasArticles = WebApplication2.Context.ArticlePublishedDbContext.getInstance().hasArticlesPublishedByCategory(subCat, lang.lang); } if (subHasArticles) { item.link = m.link; break; } else if (item.submenu != null) { foreach (Menu mm in item.submenu) { var subsubCat = InfrastructureCategoryDbContext.getInstance().findCategoryByID(mm.category.categoryItemID); var subsubHasArticles = false; if (subsubCat != null) { subsubHasArticles = WebApplication2.Context.ArticlePublishedDbContext.getInstance().hasArticlesPublishedByCategory(subsubCat, lang.lang); } if (subsubHasArticles) { item.link = mm.link; break; } } } } } return(item); }
public List <int> getAccessibleCategoryListInt() { List <string> list = getAccessibleCategoryList(); List <int> listInt = new List <int>(); foreach (string str in list) { if (!str.Equals("")) { int id = Convert.ToInt32(str); var item = InfrastructureCategoryDbContext.getInstance().findCategoryByID(id); if (item != null) { listInt.Add(id); } } } return(listInt); }
public ActionResult DeleteConfirmed(int id = 0) { var item = InfrastructureCategoryDbContext.getInstance().findCategoryByID(id); if (item == null) { return(HttpNotFound()); } var name = item.GetName(); var parentItemID = item.parentItemID; var error = InfrastructureCategoryDbContext.getInstance().delete(item, true); if (error != null) { TempData["ErrorMessage"] = error; } else { TempData["Message"] = "'" + name + "' Deleted"; } return(RedirectToAction("List", new { parentItemID = parentItemID })); }
public List <Category> getAccessibleCategoryListObject() { List <Category> items = new List <Category>(); var categoryList = getAccessibleCategoryList(); foreach (var id in categoryList) { try { int _id = Convert.ToInt32(id); var item = InfrastructureCategoryDbContext.getInstance().findCategoryByID(_id); if (item != null) { items.Add(item); } } catch (Exception e) { LogHelper.Error(null, e); } } return(items); }
public static bool NotifyAllOnActionOfBaseArticle(string categoryStr, BaseArticle baseArticle, EmailNotificationAction action, List <Object> parameters = null) { if (action == EmailNotificationAction.UNKNOWN) { return(false); } var categoryID = baseArticle.categoryID; Category category = null; if (baseArticle.categoryID == null || baseArticle.categoryID <= 0) { category = InfrastructureCategoryDbContext.getInstance().findCategoryByID(categoryID); } // get createdBy Account owner = AccountDbContext.getInstance().findAccountByID(SessionPersister.account.AccountID); // analyze category for interested accounts (by account group) List <AccountGroup> accountGroups = AccountGroupDbContext.getInstance().findGroups(); List <AccountGroup> filteredAccountGroups = new List <AccountGroup>(); foreach (var group in accountGroups) { List <int> categoryIDs = group.getAccessibleCategoryListInt(); if (category != null && categoryIDs.Contains(category.ItemID)) { filteredAccountGroups.Add(group); } } List <Account> accounts = AccountDbContext.getInstance().findAccountsByAccountGroupsToEmailNotify(filteredAccountGroups, baseArticle); // filter... List <Account> filteredAccounts = new List <Account>(); if (action == EmailNotificationAction.CREATE || action == EmailNotificationAction.EDIT || action == EmailNotificationAction.EDITPROPERTIES || action == EmailNotificationAction.CREATENEWVERSION) { foreach (var acc in accounts) { if (acc.isRoleSuperadmin() || acc.isRoleEditor()) { filteredAccounts.Add(acc); } } } if (action == EmailNotificationAction.DELETE) { foreach (var acc in accounts) { if (acc.isRoleSuperadmin() || acc.isRoleEditor()) { filteredAccounts.Add(acc); } } } if (action == EmailNotificationAction.SUBMITFORAPPROVAL) { foreach (var acc in accounts) { if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover()) { filteredAccounts.Add(acc); } } } if (action == EmailNotificationAction.APPROVE || action == EmailNotificationAction.UNAPPROVE) { foreach (var acc in accounts) { if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover() || acc.isRolePublisher()) { filteredAccounts.Add(acc); } } } if (action == EmailNotificationAction.PUBLISH || action == EmailNotificationAction.UNPUBLISH) { foreach (var acc in accounts) { if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover() || acc.isRolePublisher()) { filteredAccounts.Add(acc); } } } foreach (var acc in filteredAccounts) { // send to owner? if (owner != null && owner.AccountID == acc.AccountID && owner.ShouldEmailNotifyBaseArticleChangesByOwn()) { SendEmail(categoryStr, owner, acc, baseArticle, category, action); continue; } // send to all? if (acc.ShouldEmailNotifyBaseArticleChanges()) { SendEmail(categoryStr, owner, acc, baseArticle, category, action); continue; } } return(true); }