Skip to content

Instantly share code, notes, and snippets.

@danielwertheim
Created June 18, 2012 19:18
Show Gist options
  • Select an option

  • Save danielwertheim/2950174 to your computer and use it in GitHub Desktop.

Select an option

Save danielwertheim/2950174 to your computer and use it in GitHub Desktop.
StartNewProjectValidator
public class StartNewProjectValidator : ICommandValidator<StartNewProject>
{
protected readonly ISisoDatabase Readstore;
public StartNewProjectValidator(ISisoDatabase readstore)
{
Readstore = readstore;
}
public virtual ViolationsContainer Validate(StartNewProject cmd)
{
var validator = new ObjectValidator<StartNewProject>();
return validator
.Require(
i => i.ProjectId != Guid.Empty,
i => new Violation("ProjectId", "The ProjectId is required", Violation.Types.Required))
.Require(
i => !string.IsNullOrWhiteSpace(i.Name),
i => new Violation("Name", "The Name is required", Violation.Types.Required))
.BreakIfAnyViolations()
.Require(
i => !Readstore.UseOnceTo().Query<ProjectEntity>().Any(e => e.Name == i.Name),
i => new Violation("ProjectName", "The Project name must be unique.", Violation.Types.NotUnique))
.Validate(cmd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment