Exemplo n.º 1
0
 public Post(Guid createdByID, string title, string body, Post parent = null)
 {
     PostID = Guid.NewGuid();
     CreatedByID = createdByID;
     Title = title;
     Body = body;
     ParentPost = parent;
     CreateDate = DateTime.UtcNow;
 }
Exemplo n.º 2
0
 public void AddPost(Post newPost)
 {
     if (newPost.PostID == null)
         throw new Exception("PostID is not allowed to be null!");
     if (newPost.CreatedByID == null)
         throw new Exception("CreatedByID is not allowed to be null!");
     if (!users.Any(u => u.UserID == newPost.CreatedByID))
         throw new Exception("CreatedByID does not match any user!");
     if (string.IsNullOrEmpty(newPost.Body))
         throw new Exception("Body is not allowed to be empty!");
     if (newPost.CreateDate == null || newPost.CreateDate == new DateTime())
         throw new Exception("CreateDate must be set");
     if (posts.Any(p => p.PostID == newPost.PostID))
         throw new Exception("A Post with that PostID already Exists!");
     posts.Add(newPost);
 }
Exemplo n.º 3
0
 // Genererar en Post med slumpade fält.
 private static Post GenerateSinglePost(Random rng, List<string> postTitles, List<string> postBodies, List<Guid> UserIDs)
 {
     int userIndex = rng.Next(UserIDs.Count - 1);
     int postTitleIndex = rng.Next(postTitles.Count - 1);
     int postBodyIndex = rng.Next(postBodies.Count - 1);
     int dayOffset = -1 * rng.Next(60);
     int hourOffset = -1 * rng.Next(23);
     int minuteOffset = -1 * rng.Next(59);
     List<Post.PostTags> tagList = GenerateTagList(rng);
     Post newPost = new Post { CreatedByID = UserIDs[userIndex], Title = postTitles[postTitleIndex], Body = postBodies[postBodyIndex], CreateDate = DateTime.Now.AddDays(dayOffset).AddHours(hourOffset).AddMinutes(minuteOffset), Tags = tagList };
     return newPost;
 }