/// <summary> /// Will save a brand new page revision so we can maintain the old page structure for revision history. /// Method will generate a new MongoDB ObjectId and UTC datetime for the entity. /// </summary> /// <param name="page">page to save</param> /// <returns>bool</returns> public static bool Save(Page page) { bool SaveSuccessful = true; //Create a new object id so we can maintain the revision history of a page, the "PageId" attribute will remain the same. page.Id = ObjectId.GenerateNewId().ToString(); //Timestamp of when the page was saved. page.ModifiedDateUTC = DateTime.UtcNow; //if we are publishing a page then make sure all pages in DB that exist with same page id are set to not published. if (page.Published) { //set all records with same page id to false before saving new page. var UpdateQuery = Query <Page> .EQ(e => e.PageId, page.PageId); var UpdateSetStatement = Update <Page> .Set(e => e.Published, false); SaveSuccessful = Execute.Update <Page>(COLLECTION_NAME, UpdateQuery, UpdateSetStatement); } SaveSuccessful = Execute.Save <Page>(COLLECTION_NAME, page); //delete versions more than 10 MongoCollection <Page> Collection = Execute.GetCollection <Page>(COLLECTION_NAME); List <Page> PageList = (from e in Collection.AsQueryable <Page>() where e.PageId.Equals(page.PageId) orderby e.ModifiedDateUTC descending select e).Skip(10).ToList(); List <string> PageIdList = (List <string>)(from e in PageList select e.Id).ToList(); var DeleteQuery = Query <Page> .In(e => e.Id, PageIdList); return(SaveSuccessful && Execute.Delete <Page>(COLLECTION_NAME, DeleteQuery)); }
/// <summary> /// Load a list of page views /// </summary> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <param name="pageFriendlyUrl"></param> /// <returns></returns> public static List <PageView> LoadPageViews(DateTime dateFrom, DateTime dateTo, string pageFriendlyUrl = "") { MongoCollection <PageView> Collection = Execute.GetCollection <PageView>(COLLECTION_NAME); //grab the last viewed page and set the exit time if exists return((from e in Collection.AsQueryable <PageView>() where (pageFriendlyUrl == "" || e.PageFriendlyURL == pageFriendlyUrl) && e.PageOpenedDateUTC >= dateFrom && e.PageOpenedDateUTC <= dateTo orderby e.PageOpenedDateUTC select e).ToList()); }
public static List <string> LoadUniquePageTypes() { MongoCollectionBase <PageView> Collection = Execute.GetCollection <PageView>(COLLECTION_NAME); //grab the last viewed page and set the exit time if exists IQueryable <string> PageTypes = Collection.AsQueryable <PageView>().Select(e => e.PageFriendlyURL).Distinct(); return(PageTypes != null?PageTypes.ToList() : new List <string>()); }
/// <summary> /// Search active products by selected search filters and the searchText vs name/description. /// </summary> /// <param name="selectedSearchFilters">Key/value of the selected search filters, i.e. there is a "Color" dropdown menu, and the user selects "Red".</param> /// <param name="searchText">generic search text from a search text box to be checked vs name / description.</param> /// <returns>list of products that we searched for.</returns> public static List<Product> SearchProducts(Dictionary<string, List<string>> selectedSearchFilters = null, string searchText = "", bool? active = null) { MongoCollection<Product> Collection = Execute.GetCollection<Product>(COLLECTION_NAME); Dictionary<string, Product> ReturnProductDictionary = new Dictionary<string, Product>(); //grab all active products where the name/description contains the searchText List<Product> ProductList = new List<Product>(); if (active != null) { ProductList = (from e in Collection.AsQueryable<Product>() where e.Active == Boolean.Parse(active.ToString()) && (e.Name.ToUpper().Contains(searchText.ToUpper()) || e.Description.ToUpper().Contains(searchText.ToUpper())) orderby e.Name select e).ToList(); } else { ProductList = (from e in Collection.AsQueryable<Product>() where e.Name.ToUpper().Contains(searchText.ToUpper()) || e.Description.ToUpper().Contains(searchText.ToUpper()) orderby e.Name select e).ToList(); } foreach (var MyProduct in ProductList) { if (!ReturnProductDictionary.ContainsKey(MyProduct.Id)) { if (selectedSearchFilters != null && selectedSearchFilters.Count > 0) { if (MyProduct.SearchPropertyList != null && MyProduct.SearchPropertyList.Count > 0) { foreach (var ProductSearchProp in MyProduct.SearchPropertyList) { if (selectedSearchFilters.Keys.Contains(ProductSearchProp.Name)) { foreach (string SearchFilterValue in selectedSearchFilters[ProductSearchProp.Name]) { //will be null if no values found var ProductSearchPropValue = ProductSearchProp.Values.Where(e => e.Value.Equals(SearchFilterValue)); if (ProductSearchPropValue != null && !ReturnProductDictionary.ContainsKey(MyProduct.Id)) { ReturnProductDictionary.Add(MyProduct.Id, MyProduct); } } } } } } else { ReturnProductDictionary.Add(MyProduct.Id, MyProduct); } } } return ReturnProductDictionary.Values.ToList(); }
/// <summary> /// Load a single setting group object by its unique group name /// </summary> /// <param name="groupName"></param> /// <returns></returns> public static SettingGroup LoadSettingGroupByName(string groupName) { MongoCollection <SettingGroup> Collection = Execute.GetCollection <SettingGroup>(COLLECTION_NAME); SettingGroup SettGroup = (from e in Collection.AsQueryable <SettingGroup>() where e.GroupKey == groupName select e).FirstOrDefault(); if (SettGroup == null) { SettGroup = new SettingGroup(); } return(SettGroup); }
/// <summary> /// Load only the keys /// </summary> /// <returns></returns> public static List <string> LoadAllKeyNames() { List <string> ReturnList = new List <string>(); MongoCollection <StaticProperty> Collection = Execute.GetCollection <StaticProperty>(COLLECTION_NAME); List <StaticProperty> StaticPropList = (from e in Collection.AsQueryable <StaticProperty>() orderby e.KeyName select e).ToList(); if (StaticPropList != null && StaticPropList.Count > 0) { foreach (var StaticProp in StaticPropList) { ReturnList.Add(StaticProp.KeyName); } } return(ReturnList); }
/// <summary> /// Load a list of all active products, just their name and id. /// </summary> /// <returns></returns> public static List<PreviewProduct> LoadPreviewProducts() { MongoCollection<Product> Collection = Execute.GetCollection<Product>(COLLECTION_NAME); List<PreviewProduct> PreviewProductList = new List<PreviewProduct>(); //grab all active products where the name/description contains the searchText List<Product> ProductList = (from e in Collection.AsQueryable<Product>() where e.Active orderby e.Name select e).ToList(); if (ProductList != null && ProductList.Count > 0) { foreach (var MyProduct in ProductList) { PreviewProductList.Add(new PreviewProduct { Id = MyProduct.Id, Name = MyProduct.Name }); } } return PreviewProductList; }
/// <summary> /// Load a list of PageRevisions for a specific page id, will be ordered by descending date (most recent first). /// </summary> /// <param name="PageId">The page id that stays the same between each revision.</param> /// <returns>Lite list of page revisions for display.</returns> public static List <PageRevision> LoadRevisionHistory(Guid PageId) { MongoCollection <Page> Collection = Execute.GetCollection <Page>(COLLECTION_NAME); List <PageRevision> NewPageRevisionList = new List <PageRevision>(); List <Page> PageList = (from e in Collection.AsQueryable <Page>() where e.PageId.Equals(PageId) orderby e.ModifiedDateUTC descending select e).ToList(); if (PageList != null && PageList.Count > 0) { foreach (var Page in PageList) { NewPageRevisionList.Add(new PageRevision { Id = Page.Id, PageTitle = Page.PageTitle, PageFriendlyURL = Page.PageFriendlyURL, Published = Page.Published, ModifiedDateUTC = Page.ModifiedDateUTC }); } } return(NewPageRevisionList); }
/// <summary> /// Load a list of purchase orders by filtering by the order date and the customer info passed in /// </summary> /// <param name="paymentCaptured">if the payment from paypal has been captured</param> /// <param name="orderShipped">if the order has been shipped</param> /// <param name="orderPlacedFrom"></param> /// <param name="orderPlaceTo"></param> /// <param name="customerInfo">Relevant customer info to search by</param> /// <returns>list of purchase orders</returns> public static List <PurchaseOrderDetails> Search(string paymentCaptured, string orderShipped, DateTime orderPlacedFrom, DateTime orderPlaceTo, CustomerInfo customerInfo, int numberToQuery) { paymentCaptured = paymentCaptured.ToUpper(); orderShipped = orderShipped.ToUpper(); MongoCollection <PurchaseOrderDetails> Collection = Execute.GetCollection <PurchaseOrderDetails>(COLLECTION_NAME); return((from e in Collection.AsQueryable <PurchaseOrderDetails>() where e.PayPalOrderDetails.OrderPlacedDateUtc >= orderPlacedFrom && (orderPlaceTo == DateTime.MinValue || e.PayPalOrderDetails.OrderPlacedDateUtc <= orderPlaceTo) && (string.IsNullOrWhiteSpace(orderShipped) || ("FALSE" == orderShipped && e.PayPalOrderDetails.OrderShippedDateUtc == DateTime.MinValue) || ("TRUE" == orderShipped && e.PayPalOrderDetails.OrderShippedDateUtc != DateTime.MinValue)) && (string.IsNullOrWhiteSpace(paymentCaptured) || ("FALSE" == paymentCaptured && e.PayPalOrderDetails.PaymentCapturedDateUtc == DateTime.MinValue) || ("TRUE" == paymentCaptured && e.PayPalOrderDetails.PaymentCapturedDateUtc != DateTime.MinValue)) && ("" == customerInfo.Email || e.PayPalOrderDetails.CustomerInfo.Email.Contains(customerInfo.Email)) && ("" == customerInfo.FirstName || e.PayPalOrderDetails.CustomerInfo.FirstName.Contains(customerInfo.FirstName)) && ("" == customerInfo.LastName || e.PayPalOrderDetails.CustomerInfo.LastName.Contains(customerInfo.LastName)) orderby e.PayPalOrderDetails.OrderPlacedDateUtc descending select e).Take(numberToQuery).ToList()); }
/// <summary> /// Load a list of existing page types. /// </summary> /// <returns>A list of PageType objects.</returns> public static List <PageType> LoadPageTypes() { MongoCollection <Page> Collection = Execute.GetCollection <Page>(COLLECTION_NAME); List <Page> PageList = (from e in Collection.AsQueryable <Page>() orderby e.PageId, e.ModifiedDateUTC descending select e).ToList(); List <PageType> NewPageTypeList = new List <PageType>(); List <Guid> ProcessedPageIds = new List <Guid>(); if (PageList != null && PageList.Count > 0) { foreach (var Page in PageList) { if (!ProcessedPageIds.Contains(Page.PageId)) { NewPageTypeList.Add(new PageType { LatestVersionPublished = Page.Published, PageId = Page.PageId, PageTitle = Page.PageTitle, PageFriendlyURL = Page.PageFriendlyURL, ModifiedDateUTC = Page.ModifiedDateUTC, Published = Page.Published }); ProcessedPageIds.Add(Page.PageId); } else if (Page.Published) { PageType PageType = NewPageTypeList.Where(e => e.PageId.Equals(Page.PageId)).FirstOrDefault(); int Index = NewPageTypeList.IndexOf(PageType); if (Index != -1 && PageType != null) { NewPageTypeList[Index].Published = true; } } } return(NewPageTypeList); } return(null); }
/// <summary> /// Load a list of all the dashboard notifications that the admin user can see /// </summary> /// <returns></returns> public static List <Notification> LoadDashboardList(List <string> adminUserRoles) { MongoCollection <Notification> Collection = Execute.GetCollection <Notification>(COLLECTION_NAME); List <Notification> NotificationList = (from e in Collection.AsQueryable <Notification>() orderby e.CreatedDateUtc descending select e).ToList(); List <Notification> ReturnList = new List <Notification>(); if (adminUserRoles.Contains(Chimera.Entities.Admin.Role.AdminRoles.ADMIN_ALL)) { return(NotificationList); } else if (NotificationList != null && NotificationList.Count > 0) { foreach (var Notif in NotificationList) { int NumMatchRoles = 0; if (Notif.ViewAdminUserRolesRequired != null && Notif.ViewAdminUserRolesRequired.Count > 0) { foreach (var NotifAdminRole in Notif.ViewAdminUserRolesRequired) { if (adminUserRoles.Contains(NotifAdminRole)) { NumMatchRoles++; } } } if (NumMatchRoles == Notif.ViewAdminUserRolesRequired.Count) { ReturnList.Add(Notif); } } } return(ReturnList); }
/// <summary> /// Generate a unique list of search properties from the active products in the database. /// </summary> /// <returns>list of search properties for all active products.</returns> public static List<Property> LoadProductSearchProperties() { MongoCollection<Product> Collection = Execute.GetCollection<Product>(COLLECTION_NAME); List<Product> ProductList = (from e in Collection.AsQueryable<Product>() where e.Active select e).ToList(); Dictionary<string, Property> ReturnPropertyList = new Dictionary<string, Property>(); if (ProductList != null && ProductList.Count > 0) { foreach (var MyProduct in ProductList) { if (MyProduct.SearchPropertyList != null && MyProduct.SearchPropertyList.Count > 0) { foreach (var ProductSearchProp in MyProduct.SearchPropertyList) { if (!ReturnPropertyList.ContainsKey(ProductSearchProp.Name)) { ReturnPropertyList.Add(ProductSearchProp.Name, new Property(ProductSearchProp.Name)); } if (ProductSearchProp.Values != null && ProductSearchProp.Values.Count > 0) { foreach (var SearchPropValue in ProductSearchProp.Values) { if (!ReturnPropertyList[ProductSearchProp.Name].Values.Contains(SearchPropValue)) { ReturnPropertyList[ProductSearchProp.Name].Values.Add(SearchPropValue); } } } } } } } return ReturnPropertyList.Values.ToList(); }
/// <summary> /// Grab the last page the user visted if exists and update the exit time /// </summary> /// <param name="sessionId"></param> /// <returns></returns> public static bool UpdateLastPageUserWasOn(bool allowPageReportRecording, UserSessionInformation userInfo) { if (allowPageReportRecording && !userInfo.IsBot) { MongoCollection <PageView> Collection = Execute.GetCollection <PageView>(COLLECTION_NAME); //grab the last viewed page and set the exit time if exists PageView LastPageView = (from e in Collection.AsQueryable <PageView>() where e.SessionId == userInfo.SessionId orderby e.PageOpenedDateUTC descending select e).FirstOrDefault(); if (LastPageView != null && LastPageView.SessionId.Equals(userInfo.SessionId)) { //only update if was not set before, the exit time will already be set whenever the tab was closed and the session ends 20 mins later if (LastPageView.PageExitDateUTC.Equals(DateTime.MinValue)) { LastPageView.PageExitDateUTC = DateTime.UtcNow; return(Execute.Save <PageView>(COLLECTION_NAME, LastPageView)); } } } return(true); }
/// <summary> /// Get the count of total notifications /// </summary> /// <returns></returns> public static int GetCount() { MongoCollection <Notification> Collection = Execute.GetCollection <Notification>(COLLECTION_NAME); return(Collection.AsQueryable <Notification>().Count()); }
/// <summary> /// Load a single notification by its entity id /// </summary> /// <param name="entityId"></param> /// <returns></returns> public static Notification Load(string entityId) { MongoCollection <Notification> Collection = Execute.GetCollection <Notification>(COLLECTION_NAME); return((from e in Collection.AsQueryable <Notification>() orderby e.CreatedDateUtc descending select e).FirstOrDefault()); }
/// <summary> /// Load a list of all available admin user roles. /// </summary> /// <returns>list of strings.</returns> public static List <AdminUserRole> LoadAll() { MongoCollection <AdminUserRole> Collection = Execute.GetCollection <AdminUserRole>(COLLECTION_NAME); return((List <AdminUserRole>)(from e in Collection.AsQueryable <AdminUserRole>() select e).ToList()); }
/// <summary> /// Load a list of all the admin users. /// </summary> /// <returns>list of admin user objects.</returns> public static List <AdminUser> LoadAll() { MongoCollection <AdminUser> Collection = Execute.GetCollection <AdminUser>(COLLECTION_NAME); return((List <AdminUser>)(from e in Collection.AsQueryable <AdminUser>() orderby e.Username select e).ToList()); }
/// <summary> /// Load a single static property object by its unique key name. /// </summary> /// <param name="keyName"></param> /// <returns></returns> public static StaticProperty LoadByKeyName(string keyName) { MongoCollection <StaticProperty> Collection = Execute.GetCollection <StaticProperty>(COLLECTION_NAME); return((from e in Collection.AsQueryable <StaticProperty>() where e.KeyName.Equals(keyName) select e).FirstOrDefault()); }
/// <summary> /// Load a list of products by their unique ids /// </summary> /// <param name="idList"></param> /// <returns></returns> public static List<Product> LoadSpecificProducts(List<string> idList) { MongoCollection<Product> Collection = Execute.GetCollection<Product>(COLLECTION_NAME); return (from e in Collection.AsQueryable<Product>() where e.Active == true orderby e.Name select e).Where(e => idList.Contains(e.Id)).ToList(); }
/// <summary> /// Simply load a admin user by its unique Mongo Bson Id. /// </summary> /// <param name="bsonId">The unqiue Mongo Bson Id.</param> /// <returns>A single admin user object.</returns> public static AdminUser LoadByBsonId(ObjectId bsonId) { MongoCollection <AdminUser> Collection = Execute.GetCollection <AdminUser>(COLLECTION_NAME); return((from e in Collection.AsQueryable <AdminUser>() where e.Id.Equals(bsonId) select e).FirstOrDefault()); }
/// <summary> /// Simply load a page by its unique Mongo Bson Id. /// </summary> /// <param name="bsonId">The unqiue Mongo Bson Id.</param> /// <returns>A single page object.</returns> public static Page LoadByBsonId(string bsonId) { MongoCollection <Page> Collection = Execute.GetCollection <Page>(COLLECTION_NAME); return((from e in Collection.AsQueryable <Page>() where e.Id == bsonId select e).FirstOrDefault()); }
/// <summary> /// Load a admin user by its unique login username. /// </summary> /// <param name="username">The unique username.</param> /// <returns>A single admin user object.</returns> public static AdminUser LoadByUsername(string username) { MongoCollection <AdminUser> Collection = Execute.GetCollection <AdminUser>(COLLECTION_NAME); return((from e in Collection.AsQueryable <AdminUser>() where e.Username == username select e).FirstOrDefault()); }
/// <summary> /// Load all the static properties. /// </summary> /// <returns></returns> public static List <StaticProperty> LoadAll() { MongoCollection <StaticProperty> Collection = Execute.GetCollection <StaticProperty>(COLLECTION_NAME); return((List <StaticProperty>)(from e in Collection.AsQueryable <StaticProperty>() orderby e.KeyName select e).ToList()); }
/// <summary> /// Load a list of admin users by using a list of ids /// </summary> /// <param name="adminUserIds">The admin user id list</param> /// <returns>list of admin users</returns> public static List <AdminUser> LoadByMultipleIds(List <string> adminUserIds) { MongoCollection <AdminUser> Collection = Execute.GetCollection <AdminUser>(COLLECTION_NAME); return((List <AdminUser>)(from e in Collection.AsQueryable <AdminUser>() orderby e.Username where adminUserIds.Contains(e.Id) select e).ToList()); }
/// <summary> /// Load a single nav menu /// </summary> /// <param name="keyName"></param> /// <returns></returns> public static NavigationMenu LoadByKeyName(string keyName) { MongoCollection <NavigationMenu> Collection = Execute.GetCollection <NavigationMenu>(COLLECTION_NAME); return((from e in Collection.AsQueryable <NavigationMenu>() where e.KeyName == keyName select e).FirstOrDefault()); }
/// <summary> /// Load a list of static properties wwith a list of key names /// </summary> /// <param name="keyNames"></param> /// <returns></returns> public static List <StaticProperty> LoadByMultipleKeyNames(List <string> keyNames) { MongoCollection <StaticProperty> Collection = Execute.GetCollection <StaticProperty>(COLLECTION_NAME); return((from e in Collection.AsQueryable <StaticProperty>() orderby e.KeyName select e).Where(e => keyNames.Contains(e.KeyName)).ToList()); }
/// <summary> /// Load the only published version of a page. /// </summary> /// <param name="pageURL">the unique page friendly url (i.e. "Blog", "BuyShirts", etc).</param> /// <returns>A single page object.</returns> public static Page LoadByURL(string pageURL) { MongoCollection <Page> Collection = Execute.GetCollection <Page>(COLLECTION_NAME); return((from e in Collection.AsQueryable <Page>() where e.PageFriendlyURL.ToUpper() == pageURL.ToUpper() && e.Published select e).FirstOrDefault()); }
/// <summary> /// Load a single nav menu /// </summary> /// <param name="keyName"></param> /// <returns></returns> public static NavigationMenu LoadById(string id) { MongoCollection <NavigationMenu> Collection = Execute.GetCollection <NavigationMenu>(COLLECTION_NAME); return((from e in Collection.AsQueryable <NavigationMenu>() where e.Id == id select e).FirstOrDefault()); }
/// <summary> /// Load the most recent page revision of a specific page type by the page id if it is published. /// </summary> /// <param name="pageId">PageId that ties page revisions together.</param> /// <returns>A single page object.</returns> public static Page LoadByPageId(Guid pageId) { MongoCollection <Page> Collection = Execute.GetCollection <Page>(COLLECTION_NAME); return((from e in Collection.AsQueryable <Page>() where e.PageId.Equals(pageId) orderby e.Published descending, e.ModifiedDateUTC descending select e).FirstOrDefault()); }
/// <summary> /// load all the nav menus /// </summary> /// <returns></returns> public static List <NavigationMenu> LoadAll() { MongoCollection <NavigationMenu> Collection = Execute.GetCollection <NavigationMenu>(COLLECTION_NAME); return((from e in Collection.AsQueryable <NavigationMenu>() orderby e.UserFriendlyName select e).ToList()); }