public List <Customer> FindAllCustomers() { string query = "SELECT ID,ALIAS,FIRSTNAME, LASTNAME FROM CUSTOMER"; List <Customer> customers = new List <Customer>(); using (SQLiteConnection dataConnection = SqliteDBHelper.GetConnection(this.databasePath)) { using (SQLiteCommand dataCommand = dataConnection.CreateCommand()) { var result = SqliteDBHelper.GetResult(dataCommand, query); foreach (DataRow dataRow in result.Tables[0].Rows) { customers.Add(new Customer() { Id = Convert.ToInt32(dataRow["Id"]), Alias = dataRow.GetString("Alias"), FirstName = dataRow.GetString("FirstName") } ); } } dataConnection.Close(); } return(customers); }
public Customer CreateCustomer(Customer customer) { using (SQLiteConnection dataConnection = SqliteDBHelper.GetConnection(this.databasePath)) { using (SQLiteTransaction dbTransaction = dataConnection.BeginTransaction()) { using (SQLiteCommand dataCommand = dataConnection.CreateCommand()) { dataCommand.Transaction = dbTransaction; int sessionId = this.CreateDataUpdateSession(dataCommand); int customerId = this.GetNextId(dataCommand, "Customer"); string query = $"INSERT INTO Customer(ID,SessionId,ALIAS,FIRSTNAME,LASTNAME)" + $" VALUES ({customerId},{sessionId}, '{customer.Alias}','{customer.FirstName}','{customer.LastName}')"; SqliteDBHelper.ExecuteNonQuery(dataCommand, query); customer.Id = customerId; } dbTransaction.Commit(); } dataConnection.Close(); } return(customer); }