示例#1
0
 public static Result <SubjectId> Create(long subjectId, ISubjectExistenceValidator subjectExistenceValidator)
 {
     return(Result.Create(() => subjectId > 0, DomainErrors.BuildInvalidIdentifier(subjectId))
            .AndEnsure(() => subjectExistenceValidator.Exist(subjectId),
                       DomainErrors.BuildNotFound("Subject", subjectId))
            .OnSuccess(() => new SubjectId(subjectId)));
 }
 public ExamsController(IMediator mediator, ISubjectExistenceValidator subjectExistenceValidator,
                        ILocationExistenceValidator locationExistenceValidator,
                        IExamExistenceValidator examExistenceValidator) : base(mediator)
 {
     _subjectExistenceValidator  = subjectExistenceValidator;
     _locationExistenceValidator = locationExistenceValidator;
     _examExistenceValidator     = examExistenceValidator;
 }
        public static Result <CreateExamCommand> Create(CreateExamRequest request,
                                                        ISubjectExistenceValidator subjectExistenceValidator,
                                                        ILocationExistenceValidator locationExistenceValidator)
        {
            var subjectId = SubjectId.Create(request.SubjectId, subjectExistenceValidator)
                            .BindErrorsTo(nameof(request.SubjectId));
            var locationId = LocationId.Create(request.LocationId, locationExistenceValidator)
                             .BindErrorsTo(nameof(request.LocationId));
            var examDateTime = UtcDateTime.Create(request.ExamDateTime)
                               .BindErrorsTo(nameof(request.ExamDateTime));
            var capacity = Capacity.Create(request.Capacity)
                           .BindErrorsTo(nameof(request.Capacity));
            var registrationStartDate = UtcDate.Create(request.RegistrationStartDate)
                                        .BindErrorsTo(nameof(request.RegistrationStartDate));
            var registrationEndDate = UtcDate.Create(request.RegistrationEndDate)
                                      .BindErrorsTo(nameof(request.RegistrationEndDate));

            return(Result.Combine(subjectId, locationId, examDateTime, capacity, registrationStartDate,
                                  registrationEndDate)
                   .OnSuccess(() => new CreateExamCommand(subjectId.Value, locationId.Value, examDateTime.Value,
                                                          capacity.Value, registrationStartDate.Value, registrationEndDate.Value)));
        }