Example #1
0
        public async Task <string> InsertBills(BillPostModel model)
        {
            try
            {
                DateTime   date  = DateTime.ParseExact(model.Date.ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture);
                BillsTable bills = new BillsTable()
                {
                    BillId          = model.BillId,
                    Number          = model.Number,
                    LanguangeId     = model.LanguangeId,
                    CurrencyId      = model.CurrencyId,
                    From            = model.From,
                    DestinationId   = model.DestinationId,
                    Date            = date,
                    InvoiceDue      = model.InvoiceDue,
                    PurchaseOrderId = model.PurchaseOrderId,
                    MeasurementId   = model.MeasurementId,
                    SubTotal        = decimal.Parse(model.SubTotal.Replace(".", ",")),
                    Discount        = decimal.Parse(model.Discount.Replace(".", ",")),
                    Total           = decimal.Parse(model.Total.Replace(".", ",")),
                    DiscountName    = model.DiscountName,
                    Status          = model.Status,
                };
                await db.Bills.AddAsync(bills);

                await db.SaveChangesAsync();

                return(bills.Number + " successfully added");
            }
            catch (Exception x)
            {
                return(x.Message.ToString());
            }
        }
Example #2
0
        public static async Task <bool> AddBill(BillPostModel model, BillDetailPostModel billDetailPostModel)
        {
            string url  = Startup.RestUrl + "/Bills/InsertBills";
            string url2 = Startup.RestUrl + "/Bills/InsertBillDetail";

            if (string.IsNullOrEmpty(model.From))
            {
                model.From = "-";
            }
            if (string.IsNullOrEmpty(model.Date))
            {
                model.Date = DateTime.Now.ToString("MM/dd/yyyy");
            }
            if (string.IsNullOrEmpty(model.InvoiceDue))
            {
                model.InvoiceDue = "-";
            }
            if (string.IsNullOrEmpty(model.Status))
            {
                model.Status = "-";
            }
            if (string.IsNullOrEmpty(model.DiscountName))
            {
                model.DiscountName = "-";
            }
            if (string.IsNullOrEmpty(model.Discount))
            {
                model.Discount = "0.0";
            }
            if (string.IsNullOrEmpty(model.SubTotal))
            {
                model.SubTotal = "0.0";
            }
            if (string.IsNullOrEmpty(model.Total))
            {
                model.Total = "0.0";
            }
            string billId = Guid.NewGuid().ToString();

            model.BillId = billId;
            var    client   = new HttpClient();
            string jsonText = JsonConvert.SerializeObject(model);
            var    content  = new StringContent(jsonText, System.Text.Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(url, content);

            if (response.IsSuccessStatusCode)
            {
                if (string.IsNullOrEmpty(billDetailPostModel.Quantity))
                {
                    billDetailPostModel.Quantity = "0.0";
                }
                if (string.IsNullOrEmpty(billDetailPostModel.Rate))
                {
                    billDetailPostModel.Rate = "0.0";
                }
                if (string.IsNullOrEmpty(billDetailPostModel.Amount))
                {
                    billDetailPostModel.Amount = "0.0";
                }
                if (string.IsNullOrEmpty(billDetailPostModel.Name))
                {
                    billDetailPostModel.Name = "-";
                }

                billDetailPostModel.BillId = billId;
                string jsonText2 = JsonConvert.SerializeObject(billDetailPostModel);
                var    content2  = new StringContent(jsonText2, System.Text.Encoding.UTF8, "application/json");
                HttpResponseMessage response2 = await client.PostAsync(url2, content2);

                if (response2.IsSuccessStatusCode)
                {
                    return(true);
                }
            }
            client.Dispose();
            return(false);
        }
Example #3
0
        public async Task <string> Create(BillPostModel model, BillDetailPostModel billDetailPost)
        {
            await MasterHelpers.AddBill(model, billDetailPost);

            return(model.Number + " successfully added");
        }