public async Task <HttpResponseMessage> PostSupplierBill(string token, SupplierBillModel 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/SupplierBills", 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) { SupplierBillModel billData = new SupplierBillModel { SupplierID = Supplier.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.PostSupplierBill(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) { SupplierPaymentModel paymentData = new SupplierPaymentModel { SupplierBillID = SelectedBill.ID, PaidOn = BillDate, Amount = Amount, PaymentModeID = SelectedPaymentMode.ID, Remarks = Remarks, Status = true, CreatedOn = DateTime.Now, CreatedBy = ParentLayout.LoggedInUser.Name }; HttpResponseMessage result = await paymentApiHelper.PostSupplierPayment(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; } }