public Seeder(MongoDBConnection db) { dbInstance = db; }
public static IEnumerable<Post> UserPostsHoursAgo(MongoDBConnection db, string uid, int hoursAgo = 1) { return db.Posts.FindAllAs<Post>().Where(i => i.DeletedAt == null && i.CreatedByUID == uid && i.CreatedAt > DateTime.UtcNow.AddHours(-hoursAgo)); }
public static WriteConcernResult Create(MongoDBConnection db, SetterPost setterPost) { if (IsUniquePost(db, setterPost) == null && UserPostsHoursAgo(db, setterPost.CreatedByUID).Count() < 2) { Post post = new Post(setterPost); var createdPostResult = db.Posts.Insert(post); // create vote for post by user db.Votes.Insert(new SetterVote(post.Id, setterPost.CreatedByUID, 1)); return createdPostResult; } return null; }
public static Post IsUniquePost(MongoDBConnection db, SetterPost setterPost) { if (db.Posts.Count() > 0) { // use db.collection.find({_id: "myId"}, {_id: 1}).limit(1) instead return db.Posts.FindOneAs<Post>(Query<Post>.Where(i => i.Title == setterPost.Title && i.DeletedAt == null)); } return null; }
public static IEnumerable<Post> GetTop(MongoDBConnection db) { return db.Posts.FindAll().Where(i => i.DeletedAt == null).AsQueryable().OrderByDescending(x => x.GetScore()).ToList();//.OrderByDescending(x => x.CreatedAt).ThenByDescending(x => x.GetScore()).ToList(); }
public static IEnumerable<Post> GetLatest(MongoDBConnection db) { return db.Posts.FindAs<Post>(Query<Post>.Where(i => i.DeletedAt == null)).SetSortOrder(SortBy<Post>.Descending(i => i.CreatedAt)); }
public static Post Get(MongoDBConnection db, string id) { return db.Posts.FindOne(Query<Post>.Where(i => i.Id == id)); }
/*public static IEnumerable<Post> GetByQuery(MongoDBConnection db, string title) { return db.Posts.FindAs<Post>(Query<Post>.Where(i => i.Title == title)); }*/ public static WriteConcernResult Delete(MongoDBConnection db, string id) { //return db.Posts.Remove(Query.EQ("_id", id)); return db.Posts.Update(Query.EQ("_id", new ObjectId(id)), Update<Post>.Set(i => i.DeletedAt, DateTime.UtcNow)); }