コード例 #1
0
        //
        // Summary:
        //     /// Method responsible for initializing the schema. ///
        //
        // Parameters:
        //   interviewService:
        //     The interviewService param.
        //
        public InterviewMutationType(IInterviewService interviewService)
        {
            Name        = "InterviewMutation";
            Description = "Interview Mutation Type";

            FieldAsync <InterviewType>(
                name: "createInterview",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <InterviewInputType> > {
                Name = "data"
            }
                    ),
                resolve: async context =>
            {
                InterviewCommand data = context.GetArgument <InterviewCommand>("data");

                Interview result = await interviewService.AddAsync(data);

                if (interviewService.ValidationResult().IsValid is true)
                {
                    return(result);
                }

                context.Errors.AddRange(interviewService.ValidationResult().Errors.Select(x => new ExecutionError(x.ErrorMessage)));

                return(null);
            }
                );

            FieldAsync <BooleanGraphType>(
                name: "removeInterview",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                Guid id = context.GetArgument <Guid>("id");

                await interviewService.RemoveAsync(id);

                if (interviewService.ValidationResult().IsValid is true)
                {
                    return(true);
                }

                context.Errors.AddRange(interviewService.ValidationResult().Errors.Select(x => new ExecutionError(x.ErrorMessage)));

                return(null);
            }
                );
        }
コード例 #2
0
        //
        // Summary:
        //     /// Method responsible for create registry. ///
        //
        // Parameters:
        //   command:
        //     The command param.
        //
        public async Task <Interview> AddAsync(InterviewCommand command)
        {
            _validationResult = await _interviewValidator.ValidateAsync(command);

            if (_validationResult.IsValid is false)
            {
                return(null);
            }

            Person person = await _personRepository.FindAsync(command.PersonId);

            Interview interview = new Interview(command.SchedulingDate, command.Squad, person);

            await _interviewRepository.AddAsync(interview);

            await _entityAuditService.AddAsync("INS", nameof(Interview), interview);

            return(interview);
        }
コード例 #3
0
        //
        // Summary:
        //     /// Method responsible for update registry. ///
        //
        // Parameters:
        //   command:
        //     The command param.
        //
        //   id:
        //     The id param.
        //
        public async Task <Interview> UpdateAsync(InterviewCommand command, Guid id)
        {
            _validationResult = await _interviewValidator.ValidateAsync(command);

            if (_validationResult.IsValid is false)
            {
                return(null);
            }

            Interview interview = await _interviewRepository.FindAsync(id);

            interview.Update(command.SchedulingDate, command.Squad);

            await _interviewRepository.UpdateAsync(interview);

            await _entityAuditService.AddAsync("UPD", nameof(Interview), interview);

            return(interview);
        }
コード例 #4
0
        public async Task <IActionResult> Create([FromBody] InterviewCommand command)
        {
            if (command is null)
            {
                return(BadRequest());
            }

            Interview interview = await _interviewService.AddAsync(command);

            if (interview is null)
            {
                return(BadRequest(_interviewService.ValidationResult()
                                  .Errors
                                  .Select(x => new ValidationResult()
                {
                    PropertyName = x.PropertyName, ErrorMessage = x.ErrorMessage
                })));
            }

            return(Ok(_mapper.Map <Interview, InterviewResult>(interview)));
        }