private async void BtnSaveDisease_Clicked(object sender, EventArgs e)
        {
            DateTime date = DateTime.UtcNow;
            //Detele API service call DeleteDonorHealthAsync
            await ApiService.DeleteDonorHealthAsync(DonorId, accessToken);

            //disease.Count
            foreach (var disease in diseases)
            {
                Console.WriteLine(disease);
                var donorHealth = new DonorHealth
                {
                    DonorId     = DonorId,
                    Disease     = disease,
                    AddedBy     = userName,
                    AddedDate   = date,
                    UpdatedBy   = userName,
                    UpdatedDate = date
                };
                await ApiService.PostDonorHealtAsync(donorHealth, accessToken);
            }
            diseases.Clear();
            Console.WriteLine(diseases);
            await DisplayAlert("Success!", "Donor details saved successfully", "OK");

            await Navigation.PushModalAsync(new HomePage());
        }
Example #2
0
        //#region Update donorHealth Details by donorId
        //public static async Task PutDonorHealtAsync(DonorHealth donorHealth, string accessToken)
        //{
        //    var client = new HttpClient();
        //    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

        //    var json = JsonConvert.SerializeObject(donorHealth);
        //    HttpContent content = new StringContent(json);
        //    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        //    var response = await client.PutAsync(
        //        Constants.ApiUrl + "Disease/SetDonorHealthId?DonorId=" + donorHealth.DonorId, content);
        //}
        //#endregion

        #region Add donorHealth Details by donorId
        public static async Task PostDonorHealtAsync(DonorHealth donorHealth, string accessToken)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            var         json    = JsonConvert.SerializeObject(donorHealth);
            HttpContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var response = await client.PostAsync(Constants.ApiUrl + "Disease/SetDonorHealthId?DonorId=" + donorHealth.DonorId, content);
        }