public async Task <IEnumerable <CollectionModel> > GetAll() { List <CollectionModel> collections = new List <CollectionModel>(); try { using (SQLiteConnection conn = new SQLiteConnection(Database.LoadConnectionString())) { dt.Clear(); conn.Open(); string query = "SELECT * FROM Collections"; cmd = new SQLiteCommand(query, conn); await cmd.ExecuteNonQueryAsync(); da = new SQLiteDataAdapter(cmd); da.Fill(dt); Loans loans = new Loans(); Borrowers borrowers = new Borrowers(); foreach (DataRow row in dt.Rows) { LoanModel l = await loans.GetSingle(Convert.ToInt32(row["LoanId"])); BorrowerModel b = await borrowers.GetSingle(Convert.ToInt32(row["BorrowerId"])); collections.Add(new CollectionModel() { Id = Convert.ToInt32(row["Id"]), Amount = Convert.ToDecimal(row["Amount"]), Date = Convert.ToDateTime(row["Date"]), Borrower = b, Loan = l }); } } } catch (Exception e) { msg = e.Message; } return(collections); }
public async Task <CollectablesModel> GetSingle(int id) { CollectablesModel collectables = new CollectablesModel(); try { using (SQLiteConnection conn = new SQLiteConnection(Database.LoadConnectionString())) { dt.Clear(); conn.Open(); string query = $"SELECT * FROM Collectables WHERE LoanId = '{id}'"; cmd = new SQLiteCommand(query, conn); await cmd.ExecuteNonQueryAsync(); da = new SQLiteDataAdapter(cmd); da.Fill(dt); DataRow row = dt.Rows[0]; Loans loans = new Loans(); Borrowers borrowers = new Borrowers(); LoanModel l = await loans.GetSingle(Convert.ToInt32(row["LoanId"])); BorrowerModel b = await borrowers.GetSingle(Convert.ToInt32(row["BorrowerId"])); collectables.Id = Convert.ToInt32(row["Id"]); collectables.DueDate = Convert.ToDateTime(row["DueDate"]); collectables.Loan = l; collectables.Borrower = b; } } catch (Exception e) { msg = e.Message; } return(collectables); }