/// <summary> /// Default constructur /// </summary> public ObjectCommentRepository() { _comments = new Collection<CommentEntity>(); Random rand = new Random(); for (long i = 1; i < Repository.UserPostRepositoryInstance.GetCount(); i++) { // random count of comments for post for (int j = 1; j < rand.Next(1, 100); j++) { if (Repository.UserPostRepositoryInstance.IsExists(i)) { CommentEntity comment = new CommentEntity(); comment.Id = identityIdCounter++; comment.CreatedUTC = DateTime.Now; comment.PostId = i; comment.UserId = Repository.UserPostRepositoryInstance.Get(i).AuthorUserId; comment.Message = ""; for (int k = 0; k < rand.Next(1, 10); k++) comment.Message += "Nice post!"; _comments.Add(comment); } } } }
/// <summary> /// Create comment /// </summary> /// <param name="comment"></param> /// <returns>created comment</returns> public bool Create(CommentEntity comment) { bool createResult = false; if (comment != null) { _comments.Add(comment); createResult = true; } return createResult; }
/// <summary> /// Update comment /// </summary> /// <param name="comment"></param> /// <returns>updated comment</returns> public bool Update(CommentEntity comment) { bool updateResult = false; CommentEntity old = _comments.SingleOrDefault(c => c.Id == comment.Id); if (old != null) { old.Message = comment.Message; updateResult = true; } return updateResult; }