/// <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> /// Delete all notifications that are associated with any of the entity ids in the list /// </summary> /// <param name="entityIdList"></param> /// <returns>bool</returns> public static bool Delete(List <string> entityIdList) { var DeleteQuery = Query <Notification> .In(e => e.EntityId, entityIdList); return(Execute.Delete <Notification>(COLLECTION_NAME, DeleteQuery)); }
/// <summary> /// Delete all notifications that are assoicated when the entity id (call after the user updates or performs a specific action) /// </summary> /// <param name="entityId">the product id / order id / form submission id, etc.</param> /// <returns>bool</returns> public static bool Delete(string entityId) { var DeleteQuery = Query <Notification> .EQ(e => e.EntityId, entityId); return(Execute.Delete <Notification>(COLLECTION_NAME, DeleteQuery)); }