示例#1
0
        public HttpResponseMessage CreateExam([FromQuery] CreateExamRequest createExamRequest)
        {
            _examService.CreateExam(new Exam(createExamRequest.CourseId, createExamRequest.ExamDate,
                                             createExamRequest.Room,
                                             createExamRequest.StartTime, createExamRequest.EndTime, createExamRequest.CorrectionScorePostDate,
                                             createExamRequest.Type,
                                             createExamRequest.CorrectionScore));

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        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)));
        }
 public Task <IActionResult> Create(CreateExamRequest request)
 {
     return(CreatedOrUnprocessableEntityAsync <CreateExamCommand, ExamId>(
                CreateExamCommand.Create(request, _subjectExistenceValidator, _locationExistenceValidator),
                id => $"/api/exams/{id}"));
 }