private async void OnSave(object sender, EventArgs e) { string billNo = await Utils.GetBillNo(_party.PartyType); List <Transaction> transactions = new List <Transaction>(); int gridRowCount = itemList.Children.Select(c => Grid.GetRow(c)).Max(); for (int i = 1; i <= gridRowCount; i++) { var itemNameLabel = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 0).FirstOrDefault() as Label; if (string.IsNullOrWhiteSpace(itemNameLabel.Text)) { continue; } var qtyEntry = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 1).FirstOrDefault() as Entry; if (string.IsNullOrWhiteSpace(qtyEntry.Text)) { await DisplayAlert("Error", "Qty is required", "OK"); return; } var mrpEntry = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 2).FirstOrDefault() as Entry; if (string.IsNullOrWhiteSpace(mrpEntry.Text)) { mrpEntry.Text = "0"; } var amountEntry = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 3).FirstOrDefault() as Entry; if (string.IsNullOrWhiteSpace(amountEntry.Text)) { amountEntry.Text = "0"; } transactions.Add(new Transaction { BillNo = billNo, TransactionType = Utils.GetTransactionType(_party.PartyType), PartyName = _party.PartyName, PartyType = _party.PartyType, City = _party.City, ItemName = itemNameLabel.Text, Qty = qtyEntry.Text, MRP = mrpEntry.Text, Amount = amountEntry.Text, CreatedDate = DateTime.Now }); } DbTransaction dbTransaction = DbTransaction.GetInstance(); dbTransaction.InsertAllAsync(transactions); Register register = new Register { BillNo = billNo, TransactionDate = DateTime.Now, PartyName = _party.PartyName, City = _party.City, TransactionType = Utils.GetTransactionType(_party.PartyType), Amount = transactions.Sum(t => Utils.ToDecimal(t.Amount)).ToString() }; dbTransaction.InsertAsync(register); await DisplayAlert("Success", $"Bill No: {billNo} generated", "OK"); OnClear(null, null); }