Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            //This row uses setup in the Startup.cs file
            DataContext dc = HttpContext.RequestServices.GetService(typeof(DataContext)) as DataContext;

            //Check for OnlyOwned variables
            bool ShowOwned = string.IsNullOrEmpty(HttpContext.Session.GetString("ShowOwned")) ? false : (HttpContext.Session.GetString("ShowOwned").ToLower() == "true") ? true : false;

            //Get a list of data
            List <GameEntry> data = new List <GameEntry>();

            if (ShowOwned)
            {
                data = dc.GetAllGames().Where(a => a.Owned == true).ToList();
                data = data.OrderBy(a => a.Name).ToList();
                ViewBag.ShowOwned = "checked";
            }
            else
            {
                data = dc.GetAllGames().Where(a => a.Owned == false).ToList();
                data = data.OrderBy(a => a.Ranking).ToList();
                ViewBag.ShowOwned = "";
            }

            //Assign any message to the viewbag
            string message = HttpContext.Session.GetString("Message");

            ViewBag.Message = message;

            //Clear message out so it's not shown multiple times
            HttpContext.Session.Remove("Message");

            //Update the prices of the games in the list from Steam data
            Code.SteamPriceChecker spc = new Code.SteamPriceChecker();

            foreach (var game in data)
            {
                //TODO add support for price checking other stores
                if (game.Store != "steam")
                {
                    continue;
                }

                //get current price from steam
                var appid = dc.GetGameAppId(game.Name);
                if (appid == 0)
                {
                    continue;
                }
                var price = await spc.GetPrice(appid.ToString());

                game.Price = price;

                //update price in db and throw error if cannot
                if (!dc.EditGame(game))
                {
                    throw new Exception("There was a problem editing the game");
                }
            }

            //Pass list to the view as Model
            return(View(data));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            List <Dlc> data;

            //This row uses setup in the Startup.cs file
            DataContext dc = HttpContext.RequestServices.GetService(typeof(DataContext)) as DataContext;

            //Check for OnlyOwned variables
            bool ShowOwned = string.IsNullOrEmpty(HttpContext.Session.GetString("ShowOwned")) ? false : (HttpContext.Session.GetString("ShowOwned").ToLower() == "true") ? true : false;

            //Get a list of dlc data
            if (ShowOwned)
            {
                data = dc.GetAllDlc().Where(a => a.Owned == true).ToList();
                data = data.OrderBy(a => a.Name).ToList();
                ViewBag.ShowOwned = "checked";
            }
            else
            {
                data = dc.GetAllDlc().Where(a => a.Owned == false).ToList();
                data = data.OrderBy(a => a.Ranking).ToList();
                ViewBag.ShowOwned = "";
            }

            //get owned games to populate parent game list
            List <GameEntry>    games        = dc.GetAllGames().Where(a => a.Owned == true).ToList();
            List <DlcViewModel> dlcViewModel = new List <DlcViewModel>();


            //Update the prices of the games in the list from Steam data
            Code.SteamPriceChecker spc = new Code.SteamPriceChecker();

            foreach (var dlc in data)
            {
                //TODO add support for price checking other stores
                if (dlc.Store != "steam")
                {
                    continue;
                }

                //get current price from steam
                var appid = dc.GetDlcAppId(dlc.Name);
                if (appid == 0)
                {
                    continue;
                }
                var price = await spc.GetPrice(appid.ToString());

                dlc.Price = price;

                //update price in db and throw error if cannot
                if (!dc.EditDlc(dlc))
                {
                    throw new Exception("There was a problem editing the game");
                }
            }

            //assign to list of view models and get the parent game names
            foreach (var dlc in data)
            {
                var parentGame = games.Where(a => a.Id == dlc.ParentGameId).FirstOrDefault();

                DlcViewModel dlcvm = new DlcViewModel()
                {
                    Id             = dlc.Id,
                    Name           = dlc.Name,
                    Notes          = dlc.Notes,
                    Owned          = dlc.Owned,
                    ParentGameId   = dlc.ParentGameId,
                    ParentGameName = parentGame.Name,
                    Price          = dlc.Price,
                    Ranking        = dlc.Ranking,
                    Rating         = dlc.Rating,
                    Store          = dlc.Store
                };

                dlcViewModel.Add(dlcvm);
            }

            //sort list by ranking
            dlcViewModel = dlcViewModel.OrderBy(a => a.Ranking).ToList();

            //Assign any message to the viewbag
            string message = HttpContext.Session.GetString("Message");

            ViewBag.Message = message;

            //Clear message out so it's not shown multiple times
            HttpContext.Session.Remove("Message");

            //Pass list to the view as Model
            return(View(dlcViewModel));
        }