public string CreateBlogPost(BlogPost newPost) { string newId = Guid.NewGuid().ToString("d"); newPost.Id = newId; using (Lock(true)) { Add(newPost.Clone()); } return(newId); }
public BlogPost[] GetRecentPublishedPosts(int numberOfPosts) { ArrayList results = new ArrayList(); using (Lock(false)) { for (int i = 0; i < Count && results.Count < numberOfPosts; i++) { BlogPost post = this[Count - i - 1]; if (post.Published) { results.Add(post.Clone()); } } } return((BlogPost[])results.ToArray(typeof(BlogPost))); }
public void UpdateBlogPost(BlogPost existingPost) { using (Lock(true)) { if (!_postTable.ContainsKey(existingPost.Id)) { throw new XmlRpcServerException(404, "Cannot edit a post that doesn't exist (was it deleted?)"); } // pass-by-value semantics BlogPost clone = existingPost.Clone(); _postTable[existingPost.Id] = clone; for (int i = 0; i < _postList.Count; i++) { if (((BlogPost)_postList[i]).Id == clone.Id) { _postList[i] = clone; break; } } } }
public void UpdateBlogPost(BlogPost existingPost) { using (Lock(true)) { if (!_postTable.ContainsKey(existingPost.Id)) throw new XmlRpcServerException(404, "Cannot edit a post that doesn't exist (was it deleted?)"); // pass-by-value semantics BlogPost clone = existingPost.Clone(); _postTable[existingPost.Id] = clone; for (int i = 0; i < _postList.Count; i++) { if (((BlogPost) _postList[i]).Id == clone.Id) { _postList[i] = clone; break; } } } }
public string CreateBlogPost(BlogPost newPost) { string newId = Guid.NewGuid().ToString("d"); newPost.Id = newId; using (Lock(true)) { Add(newPost.Clone()); } return newId; }