56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using Dapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SQLite;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
|
|
namespace CryptoCalc
|
|
{
|
|
public class DBInteraction
|
|
{
|
|
public static void SaveData<T>(ref T data) where T : DBClasses
|
|
{
|
|
if (data is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(data));
|
|
}
|
|
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBTableName));
|
|
cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data);
|
|
Debug.WriteLine($"Saved {data.DBTableName} DB data");
|
|
}
|
|
|
|
//public static List<T> _LoadTransactions()
|
|
//{
|
|
// using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("RawData"));
|
|
// var output = _connection.Query<T>("select * from RawData", new DynamicParameters());
|
|
// Debug.WriteLine("Loaded DB data");
|
|
// return output.ToList();
|
|
//}
|
|
|
|
|
|
public static List<Transaction> LoadTransactions()
|
|
{
|
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("Transactions"));
|
|
IEnumerable<Transaction> output = _connection.Query<Transaction>("select * from Transactions", new DynamicParameters());
|
|
Debug.WriteLine("Loaded DB data");
|
|
return output.ToList();
|
|
}
|
|
|
|
|
|
public static List<Transaction> LoadTransactionsOfCurrency(string currency)
|
|
{
|
|
if (currency is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(currency));
|
|
}
|
|
|
|
Debug.WriteLine($"Fetching all {currency} transactions from Database");
|
|
using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString("Transactions"));
|
|
return connection.Query<Transaction>($"select * from Transactions where Currency = '{ currency.ToUpper() }'")
|
|
.ToList();
|
|
}
|
|
}
|
|
}
|