// Add new expense to trip public static int AddNewExpenseToTrip(ExpenseModel expense, int tripID) { int currentExpenseNumber = 0; using (var cnn = new SQLiteConnection(LoadConnectionString())) { currentExpenseNumber = cnn.QueryFirst <int>($"SELECT IFNULL(MAX(NUMBER),0) FROM EXPENSE WHERE TRIPID = {tripID} "); cnn.Execute($"INSERT INTO EXPENSE VALUES ({tripID}, {currentExpenseNumber + 1}, @Name,@AmountMoney)", expense); } return(currentExpenseNumber + 1); }
public void AddExpense(ExpenseModel expense) // pass model with name and amount only { int newNum = DatabaseAccess.AddNewExpenseToTrip(expense, this.ID); ExpenseModel toAddToTripModel = new ExpenseModel { TripID = this.ID, Number = newNum, AmountMoney = expense.AmountMoney, Name = expense.Name }; this.expensesList.Add(toAddToTripModel); Console.WriteLine($"Added expense num: {newNum}"); }