Esempio n. 1
0
        //Prases new transactions, adds them to the database, and returns all available transactions
        public List <Transaction> UpdatedPrivateTransactions()
        {
            List <Transaction> parsed = ParsePrivateTransactions();

            Debug.Print("Parsed " + parsed.Count() + " transaction");
            //If it fails to update the database, only return newly parsed transactions
            List <Transaction> ret = parsed;

            using (var ctx = new TransactionHistoriesEntities()) {
                foreach (var transaction in parsed)
                {
                    if (!ctx.Transactions.Any(t => t.id == transaction.id))
                    {
                        ctx.Transactions.Add(transaction);
                    }
                }
                try {
                    ctx.SaveChanges();
                }
                catch (DbEntityValidationException e) {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        foreach (var v in eve.ValidationErrors)
                        {
                            Debug.Print(v.PropertyName + " - " + v.ErrorMessage);
                        }
                    }
                }
                ret = ctx.Transactions.ToList();
            }
            return(ret);
        }
Esempio n. 2
0
        //Prases new transactions, adds them to the database, and returns all available transactions
        public List <PublicTransaction> UpdatedPublicTransactions(string pair, Dictionary <string, string> parameters)
        {
            List <PublicTransaction> parsed = ParsePublicTransactionsFor(pair, parameters);
            //If it fails to update the database, only return newly parsed transactions
            List <PublicTransaction> ret = parsed;

            using (var ctx = new TransactionHistoriesEntities()) {
                foreach (var transaction in parsed)
                {
                    if (!ctx.PublicTransactions.Any(t => t.tid == transaction.tid))
                    {
                        ctx.PublicTransactions.Add(transaction);
                    }
                }
                try {
                    ctx.SaveChanges();
                }
                catch (DbEntityValidationException e) {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        foreach (var v in eve.ValidationErrors)
                        {
                            Debug.Print(v.PropertyName + " - " + v.ErrorMessage);
                        }
                    }
                }
                ret = ctx.PublicTransactions.ToList();
            }
            return(ret);
        }
 private void buttonClearDatabase_Click(object sender, EventArgs e)
 {
     using (var ctx = new TransactionHistoriesEntities()) {
         foreach (var id in ctx.Transactions.Select(t => t.id))
         {
             var entity = new Transaction {
                 id = id
             };
             ctx.Transactions.Attach(entity);
             ctx.Transactions.Remove(entity);
         }
         ctx.SaveChanges();
     }
 }