Created
June 18, 2012 19:18
-
-
Save danielwertheim/2950174 to your computer and use it in GitHub Desktop.
StartNewProjectValidator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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