Beispiel #1
0
        public async Task Upload(VoygerBill vBill)
        {
            //TODO: Here implement or add function to convert payment mode to PayModes unit. so less amount of data will be uploaded
            VoyagerBillInfo bill = new VoyagerBillInfo()
            {
                Amount     = (decimal)vBill.bill.BillAmount,
                BillDate   = vBill.bill.BillTime ?? DateTime.Now,
                ImportDate = DateTime.Now,
                InvoiceNo  = vBill.bill.BillNumber,
                IsUsed     = false,
                PayModes   = 0
            };

            LogEvent.WriteEvent($"UploadFunctionStated with: {bill.VoyagerBillId}");

            await UploadBill(bill);
        }
Beispiel #2
0
        private async Task UploadBill(VoyagerBillInfo bill)
        {
            // Update port # in the following line.
            client.BaseAddress = new Uri(DataConstant.API_URL);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            LogEvent.WriteEvent($"Invoice Uploader with bill {bill.InvoiceNo} with Base address {client.BaseAddress.AbsoluteUri} .");

            try
            {
                var url = await AddBill(bill);

                LogEvent.WriteEvent($"Invoice Upload with url : {url}");
            }
            catch (Exception e)
            {
                LogEvent.WriteEvent("UploadBill: " + e.Message);
                LogEvent.WriteEvent("UpLoadBillError:" + e.StackTrace);
            }
        }
Beispiel #3
0
        private async Task <Uri> AddBill(VoyagerBillInfo bill)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync("api/VoyagerBills", bill);

            LogEvent.WriteEvent("Header:" + response.Headers.ToString());
            LogEvent.WriteEvent("Content:" + response.Content.ToString());
            LogEvent.WriteEvent("Status Code:" + response.StatusCode.ToString());

            response.EnsureSuccessStatusCode();

            if (response.IsSuccessStatusCode)
            {
                LogEvent.WriteEvent("Invocie is saved: " + bill.InvoiceNo);
                using (VoyagerContext db = new VoyagerContext())
                {
                    InsertDataLog log = db.InsertDataLogs.Where(c => c.BillNumber == bill.InvoiceNo).FirstOrDefault();
                    log.Remark          = response.Content.ToString();
                    db.Entry(log).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(response.Headers.Location);
        }