public Post(SetterPost setterPost) { Title = setterPost.Title; Content = setterPost.Content; VoteCount = 1; CreatedByUID = setterPost.CreatedByUID; CreatedAt = DateTime.UtcNow; DeletedAt = null; Archived = false; }
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; }
// POST: api/Post public bool Post(SetterPost setterPost) { setterPost.CreatedByUID = Helper.GenerateClientUID(); return (PostShepherd.Create(db, setterPost) != null); }