hn-dotnet/Domain/Link.cs
2020-12-10 18:37:46 +01:00

43 lines
864 B
C#

using System;
using System.Collections.Generic;
namespace HN.Domain
{
public sealed class Link
{
public Guid Id { get; }
public string Url { get; }
public DateTime CreatedAt { get; }
private List<Vote> _votes;
public IReadOnlyList<Vote> Votes { get { return _votes; } }
private Link(string url)
{
this.Id = Guid.NewGuid();
this.CreatedAt = DateTime.UtcNow;
this.Url = url;
this._votes = new List<Vote>();
}
public static Link FromUrl(string url)
{
return new Link(url);
}
public void Upvote()
{
_votes.Add(new Vote(VoteType.Up));
}
public void Downvote()
{
_votes.Add(new Vote(VoteType.Down));
}
public Comment AddComment(string content)
{
return new Comment(Id, content);
}
}
}