public async Task <ActionResult> AddFundsToClinetAsync(int id, AddFundsToAccountRequestModel request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Call made to AddFundsToClinetAsync.");

            var command   = request.ToAddFundsToClientCommand(id);
            var accountId = await _mediator.Send(command, cancellationToken);

            var response = new CreateAccountResponseModel {
                AccountId = accountId
            };

            return(new ObjectResult(response)
            {
                StatusCode = StatusCodes.Status201Created
            });
        }
Ejemplo n.º 2
0
        public async Task <CreateAccountResponseModel> Post(CreateAccountRequestModel model)
        {
            CreateAccountResponseModel responseModel = new CreateAccountResponseModel();

            try
            {
                string token = _configuration.GetSection("Auth0").GetSection("Token").Value;
                string url   = _configuration.GetSection("Auth0").GetSection("Url").Value;
                Dictionary <string, string> metadata = new Dictionary <string, string>();
                metadata.Add("DeviceID", model.DeviceId);

                using var client = new ManagementApiClient(token, new Uri(url));
                var response = await client.Users.CreateAsync(new UserCreateRequest
                {
                    Connection   = "Username-Password-Authentication",
                    Email        = model.Email,
                    Password     = model.Password,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    UserMetadata = metadata
                });

                if (!String.IsNullOrEmpty(response.UserId))
                {
                    responseModel.IsSuccess    = true;
                    responseModel.ErrorMessage = string.Empty;
                    responseModel.UserId       = response.UserId;
                }
                else
                {
                    responseModel.ErrorMessage = "Failed to create new user";
                }
            }
            catch (Exception ex)
            {
                responseModel.IsSuccess    = false;
                responseModel.ErrorMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                _logger.LogError(ex.ToString());
            }

            return(responseModel);
        }