public async Task <HttpResponseMessage> PostContractorBill(string token, ContractorBillModel billData)
 {
     try
     {
         httpClient.DefaultRequestHeaders.Clear();
         httpClient.DefaultRequestHeaders.Accept.Clear();
         httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         httpClient.DefaultRequestHeaders.Add("Authorization", $"bearer {token}");
         using (HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/ContractorBills", billData))
         {
             return(response);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        private async Task CreateBill()
        {
            try
            {
                if (!(IsPayment || IsBill))
                {
                    MessageBox.Show("Please select either a Bill or Payment Option", "Option Required", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else if (Amount <= 0)
                {
                    MessageBox.Show("Please enter an amount", "Amount Required", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else if (BillNo.Trim().Length == 0)
                {
                    MessageBox.Show("Please enter Bill Number", "Bill Number Required", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else if (IsPayment && SelectedPaymentMode == null)
                {
                    MessageBox.Show("Please select Payment Mode", "Payment Mode Required", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    CanBill = false;
                    if (IsBill)
                    {
                        ContractorBillModel billData = new ContractorBillModel
                        {
                            ContractorID = Contractor.ID,
                            ProjectID    = ParentLayout.SelectedProject.ID,
                            BillNo       = BillNo,
                            BillDate     = BillDate,
                            Amount       = Amount,
                            Remarks      = Remarks,
                            Status       = true,
                            CreatedOn    = DateTime.Now,
                            CreatedBy    = ParentLayout.LoggedInUser.Name
                        };


                        HttpResponseMessage result = await apiHelper.PostContractorBill(ParentLayout.LoggedInUser.Token, billData).ConfigureAwait(false);

                        if (result.IsSuccessStatusCode)
                        {
                            MessageBox.Show($"Bill Added Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                            await GetBills();

                            ClearFields();
                        }
                        else
                        {
                            MessageBox.Show("Error in adding bill", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else if (IsPayment)
                    {
                        ContractorPaymentModel paymentData = new ContractorPaymentModel
                        {
                            ContractorBillID = SelectedBill.ID,
                            PaidOn           = BillDate,
                            Amount           = Amount,
                            PaymentModeID    = SelectedPaymentMode.ID,
                            Remarks          = Remarks,
                            Status           = true,
                            CreatedOn        = DateTime.Now,
                            CreatedBy        = ParentLayout.LoggedInUser.Name
                        };


                        HttpResponseMessage result = await paymentApiHelper.PostContractorPayment(ParentLayout.LoggedInUser.Token, paymentData).ConfigureAwait(false);

                        if (result.IsSuccessStatusCode)
                        {
                            MessageBox.Show($"Payment Added Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                            await GetBills();

                            ClearFields();
                        }
                        else
                        {
                            MessageBox.Show("Error in adding bill", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    CanBill = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                CanBill = true;
            }
        }