Example #1
0
        public async Task <(PaymentReqRespModel, ModelStateDictionary)> PostAsync(PaymentReqModel paymentReqModel, ModelStateDictionary modelStateDictionary)
        {
            string paymentReqModelAsString = JsonConvert.SerializeObject(paymentReqModel);

            StringContent stringContent = new StringContent(paymentReqModelAsString, Encoding.UTF8, "application/json");

            (PaymentReqRespModel paymentReqRespModel, string errorMessage) = await httpClientManager.PostAsync <PaymentReqRespModel>(endpointOptions?.Value.Endpoint, stringContent);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                modelStateDictionary.AddModelError("Payment", _Failed_ToPostPayment);
            }

            return(paymentReqRespModel, modelStateDictionary);
        }
Example #2
0
        public async Task <UserRoleDTO> Create(UserRoleDTO user)
        {
            string url     = _config["App:IdentityServerAddress"] + "api/users/";
            var    content = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _client.PostAsync(new Uri(url), content);

            if (response.IsSuccessStatusCode)
            {
                using (HttpContent result = response.Content)
                {
                    string responseBody = await response.Content.ReadAsStringAsync();

                    var createdUser = JsonConvert.DeserializeObject <UserRoleDTO>(responseBody);
                    return(createdUser);
                }
            }
            else
            {
                var result = response.Content.ReadAsStringAsync().Result;
                throw new UserFriendlyException(result);
            }
        }