public static Result <LocationId> Create(long locationId, ILocationExistenceValidator locationExistenceValidator)
 {
     return(Result.Create(locationId > 0, DomainErrors.BuildInvalidIdentifier(locationId))
            .AndEnsure(() => locationExistenceValidator.Exist(locationId),
                       DomainErrors.BuildNotFound("Location", locationId))
            .OnSuccess(() => new LocationId(locationId)));
 }
 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)));
        }