Skip to content

Instantly share code, notes, and snippets.

@explorer14

explorer14/DomainModel.cs Secret

Created Dec 22, 2019
Embed
What would you like to do?
public class Blog
{
private readonly List<Post> posts = new List<Post>();
public string Name { get; }
public Guid Id { get; }
public IReadOnlyCollection<Post> Posts => posts.AsReadOnly();
private Blog()
{
}
public Blog(string name)
{
Name = name;
Id = Guid.NewGuid();
}
public void CreatePost(string title, string content)
{
this.posts.Add(new Post(title, content));
}
public void RemovePost(Guid postId)
{
var postToRemove = posts.FirstOrDefault(x => x.Id == postId);
if (postToRemove != null)
{
posts.Remove(postToRemove);
}
}
}
public class Post
{
public string Title { get; }
public string Content { get; }
public Guid Id { get; }
private Post()
{
}
public Post(string title, string content)
{
Id = Guid.NewGuid();
Title = title;
Content = content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.