public async Task <string> InsertBillDetail(BillDetailPostModel model) { try { BillDetailsTable bills = new BillDetailsTable() { BillDetailId = Guid.NewGuid().ToString(), BillId = model.BillId, Name = model.Name, Quantity = decimal.Parse(model.Quantity.Replace(".", ",")), Rate = decimal.Parse(model.Rate.Replace(".", ",")), Amount = decimal.Parse(model.Amount.Replace(".", ",")), }; await db.BillDetails.AddAsync(bills); await db.SaveChangesAsync(); return("Success"); } catch (Exception x) { return(x.Message.ToString()); } }
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); }
public async Task <string> Create(BillPostModel model, BillDetailPostModel billDetailPost) { await MasterHelpers.AddBill(model, billDetailPost); return(model.Number + " successfully added"); }