public async Task <HttpResponseMessage> SendTodoRequest(TaskDetail task, HttpMethod method, string url)
 {
     _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _auth.GetAuthAccessToken());
     if (task != null)
     {
         return(await _client.SendAsync(new HttpRequestMessage(method, url)
         {
             Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(task), System.Text.Encoding.UTF8, "application/json")
         }));
     }
     else
     {
         return(await _client.GetAsync(url));
     }
 }
Example #2
0
        private async Task <HttpResponseMessage> UpdateMyPicture(System.IO.Stream file, string fileName)//UpdateMyProfilePictureCommand command)
        {
            try
            {
                var formData = new MultipartFormDataContent();
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _authHandler.GetAuthAccessToken());

                var content = new StreamContent(file);                                                 //command.ProfilePicture.OpenReadStream());
                formData.Add(content, nameof(UpdateMyProfilePictureCommand.ProfilePicture), fileName); // command.ProfilePicture.FileName);

                var response = await _httpClient.PutAsync("api/Profiles/MyProfile/ProfileImage", formData);

                if (response.IsSuccessStatusCode)
                {
                    formData.Dispose();

                    //var commandResult = await response.Content.ReadFromJsonAsync<UpdateMyProfilePictureCommandResult>();

                    //var profile = new ProfileDto();

                    //profile.ProfilePictureUrl = commandResult.ProfilePictureUrl;

                    //_profileSubject.OnNext(profile);
                    //_apiCallResultSubject.OnNext(new ApiCallResult<string>()
                    //{
                    //  IsSucceed = true,
                    //  Operation = "UpdateMyProfilePicture"
                    //});
                }
                return(response);
            }
            catch (Exception ex)
            {
                _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                {
                    IsSucceed    = false,
                    Operation    = "UpdateMyProfilePicture",
                    ErrorMessage = ex.Message
                });
                return(null);
            }
        }
Example #3
0
 private async Task <AuthenticationHeaderValue> GetToken()
 {
     return(_http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _auth.GetAuthAccessToken()));
 }
Example #4
0
        public async Task GetCustomer(GetCustomerDetailByEmailQuery query)
        {
            try
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _authHandler.GetAuthAccessToken());

                var response = await _httpClient.GetFromJsonAsync <GetCustomerDetailByEmailQueryResult>($"api/Customers?email={query.Email}");

                if (response.Payload != null)
                {
                    _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                    {
                        IsSucceed = true,
                        Operation = "GetStripeCustomerByEmail",
                        Payload   = response.Payload
                    });
                }

                else
                {
                    _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                    {
                        IsSucceed = false,
                        Operation = "GetStripeCustomerByEmail"
                    });
                }
            }

            catch (Exception ex)
            {
                _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                {
                    IsSucceed    = false,
                    Operation    = "GetStripeCustomerByEmail",
                    ErrorMessage = ex.Message
                });
            }
        }
        public async Task GetAllPlans()
        {
            try
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _authHandler.GetAuthAccessToken());
                var result = await _httpClient.GetFromJsonAsync <GetAllSubscriptionPlansQueryResult>("api/PayPal/GetAllSubscriptionPlans");

                _plansSubject.OnNext(result.Plans);

                _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                {
                    IsSucceed = true,
                    Operation = "GetAllPlans"
                });
            }

            catch (Exception ex)
            {
                _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                {
                    IsSucceed    = false,
                    Operation    = "GetAllPlans",
                    ErrorMessage = ex.Message
                });
            }
        }
        public async Task CreateTask(CreateTaskCommand command)
        {
            try
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _authHandler.GetAuthAccessToken());
                var response = await _httpClient.PostAsJsonAsync <CreateTaskCommand>("api/Tasks", command);

                if (response.IsSuccessStatusCode)
                {
                    var commandResult = await response.Content.ReadFromJsonAsync <CreateTaskCommandResult>();

                    var tasks = new List <TaskDto>(_tasksSubject.Value);
                    tasks.Add(commandResult.Payload);

                    _tasksSubject.OnNext(tasks);

                    _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                    {
                        IsSucceed = true,
                        Operation = "CreateTask"
                    });
                }
            }
            catch (Exception ex)
            {
                _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                {
                    IsSucceed    = false,
                    Operation    = "CreateTask",
                    ErrorMessage = ex.Message
                });
            }
        }