Example #1
0
 /// <summary>
 /// Creates a new tag given the name, body of the wiki page and creator.
 /// </summary>
 /// <param name="name">The name of the tag to create.</param>
 /// <param name="wikiBody">The markdown body of the wiki page to create for the tag.</param>
 /// <param name="creator">The user who is the creator of the tag.</param>
 public Tag(string name, string wikiBody, User creator)
 {
     this.Name = name;
     if (wikiBody == null)
     {
         this.SetBody(string.Empty, creator);
     }
     else
     {
         this.SetBody(wikiBody, creator);
     }
     this.DateCreated = DateTime.UtcNow;
 }
Example #2
0
 /// <summary>
 /// Creates a new post that was posted at DateTime.UtcNow, posted by the given author with the given body.
 /// </summary>
 /// <param name="author"></param>
 /// <param name="body"></param>
 protected Post(User author, string body)
 {
     this.Author = author;
     this.DatePosted = DateTime.UtcNow;
     this.Edits.Add(new Edit
     {
         Accepted = true,
         Editor = author,
         Body = body,
         DateChanged = DateTime.UtcNow,
         OriginalPost = this,
         PreviousVersion = null
     });
 }
Example #3
0
 /// <summary>
 /// Determines if the given user has (can use) the provided permission.
 /// </summary>
 /// <param name="user">The user to test against.</param>
 /// <param name="permission">The permission to test for access to.</param>
 /// <returns></returns>
 public static bool HasPermission(User user, UserPermission permission)
 {
     switch (permission)
     {
         case UserPermission.UpVote:
             return user.Reputation >= Settings.Permissions.UpVote;
         case UserPermission.DownVote:
             return user.Reputation >= Settings.Permissions.DownVote;
         case UserPermission.Flag:
             return user.Reputation >= Settings.Permissions.Flag;
         case UserPermission.Edit:
             return user.Reputation >= Settings.Permissions.Edit;
     }
     return false;
 }
Example #4
0
 public Answer(User author, string body, Question question, bool accepted = false)
     : base(author, body)
 {
     this.Question = question;
     this.Accepted = accepted;
 }
Example #5
0
 /// <summary>
 /// Sets the content of the body by creating a new edit by the given user.
 /// </summary>
 public void SetBody(string newBody, User editor)
 {
     if (newBody != null && editor != null)
     {
         Edits.Add(new TagEdit
         {
             Body = newBody,
             DateChanged = DateTime.UtcNow,
             Editor = editor,
             OriginalTag = this,
             PreviousVersion = Edits.OrderByDescending(a => a.DateChanged).FirstOrDefault()
         });
     }
 }
Example #6
0
 /// <summary>
 /// Creates a new proposed edit using the given body and editor based off of the previous edit.
 /// </summary>
 /// <param name="proposedBody"></param>
 /// <param name="editor"></param>
 public void ProposeEdit(string proposedBody, User editor)
 {
     if (proposedBody != null && editor != null)
     {
         Edits.Add(new Edit
         {
             Accepted = false,
             Body = proposedBody,
             DateChanged = DateTime.UtcNow,
             Editor = editor,
             OriginalPost = this,
             PreviousVersion = Edits.OrderByDescending(a => a.DateChanged).FirstOrDefault()
         });
     }
 }
Example #7
0
 public Question(User author, string body, string title, IList<Tag> tags)
     : base(author, body)
 {
     this.Title = title;
     this.Tags = tags;
 }
Example #8
0
 public Question(User author, string body, string title, IEnumerable<Tag> tags)
     : base(author, body)
 {
     this.Title = title;
     this.Tags = tags.ToList();
 }