// Refreshes a single fund price
        public async static Task RefreshCurrentFundPrices(string ticker, string fundId)
        {
            // Gets the yahoo finance url, gets its html, and parses through it to get the price
            var    financeUrl = string.Format("https://finance.yahoo.com/quote/{0}/?p={1}", ticker, ticker);
            string html       = GetHtml(financeUrl);
            double price      = GetFundPrice(html);

            // Need to use something in the format of Ticker-Date also put in time
            DateTime dateTime     = DateTime.Now;
            string   idDateString = dateTime.ToString("yyyy-MM-dd-HH:mm:ss");
            var      id           = ticker + "-" + idDateString;

            //var random = new Random();
            //var id = random.Next().ToString();
            var newFundPriceHistory = new FundPriceHistory()
            {
                Id          = id,
                FundId      = fundId,
                Ticker      = ticker,
                TickerPrice = price,
                Time        = dateTime
            };

            // Asynchronously inserts the data
            await FundPriceHistoryDataAccess.InsertData(newFundPriceHistory);
        }
Exemple #2
0
        public async Task <ActionResult> Edit(string id, FormCollection collection)
        {
            try
            {
                var ticker           = collection["Ticker"].ToString();
                var tickerPrice      = Convert.ToDouble(collection["Ticker"]);
                var time             = Convert.ToDateTime(collection["Time"]);
                var fundPriceHistory = new FundPriceHistory()
                {
                    Id          = id,
                    Ticker      = ticker,
                    TickerPrice = tickerPrice,
                    Time        = time
                };

                //var fundPriceHistoryName = collection["FundPriceHistoryName"].ToString();
                //var fundPriceHistory = new FundPriceHistory()
                //{
                //    Id = id,
                //    FundPriceHistoryName = fundPriceHistoryName
                //};
                await FundPriceHistoryLib.UpdateFundPriceHistory(fundPriceHistory);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Exemple #3
0
        public async Task <ActionResult> Create(FormCollection collection)
        {
            try
            {
                var rand             = new Random();
                var id               = rand.Next().ToString();
                var ticker           = collection["Ticker"].ToString();
                var tickerPrice      = Convert.ToDouble(collection["Ticker"]);
                var time             = Convert.ToDateTime(collection["Time"]);
                var fundPriceHistory = new FundPriceHistory()
                {
                    Id          = id,
                    Ticker      = ticker,
                    TickerPrice = tickerPrice,
                    Time        = time
                };
                await FundPriceHistoryLib.InsertFundPriceHistory(fundPriceHistory);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
        public static async Task UpdateData(FundPriceHistory fundPriceHistory)
        {
            var item = await GetFundPriceHistoryById(fundPriceHistory.Id);

            item.FundId      = fundPriceHistory.FundId;
            item.Ticker      = fundPriceHistory.Ticker;
            item.TickerPrice = fundPriceHistory.TickerPrice;
            item.Time        = fundPriceHistory.Time;

            await db.SaveChangesAsync();
        }
 public static async Task DeleteData(FundPriceHistory fundPriceHistory)
 {
     db.FundPriceHistories.Remove(fundPriceHistory);
     await db.SaveChangesAsync();
 }
 public static async Task InsertData(FundPriceHistory fundPriceHistory)
 {
     db.FundPriceHistories.Add(fundPriceHistory);
     await db.SaveChangesAsync();
 }
 public async static Task UpdateFundPriceHistory(FundPriceHistory fundPriceHistory)
 {
     await FundPriceHistoryDataAccess.UpdateData(fundPriceHistory);
 }
 public async static Task InsertFundPriceHistory(FundPriceHistory fundPriceHistory)
 {
     await FundPriceHistoryDataAccess.InsertData(fundPriceHistory);
 }
Exemple #9
0
        // GET: FundPriceHistory/Create
        public async Task <ActionResult> Create()
        {
            var fundPriceHistory = new FundPriceHistory();

            return(View(fundPriceHistory));
        }
Exemple #10
0
 public static async Task UpdateData(FundPriceHistory fundPriceHistory)
 {
     await fundPriceHistoryTable.UpdateAsync(fundPriceHistory);
 }
Exemple #11
0
 public static async Task InsertData(FundPriceHistory fundPriceHistory)
 {
     await fundPriceHistoryTable.InsertAsync(fundPriceHistory);
 }