public void AddCreditsToAccount(User user, int amount) { InsertCashTransaction newTransaction = new InsertCashTransaction(); newTransaction.User = user; newTransaction.Amount = amount; ExecuteTransaction(newTransaction); }
public bool AddCashTransaction(InsertCashTransaction transaction) { string delimiter = ";"; string[][] output = new string[][] { new string[] { "InsertCashTransaction", newTransactionID().ToString(), transaction.User.Username, "EMPTY", transaction.Amount.ToString(), "EMPTY", transaction.Date.ToString() } }; int length = output.GetLength(0); StringBuilder sb = new StringBuilder(); for (int index = 0; index < length; index++) { sb.AppendLine(string.Join(delimiter, output[index])); } File.AppendAllText(filePath, sb.ToString()); return(true); }
public List <InsertCashTransaction> GetCashList() { List <InsertCashTransaction> transactionList = new List <InsertCashTransaction>(); int i = 0; checkCreateTransactionList(); var reader = new StreamReader(File.OpenRead(filePath), Encoding.UTF8); while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); // Skipping first line of the file. (This Part not taken from source!) if (i == 1) { if (values[0] == "InsertCashTransaction") { InsertCashTransaction transaction = new InsertCashTransaction(); transaction.TransactionID = Convert.ToInt32(values[1]); transaction.User = CS.GetUser(values[2]); transaction.Amount = Convert.ToInt32(values[4]); transaction.Date = Convert.ToDateTime(values[6]); transactionList.Add(transaction); } } else { i = 1; } } reader.Close(); return(transactionList); }