private ErrorManager Validate(DeveloperUpdateCommand command) { return(new ErrorManager() .NoDuplicate(command.Experiences, x => new { x.Position, x.Company }, exp => $"The experience of '{exp.Position}' at '{exp.Company}' is duplicated") .Conditional( cond => cond.CheckPeriods(command.Experiences, x => x.StartDate, x => x.EndDate, exp => $"StartDate of '{exp.Company}' is greater than it's EndDate"), then => then.NoOverlaps(command.Experiences, x => x.StartDate, x => x.EndDate, (exp, others) => $"The experiences of '{exp.Company}' overlaps with '{string.Join(", ", others.Select(x => x.Company))}'")) .NoDuplicate(command.SideProjects, x => x.Title, proj => $"The side project of '{proj.Title}' is duplicated") .NoDuplicate(command.Educations, x => new { x.Degree, x.University }, edu => $"The education of '{edu.Degree}' in '{edu.University}' is duplicated") .Conditional( cond => cond.CheckPeriods(command.Educations, x => x.StartDate, x => x.EndDate, edu => ""), then => then.NoOverlaps(command.Educations, x => x.StartDate, x => x.EndDate, (edu, others) => $"The education of '{edu.University}' overlaps with '{string.Join(", ", others.Select(x => x.University))}'"))); }
private void UpdateAggregates(DeveloperUpdateCommand command) { _summary = command.Summary; Skills = command.Skills; Update(_experiences, command.Experiences, AddExperience); Update(_sideProjects, command.SideProjects, AddSideProject); Update(_educations, command.Educations, AddEducation); }
public static DeveloperFactoryResult Create(DeveloperUpdateCommand command) { var dev = new Developer(); var errorManager = new ErrorManager() .Add(dev.Update(command).Errors) .NotEmpty(command.Experiences, "Experiences"); if (errorManager.Dirty) { return(DeveloperFactoryResult.MakeFailure(errorManager)); } return(DeveloperFactoryResult.MakeSuccess(dev)); }
public CommandResult Update(DeveloperUpdateCommand command) { if (command == null) { throw new ArgumentNullException("command"); } var errorManager = Validate(command); if (errorManager.Dirty) { return(new CommandResult(errorManager.Errors)); } UpdateAggregates(command); return(new CommandResult(Enumerable.Empty <string>())); }