public ActionResult CryptoData()
        {
            ViewBag.Message = "Here are the top 100 coins !";
            ViewBag.Time    = DateTime.Now;

            /*
             * var hap = new HAPScraper();
             * hap.Run();
             */

            using (var db = new LedgerContext())
            {
                var url = "https://coinmarketcap.com/";

                var htmlWeb = new HtmlWeb();

                var htmlDocument = new HtmlDocument();

                htmlDocument = htmlWeb.Load(url);

                HtmlNodeCollection allRows = htmlDocument.DocumentNode.SelectNodes("//table[1]/tbody[1]/tr[*]");

                List <Coin> currencyList = new List <Coin>();

                foreach (var row in allRows)
                {
                    var CoinPosition = row.ChildNodes[1].InnerText;
                    var CoinSymbol   = row.ChildNodes[3].ChildNodes[3].InnerText;
                    var CoinName     = row.ChildNodes[3].ChildNodes[7].InnerText;
                    var CoinChange   = row.ChildNodes[13].InnerText;
                    var CoinPrice    = row.ChildNodes[7].InnerText;


                    Coin coin = new Coin(CoinPosition, CoinSymbol, CoinName, CoinChange, CoinPrice);
                    currencyList.Add(coin);
                }

                //Creates a date.time snapshot-this will be my future snapshot button


                var ledger = new Ledger
                {
                    CryptoCoins = currencyList,
                    Time        = DateTime.Now
                };
                db.Ledgers.Add(ledger);
                db.SaveChanges();
                Console.WriteLine();

                return(View(currencyList));
            }
        }
        public int RemoveTransaction(Guid transId, DbContextOptionsBuilder <LedgerContext> context)
        {
            using (var ctx = new LedgerContext(context.Options))
            {
                var entity = ctx.Transactions.FirstOrDefault(t => t.Id == transId);
                if (entity != null)
                {
                    ctx.Entry(entity).State = EntityState.Deleted;
                }

                return(ctx.SaveChanges());
            }
        }
        public void OnException(ExceptionContext filterContext)
        {
            LedgerContext context = new LedgerContext();

            ExceptionLog exception = new ExceptionLog();

            exception.RequestUrl       = filterContext.HttpContext.Request.RawUrl;
            exception.RequestDetail    = JsonConvert.SerializeObject(filterContext.HttpContext.Request.Params);
            exception.ExceptionMessage = filterContext.Exception.Message;
            exception.ExceptionDetail  = JsonConvert.SerializeObject(filterContext.Exception);
            exception.LogTime          = System.DateTime.Now;
            context.Exceptions.Add(exception);
            context.SaveChanges();
        }
Example #4
0
        private void AccountBookInitData(Guid newAbId)
        {
            //添加初始科目
            Guid abid = new Guid("00000000-0000-0000-0000-000000000000");

            List <Account> baseAccounts = _ledger.Accounts.Where(a => a.AbId == abid).ToList();

            foreach (Account acc in baseAccounts)
            {
                Account newAccount = new Account();
                newAccount.AccCode       = acc.AccCode;
                newAccount.ParentAccCode = acc.ParentAccCode;
                newAccount.AcId          = acc.AcId;
                newAccount.AccName       = acc.AccName;
                newAccount.Direction     = acc.Direction;
                newAccount.IsAuxiliary   = false;
                newAccount.IsQuantity    = false;
                newAccount.State         = AccountState.Normal;
                newAccount.AbId          = newAbId;
                newAccount.Creator       = _identity.GetUserName();
                newAccount.CreateTime    = DateTime.Now;

                _ledger.Accounts.Add(newAccount);
            }

            //添加初始凭证字
            CertificateWord defCertWord = new CertificateWord();

            defCertWord.CertWord   = "记";
            defCertWord.PrintTitle = "记";
            defCertWord.AbId       = newAbId;
            defCertWord.IsDefault  = true;
            _ledger.CertificateWords.Add(defCertWord);

            //保存初始数据
            _ledger.SaveChanges();
        }
Example #5
0
        public Company Edit(Company editCom)
        {
            Company com = _ledger.Companys.Where(c => c.ComId == editCom.ComId).FirstOrDefault();

            com.ComName             = editCom.ComName;
            com.ComShortName        = editCom.ComShortName;
            com.ComAddress          = editCom.ComAddress;
            com.LegalRepresentative = editCom.LegalRepresentative;
            com.Mobile = editCom.Mobile;
            com.Region = _ledger.Regions.Where(r => r.RegionCode == editCom.RegionCode).FirstOrDefault();

            if (_ledger.SaveChanges() > 0)
            {
                return(com);
            }

            return(null);
        }
