/// <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> /// Update a notification with a new description, usually only for purchase orders after payment captured /// </summary> /// <param name="entityId"></param> /// <param name="description"></param> /// <returns></returns> public static bool Update(string entityId, string description) { var UpdateQuery = Query <Notification> .EQ(e => e.EntityId, entityId); var UpdateSetStatement = Update <Notification> .Set(e => e.Description, description).Set(e => e.CreatedDateUtc, DateTime.UtcNow); return(Execute.Update <Notification>(COLLECTION_NAME, UpdateQuery, UpdateSetStatement)); }