public async Task <bool> UpdateCollateral(CollateralModel c, int id) { try { using (SQLiteConnection conn = new SQLiteConnection(Database.LoadConnectionString())) { conn.Open(); cmd = new SQLiteCommand($"UPDATE Collaterals SET Item = '{c.Item}', Value ='{c.Value}', Description = '{c.Description}'" + $" WHERE LoanId = '{id}'", conn); int result = await cmd.ExecuteNonQueryAsync(); if (result > 0) { return(true); } else { msg = "Failed to update Collateral"; } } } catch (Exception ex) { msg = ex.Message; } return(false); }
public async Task <bool> AddCollateral(CollateralModel c, int id) { try { using (SQLiteConnection conn = new SQLiteConnection(Database.LoadConnectionString())) { conn.Open(); cmd = new SQLiteCommand("INSERT INTO Collaterals (LoanId, Item, Value, Description)" + $"VALUES('{id}', '{c.Item}','{c.Value}','{c.Description}')", conn); int result = await cmd.ExecuteNonQueryAsync(); if (result > 0) { return(true); } else { msg = "Failed to add Collateral"; } } } catch (Exception ex) { msg = ex.Message; } return(false); }
public async Task <bool> Update(ILoanModel l, GuarantorModel g, CollateralModel c) { try { if (await UpdateCollateral(c, l.Id) && await UpdateGuarantor(g, l.Id)) { msg = "Loan is Updated Successfully!"; return(true); } msg = "Failed To Update Loan"; } catch (Exception ex) { msg = ex.Message; } return(false); }
public async Task <bool> Add(ILoanModel l, GuarantorModel g, CollateralModel c) { try { using (SQLiteConnection conn = new SQLiteConnection(Database.LoadConnectionString())) { conn.Open(); string year = Convert.ToString(DateTime.Now.Year); string query = "INSERT INTO Loans (BorrowerId, CollectorId, PrincipalLoan, InterestId, Interest, MaturityValue," + "PerRemittance, Duration, EffectiveDate, MaturityDate,TotalBalance, Prefix) " + $"VALUES('{l.BorrowerId}','{l.CollectorId}','{l.PrincipalLoan}','{l.InterestId}','{l.Interest}','{l.MaturityValue}','{l.PerRemittance}','{l.Duration}'," + $"'{l.EffectiveDate.ToShortDateString()}', '{l.MaturityDate.ToShortDateString()}', '{l.TotalBalance}', '{year}')"; cmd = new SQLiteCommand(query, conn); int result = await cmd.ExecuteNonQueryAsync(); if (result > 0) { cmd = new SQLiteCommand("SELECT last_insert_rowid()", conn); Int64 id = Convert.ToInt64(await cmd.ExecuteScalarAsync()); int _loanId = (int)id; loanId = _loanId; if (await AddCollateral(c, _loanId) && await AddGuarantor(g, loanId)) { msg = "New Loan is Added Successfully!"; return(true); } else { msg = "Failed to add collateral and guarantor"; } } else { msg = "Failed to Add New Loan! Please try again."; } } } catch (Exception ex) { msg = ex.Message; } return(false); }
public async Task <CollateralModel> GetColleteral(int id) { dt.Clear(); CollateralModel collateral = new CollateralModel(); using (SQLiteConnection conn = new SQLiteConnection(Database.LoadConnectionString())) { string query = $"SELECT * FROM Collaterals WHERE LoanId = '{id}';"; conn.Open(); cmd = new SQLiteCommand(query, conn); await cmd.ExecuteNonQueryAsync(); da = new SQLiteDataAdapter(cmd); da.Fill(dt); DataRow c = dt.Rows[0]; collateral.Id = Convert.ToInt32(c["Id"]); collateral.Item = Convert.ToString(c["Item"]); collateral.Description = Convert.ToString(c["Description"]); collateral.Value = Convert.ToDecimal(c["Value"]); } return(collateral); }