public async Task <IActionResult> TestPersonCommand([FromBody] PersonCommand request)
        {
            // See comments
            bool IsAdded = await mediator.Send(request);

            return(Ok($"Success on Add {IsAdded}"));
        }
        //
        // Summary:
        //     /// Method responsible for initializing the schema. ///
        //
        // Parameters:
        //   personService:
        //     The personService param.
        //
        public PersonMutationType(IPersonService personService)
        {
            Name        = "UserMutation";
            Description = "User Mutation Type";

            FieldAsync <PersonType>(
                name: "createPerson",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PersonInputType> > {
                Name = "data"
            }
                    ),
                resolve: async context =>
            {
                PersonCommand data = context.GetArgument <PersonCommand>("data");

                Person result = await personService.AddAsync(data);

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

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

                return(null);
            }
                );

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

                await personService.RemoveAsync(id);

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

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

                return(null);
            }
                );
        }
Beispiel #3
0
        public async Task <IActionResult> Postproduct(int seat)
        {
            var person = new PersonCommand()
            {
                Name = "Paulo"
            };
            var productCmd = ProjectRegisterCommandBuilder.Start().WithPerson(person).Build();

            var myContent     = JsonConvert.SerializeObject(productCmd);
            var stringContent = new StringContent(myContent, UnicodeEncoding.UTF8, "application/json");

            var result = await client.PostAsync("https://localhost:44301/api/projects", stringContent);

            return(Ok());
        }
Beispiel #4
0
        //
        // Summary:
        //     /// Method responsible for create registry. ///
        //
        // Parameters:
        //   command:
        //     The command param.
        //
        public async Task <Person> AddAsync(PersonCommand command)
        {
            _validationResult = await _personValidator.ValidateAsync(command);

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

            Person person = new Person(command.Name, command.BirthDate, new Cpf(command.Cpf), command.Phone, new Email(command.Email), command.Profile, command.ProfessionalDescription);

            await _personRepository.AddAsync(person);

            await _entityAuditService.AddAsync("INS", nameof(Person), person);

            return(person);
        }
        public void PostProjectReservation_IntegrationTest()
        {
            //arrange
            var personCommand = new PersonCommand()
            {
                Name = "Dienisson"
            };
            var projectCmd    = ProjectRegisterCommandBuilder.Start().WithPerson(personCommand).Build();
            var myContent     = JsonConvert.SerializeObject(projectCmd);
            var stringContent = new StringContent(myContent, UnicodeEncoding.UTF8, "application/json");

            //action
            var httpResponse = _client.PostAsync(_url, stringContent).Result;

            //assert
            httpResponse.EnsureSuccessStatusCode();

            CustomWebApplicationFactory <Startup> .appDb.Project.Count().Should().Be(2);
        }
Beispiel #6
0
        public async Task <IActionResult> Update([FromBody] PersonCommand command, Guid?id)
        {
            if (command is null || id is null)
            {
                return(BadRequest());
            }

            Person person = await _personService.UpdateAsync(command, (Guid)id);

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

            return(Ok(_mapper.Map <Person, PersonResult>(person)));
        }
 public ProjectRegisterCommandBuilder WithPerson(PersonCommand personCommand)
 {
     _command.personCommand = personCommand;
     return(this);
 }