Ejemplo n.º 1
0
        public ActionResult StockList()
        {
            try
            {
                StockHelper.UpdateCurrentPrice();
                using (var db = new ApplicationDbContext())
                {
                    var list = db.Stocks.Where(a => !a.IsDelete).ToList();

                    return(View(list));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("index", "Home"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult ClientDetail()
        {
            var username   = User.Identity.Name;
            var clientPage = new ClientPages();

            try
            {
                StockHelper.UpdateCurrentPrice();
                using (var db = new ApplicationDbContext())
                {
                    clientPage.UserName = db.User.Where(a => a.UserEmail == username).FirstOrDefault();
                    var data = db.Trades.Where(a => !a.IsDelete).ToList().Join(db.Stocks, a => a.StockId, c => c.Id, (a, c) => new Trade {
                        StockId     = a.StockId,
                        Quantity    = a.Quantity,
                        TotalAmount = a.TotalAmount,
                        TradeType   = a.TradeType,
                        Stock       = c
                    }).ToList();
                    clientPage.profits = ProfitHelper.getProfits(data);
                    var dividend = db.Dividends.Where(a => !a.IsDelete).ToList();
                    ProfitHelper.HandleProfit(clientPage.profits, dividend);
                    clientPage.SumHode      = clientPage.profits.Sum(a => a.hode);
                    clientPage.SumInvest    = clientPage.profits.Where(a => a.hode != 0).Sum(a => a.investAmount);
                    clientPage.done         = clientPage.profits.Where(a => a.hode == 0).Sum(a => a.balance);
                    clientPage.undone       = clientPage.profits.Where(a => a.hode != 0).Sum(a => a.balance);
                    clientPage.SumhodePrice = clientPage.profits.Where(a => a.hode != 0).Sum(a => a.hodePrice);

                    var stocks = db.Stocks.Where(a => !a.IsDelete).ToList();
                    ViewBag.Stocks = stocks;

                    return(View(clientPage));
                }
            }catch (Exception ex)
            {
                return(RedirectToAction("HandleError", "Error", new { @msg = ex.Message }));
            }
        }