Example #6
0
 public int Create(PaymentType paymentType, DbContextOptionsBuilder <LedgerContext> context)
 {
     try
     {
         using (var ctx = new LedgerContext(context.Options))
         {
             ctx.PaymentTypes.Add(paymentType);
             return(ctx.SaveChanges());
         }
     }
     catch (DbEntityValidationException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int Create(Category category, DbContextOptionsBuilder <LedgerContext> context)
 {
     try
     {
         using (var ctx = new LedgerContext(context.Options))
         {
             ctx.Categories.Add(category);
             return(ctx.SaveChanges());
         }
     }
     catch (DbEntityValidationException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int Create(Account account, DbContextOptionsBuilder <LedgerContext> context)
 {
     try
     {
         using (var ctx = new LedgerContext(context.Options))
         {
             account.DateCreated = DateTime.Now;
             ctx.Accounts.Add(account);
             return(ctx.SaveChanges());
         }
     }
     catch (DbEntityValidationException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #9
0
        public void Can_Create_Tranaction()
        {
            using (var context = new LedgerContext(_optionBuilder.Options))
            {
                context.Transactions.Add(new Transaction
                {
                    AccountId       = _acctId,
                    Amount          = 100,
                    CategoryId      = 1,
                    Description     = "New shoes",
                    IsDeposit       = false,
                    PaymentTypeId   = 1,
                    TransactionDate = DateTime.Now,
                    CreatedBy       = "BVilla",
                    DateCreated     = DateTime.Now,
                });
                context.SaveChanges();

                var trans = context.Transactions.FirstOrDefault(t => t.AccountId == _acctId);

                Assert.IsNotNull(trans, "Transaction was not successfully created");
            }
        }
        public void Can_Create_Account()
        {
            var optionBuilder = new DbContextOptionsBuilder <LedgerContext>();

            optionBuilder.UseInMemoryDatabase();

            using (var context = new LedgerContext(optionBuilder.Options))
            {
                context.Accounts.Add(new Account
                {
                    FirstName   = "Bob",
                    LastName    = "Villa",
                    UserName    = "******",
                    Password    = "******",
                    CreatedBy   = "Admin",
                    DateCreated = DateTime.Now
                });
                context.SaveChanges();

                var account = context.Accounts.FirstOrDefault(a => a.UserName == "BVilla");

                Assert.IsNotNull(account, "Account was not successfully created");
            }
        }
Example #11
0
        public static void CraeteReacord()
        {
            Person newPerson = new Person()
            {
                Name = SetInformations.SetName(),
                CertificateNumber = SetInformations.SetCertificateNumber()
            };

            Ledger newRecord = new Ledger()
            {
                Person       = newPerson,
                EnterTime    = DateTime.Now,
                ExitTime     = null,
                PersonId     = newPerson.Id,
                VisitPurpose = SetInformations.SetVisitPurpose()
            };

            using (var context = new LedgerContext())
            {
                context.People.Add(newPerson);
                context.Ledgers.Add(newRecord);
                context.SaveChanges();
            }
        }
        public ActionResult YahooStock()
        {
            ViewBag.Message = "Here are your Stocks !";
            ViewBag.Time    = DateTime.Now;

            /*
             * IWebDriver chromeDriver = new ChromeDriver();
             * Auth.YahooSignin(chromeDriver);
             *
             * var ext = ExtractStock.Extractor(chromeDriver);
             */

            var url = "https://login.yahoo.com/";

            var pass = "******";

            var email = "*****@*****.**";

            var chromeDriver = new ChromeDriver();

            chromeDriver.Navigate().GoToUrl(url);

            var wait = new WebDriverWait(chromeDriver, TimeSpan.FromSeconds(120));

            chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(60);

            IWebElement emailBox = chromeDriver.FindElement(By.XPath("//*[@id='login-username']"));

            emailBox.SendKeys(email);

            IWebElement nextBox = chromeDriver.FindElement(By.XPath("//*[@id='login-signin']"));

            nextBox.Click();

            wait.Until(d => d.FindElement(By.Id("login-passwd")));

            IWebElement passBox = chromeDriver.FindElement(By.Id("login-passwd"));

            passBox.SendKeys(pass);
            passBox.SendKeys(Keys.Enter);

            chromeDriver.Navigate().GoToUrl("https://finance.yahoo.com/");

            Console.WriteLine("Complete !");

            using (var db = new LedgerContext())
            {
                List <Stock> stocksList = new List <Stock>();
                for (var row = 2; row < chromeDriver.FindElements(By.XPath("//section[2]/table/tbody/tr[*]")).Count; row++)
                {
                    var stockSymbol =
                        chromeDriver.FindElement(By.XPath("//section[2]/table/tbody/tr[" + row + "]/td[1]/a")).Text;

                    var stockName =
                        chromeDriver.FindElement(By.XPath("//section[2]/table/tbody/tr[" + row + "]/td[1]/p")).Text;

                    var stockLPrice =
                        chromeDriver.FindElement(By.XPath("//section[2]/table/tbody/tr[" + row + "]/td[2]")).Text;

                    var stockChange =
                        chromeDriver.FindElement(By.XPath("//section[2]/table/tbody/tr[" + row + "]/td[3]/span")).Text;

                    var stockPChange =
                        chromeDriver.FindElement(By.XPath("//section[2]/table/tbody/tr[" + row + "]/td[4]/span")).Text;

                    Stock stock = new Stock(stockSymbol, stockName, stockLPrice, stockChange, stockPChange);
                    stocksList.Add(stock);
                }

                var ledger = new SelenLedger
                {
                    StocksL = stocksList,
                    STime   = DateTime.Now
                };
                db.SelenLedgers.Add(ledger);
                Console.WriteLine();
                db.SaveChanges();

                return(View(stocksList));
            }
        }