public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); var authCookie = filterContext.HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { var userService = (IUser)DependencyResolver.Current.GetService(typeof(IUser)); var ticket = FormsAuthentication.Decrypt(authCookie.Value); CustomPrincipalSerializeModel principalModel = new JavaScriptSerializer().Deserialize<CustomPrincipalSerializeModel>(ticket.UserData); CustomPrincipal principal = new CustomPrincipal(principalModel, principalModel.IsAdmn ? (int?)userService.GetUserGroupIDByUserID(principalModel.UserID) : null, principalModel.IsAdmn ? userService.GetPermissionsByUserID(principalModel.UserID) : null, AuthorizeCore(filterContext.HttpContext)); filterContext.HttpContext.User = principal; } }
private static List<CMSMenuItem> CreateSectionsSubMenu(IEnumerable<tbl_SiteMap> sections, int parentID, CustomPrincipal currentUser) { return sections.Where(sm => parentID == 0 ? (sm.SM_ParentID == 0 || sm.IsDirectlyInMenu) : (sm.SM_ParentID == parentID && sm.IsUnderParentInMenu)) .OrderBy(sm => sm.SM_OrderBy).Select(section => { var item = new CMSMenuItem { MenuItemID = section.SiteMapID, SubMenuItems = CreateSectionsSubMenu(sections, section.SiteMapID, currentUser), CssClasses = section.SM_IsPredefined ? "predefinedSection" : String.Empty, IsDelete = !section.tbl_ContentType.CTP_Value.Equals(ContentType.Category.ToString()), IsEdit = !section.tbl_ContentType.CTP_Value.Equals(ContentType.Category.ToString()), IsMove = currentUser.HasPermission(Permission.EditContent), ApproveText = String.Format("{0} Content Requires Approval", section.SM_Name), DeleteText = String.Format("Delete {0} ({1})", section.SM_Name, section.SiteMapID), EditText = String.Format("Edit {0} ({1})", section.SM_Name, section.SiteMapID), EditImagesText = String.Format("Images for {0} ({1})", section.SM_Name, section.SiteMapID), ExpandText = String.Format("Show Sub Pages of {0}", section.SM_Name), PreviewText = String.Format("Preview {0}", section.SM_Name), PreviewUrl = String.Format("/Admn/Preview?sectionID={0}", section.SiteMapID), Title = section.SM_Name, }; if (section.IsType(ContentType.Category)) { item.Title += " (Product Category)"; } else if (section.IsType(ContentType.Gallery) && section.tbl_Gallery.G_CustomerID==0) { item.Title += " (Gallery)"; } else { item.IsPreview = true; item.IsApprove = section.tbl_Content.Where(c => !c.C_Deleted).All(c => !c.C_Approved) && currentUser.HasPermission(Permission.ApproveContent); item.IsEdit = currentUser.HasPermission(Permission.EditContent); item.IsExpand = sections.Any(c => c.SM_ParentID == section.SiteMapID); item.IsEditImages = currentUser.HasPermission(Permission.EditContent); if (!section.SM_IsPredefined) { item.IsDelete = currentUser.HasPermission(Permission.DeleteContent); } } return item; }).ToList(); }
private static List<CMSMenuItem> MapProductsForCategory(List<tbl_Products> products, CustomPrincipal currentUser) { return products.OrderBy(p => p.P_Order).Select(product => new CMSMenuItem { MenuItemID = product.ProductID, Title = String.Format("{0} ({1})", product.P_Title, product.P_ProductCode), DeleteText = String.Format("Delete {0} ({1})", product.P_Title, product.ProductID), EditText = String.Format("Edit {0}", product.P_Title), IsEditImages = true, EditImagesText = "Images", IsAssociation = true, IsMove = true, IsApprove = product.tbl_SiteMap.tbl_Content.Where(c => !c.C_Deleted).All(c => !c.C_Approved) && currentUser.HasPermission(Permission.ApproveContent), ApproveText = "Content Requires Approval", IsStock = true, StockText = "Stock" }).ToList(); }
private static List<CMSMenuItem> CreateFormItemsSubMenu(List<tbl_FormItem> formsItems, CustomPrincipal currentUser) { return formsItems.OrderBy(fi => fi.FI_Order).Select(item => new CMSMenuItem { MenuItemID = item.FormItemID, Title = item.tbl_FormItemType.FIT_Name == ContactItemTypeName.Divider ? String.Format("- {0} -", item.FI_Name) : item.FI_Name, IsDelete = true, DeleteText = String.Format("Delete {0}", item.FI_Name), IsEdit = true, EditText = String.Format("Edit: {0}", item.FI_Name), IsVisibility = true, VisibilityText = "Turn item on / off", Visible = item.FI_Live, IsMove = true }).ToList(); }
private static List<CMSMenuItem> CreateProdSubCategories(List<tbl_SiteMap> categories, int parentID, CustomPrincipal currentUser) { return categories.Where(c => c.tbl_ProdCategories.PC_ParentID.GetValueOrDefault(0) == parentID) .Select(category => new CMSMenuItem { MenuItemID = category.tbl_ProdCategories.CategoryID, Title = category.tbl_ProdCategories.PC_Title, SubMenuItems = CreateProdSubCategories(categories, category.SiteMapID, currentUser), DeleteText = String.Format("Delete {0} ({1})", category.tbl_ProdCategories.PC_Title, category.tbl_ProdCategories.CategoryID), EditText = String.Format("Edit {0}", category.tbl_ProdCategories.PC_Title), IsEditImages = true, EditImagesText = "Image", IsMove = true, IsApprove = category.tbl_Content.Where(c => !c.C_Deleted).All(c => !c.C_Approved) && currentUser.HasPermission(Permission.ApproveContent), ApproveText = String.Format("{0} Category Requires Approval", category.tbl_ProdCategories.PC_Title), }).ToList(); }
public static List<CMSMenuModel> MapSections(List<tbl_Domains> domains, CustomPrincipal currentUser) { return domains.Select(domain => { var sections = domain.tbl_SiteMap.Where(sm => !sm.SM_Deleted && (sm.IsType(ContentType.Content) || ((sm.IsType(ContentType.Category) || sm.IsType(ContentType.Gallery)) && sm.IsDirectlyInMenu))); return new CMSMenuModel { Title = domain.DO_CompanyName, MenuItems = CreateSectionsSubMenu(sections, 0, currentUser) }; }).ToList(); }
public static List<CMSMenuModel> MapUsers(List<tbl_AdminUsers> users, CustomPrincipal currentUser) { return new List<CMSMenuModel> { new CMSMenuModel { Title = "Users", MenuItems = users.Select(user => new CMSMenuItem { MenuItemID = user.AdminUserID, Title = String.Format("<b>{0}: {1}</b> ({2})", user.US_UserName, user.US_Email, user.tbl_UserGroups.UG_Type), IsDelete = currentUser.HasPermission(Permission.DeleteUser), IsEdit = currentUser.HasPermission(Permission.EditUser) }).ToList() } }; }
public static List<CMSMenuModel> MapProdCategories(List<tbl_Domains> domains, CustomPrincipal currentUser) { return domains.Select(domain => { var categories = domain.tbl_SiteMap.Where(sm => !sm.SM_Deleted && sm.IsType(ContentType.Category) && sm.tbl_ProdCategories.PC_ProductTypeID == (int)ProductType.Item).OrderBy(c => c.tbl_ProdCategories.PC_Order).ToList(); return new CMSMenuModel { Title = "Product Categories for " + domain.DO_CompanyName, MenuItems = CreateProdSubCategories(categories, 0, currentUser) }; }).ToList(); }
public static List<CMSMenuModel> MapProducts(List<tbl_Products> products, CustomPrincipal currentUser) { var categories = products.Select(p => p.tbl_ProdCategories).Distinct(); return new List<CMSMenuModel> { new CMSMenuModel { Title = products.Select(p => p.tbl_ProductTypes.PT_Name).FirstOrDefault() == ProductType.Event.ToString() ? "Events" : "Products", MenuItems = categories.Select(category => new CMSMenuItem { MenuItemID = category.CategoryID, BoldedTitle = category.PC_Title, SubMenuItems = MapProductsForCategory(products.Where(p => p.P_CategoryID == category.CategoryID).ToList(), currentUser), IsDelete = false, IsEdit = false }).ToList() } }; }
public static List<CMSMenuModel> MapPostage(List<tbl_Domains> domains, CustomPrincipal customPrincipal) { return domains.Select(domain => new CMSMenuModel { Title = "Postages for " + domain.DO_CompanyName, MenuItems = domain.tbl_Postage.Select(item => new CMSMenuItem { MenuItemID = item.PostageID, Title = String.Format("{0} {1:C} ( {2} {3} {4} )", item.PST_Description, item.PST_Amount.GetValueOrDefault(0), item.tbl_PostageBands != null ? String.Format("{0:C}-{1:C}", item.tbl_PostageBands.PB_Lower, item.tbl_PostageBands.PB_Upper) : String.Empty, item.tbl_PostageWeights != null ? String.Format("{0}-{1}", item.tbl_PostageWeights.PW_Lower, item.tbl_PostageWeights.PW_Upper) : String.Empty, item.tbl_PostageZones != null ? item.tbl_PostageZones.PZ_Name : String.Empty) }).ToList() }).ToList(); }
public static List<CMSMenuModel> MapNews(List<tbl_Domains> domains, CustomPrincipal currentUser) { return domains.Select(domain => new CMSMenuModel { Title = "Blog Articles for " + domain.DO_CompanyName, MenuItems = domain.tbl_SiteMap .Where(sm => !sm.SM_Deleted && sm.IsType(ContentType.Blog)).OrderByDescending(b => b.SM_Live).ThenByDescending(b => b.SM_Date) .Select(b => new CMSMenuItem { MenuItemID = b.SiteMapID, Date = b.SM_Date, IsFuturePublish = b.SM_PublishDate == null ? false : (b.SM_PublishDate >= DateTime.Now), PublishDateText = b.SM_PublishDate != null ? ("Publish date: " + b.SM_PublishDate.ToString()) : String.Empty, Title = b.SM_Name, IsDelete = currentUser.HasPermission(Permission.DeleteNews), DeleteText = String.Format("Delete {0} ({1})", b.SM_Name, b.SiteMapID), IsEdit = currentUser.HasPermission(Permission.EditNews), EditText = String.Format("Edit \"{0}\"", b.SM_Name), IsEditImages = currentUser.HasPermission(Permission.EditNews), EditImagesText = String.Format("Edit images for \"{0}\"", b.SM_Name), IsComment = true, CommentsText = String.Format("View comments for \"{0}\"", b.SM_Name), UnauthorizedCommentExists = b.tbl_Comments.Any(c => !c.CO_Authorised), AuthorizedCommentExists = b.tbl_Comments.Any(c => c.CO_Authorised), IsVisibility = true, VisibilityText = "Turn news article on / off", Visible = b.SM_Live }).ToList() }).ToList(); }
public static List<CMSMenuModel> MapForms(List<tbl_Domains> domains, List<tbl_Form> forms, CustomPrincipal currentUser) { return domains.Select(domain => new CMSMenuModel { Title = "Forms for " + domain.DO_CompanyName, MenuItems = forms.Where(f => f.F_DomainID == domain.DomainID).Select(f => new CMSMenuItem { MenuItemID = f.FormID, Title = f.F_Name, IsEdit = false, IsDelete = false, IsComment = true, CommentsText = String.Format("View form submissions for \"{0}\"", f.F_Name), UnauthorizedCommentExists = f.tbl_FormSubmission.Any(fs => !fs.FS_Read), AuthorizedCommentExists = f.tbl_FormSubmission.Any(fs => fs.FS_Read) }).ToList() }).ToList(); }
public static List<CMSMenuModel> MapFormItems(List<tbl_Domains> domains, List<tbl_Form> forms, List<tbl_FormItem> formsItems, CustomPrincipal currentUser) { return domains.Select(domain => new CMSMenuModel { Title = "Forms for " + domain.DO_CompanyName, MenuItems = forms.Where(f => f.F_DomainID == domain.DomainID).OrderBy(f => f.F_Name) .Select(form => new CMSMenuItem { MenuItemID = form.FormID, Title = form.F_Name, IsDelete = true, IsEdit = true, SubMenuItems = CreateFormItemsSubMenu(formsItems.Where(fi => fi.FI_FormID == form.FormID).ToList(), currentUser) }).ToList() }).ToList(); }
public static List<CMSMenuModel> MapDonationInfo(List<tbl_Domains> domains, CustomPrincipal principal) { var menuModel = new CMSMenuModel { Title = "Donations Info", MenuItems = new List<CMSMenuItem>() }; var categoriesModels = new List<CMSMenuModel>(); foreach (var domain in domains) { var categoryModel = new CMSMenuModel { Title = "Donations Info for " + domain.DO_CompanyName, MenuItems = new List<CMSMenuItem>() }; foreach (var item in domain.tbl_DonationInfo) { categoryModel.MenuItems.Add(new CMSMenuItem() { MenuItemID = item.DonationInfoID, Title = String.Format("{0} {1:C}", item.DI_Title, item.DI_Amount), IsEdit = true, IsDelete = true, EditText = "Edit Donation Info", DeleteText = "Delete Donation Info", IsEditImages = true, EditImagesText = "Manage DonationInfo Image" }); } categoriesModels.Add(categoryModel); } return categoriesModels; }