Skip to content

Instantly share code, notes, and snippets.

@llytvynenko
Created November 23, 2014 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llytvynenko/ce872f9b38ed37c40b7f to your computer and use it in GitHub Desktop.
Save llytvynenko/ce872f9b38ed37c40b7f to your computer and use it in GitHub Desktop.
class CreateTheme
{
public int Id;
public int AccountId;
public string Name;
public Optional<string> Description;
}
static void Handle(IUnitOfWork uow, CreateTheme cmd)
{
var account = uow.Load<Account>(cmd.AccountId);
uow.Register(account.Create(cmd.Name, cmd.Description));
}
class Theme
{
public readonly int Id;
public readonly int AccountId;
public readonly string Name;
public readonly string Description;
public Theme(int id, int accountId, string name, string description)
{
Guard.Against(id < 1, ()=> Argument.Invalid("id should be greater than 0"));
Guard.AgainstNullOrEmpty(()=> name);
Id = id;
AccountId = accountId;
Name = name;
Description = description;
}
}
class Account
{
const int Max_Themes_Per_Account = 10;
readonly IList<Theme> themes = new List<Theme>();
public Theme Create(string name, string description)
{
if (themes.Count + 1 > Max_Themes_Per_Account)
throw MaxThemePerAccountLimitReached.Create(this, name);
return new Theme(themes.Count + 1, this.Id, name, description);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment