예제 #1
0
        public async Task <ResponseViewModel> CreateAsync(UserCreateRequestViewModel request)
        {
            using (_unitOfWork)
            {
                // Inicia a transação
                _unitOfWork.BeginTransaction();

                // Adiciona o Perfil
                ProfileCreateCommand profileCreateCommand  = new ProfileCreateCommand(Convert.ToInt32(request.IdType), Guid.NewGuid().ToString(), request.Avatar, request.CpfCnpj, request.Address);
                ResponseCommand      profileCreateResponse = await _mediator.Send(profileCreateCommand, CancellationToken.None).ConfigureAwait(true);

                if (!profileCreateResponse.Success)
                {
                    return(new ResponseViewModel(false, profileCreateResponse.Object));
                }

                // Adiciona o Usuário
                UserCreateCommand userCreateCommand  = new UserCreateCommand((int)profileCreateResponse.Object, Guid.NewGuid().ToString(), request.Name, request.Email);
                ResponseCommand   userCreateResponse = await _mediator.Send(userCreateCommand, CancellationToken.None).ConfigureAwait(true);

                if (!userCreateResponse.Success)
                {
                    return(new ResponseViewModel(false, userCreateResponse.Object));
                }

                // Comita e Retorna
                _unitOfWork.CommitTransaction();
                return(new ResponseViewModel(true, "User created"));
            }
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] UserCreateRequestViewModel request)
        {
            ResponseViewModel response = await _userAppService.CreateAsync(request).ConfigureAwait(true);

            return(Ok(response));
        }