/*
         * Action that allows a user to save an item
         * to view later on the MyFavorites page
         *
         */
        public IActionResult SaveItem(RootobjectOsrsGe items, string returnUrl)
        {
            var    url      = "https://api.osrsbox.com/items?where={ \"name\": \"" + items.item.name + "\", \"duplicate\": false }";
            _Items nameToId = new _Items();

            nameToId = DownloadedItem.Download_serialized_json_data(url);
            url      = "https://secure.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + nameToId.id;
            RootobjectOsrsGe itemID = new RootobjectOsrsGe();

            itemID = DownloadedItemOsrsGe.Download_serialized_json_data(url);
            FavoriteModel favorite = new FavoriteModel
            {
                ItemID   = itemID.item.id.ToString(),
                Username = HttpContext.User.Identity.Name
            };

            if (repository.SaveFavorite(favorite) == 1)
            {
                TempData["Result"] = "Item successfully added to favorites";

                return(Redirect(returnUrl));
            }
            else if (repository.SaveFavorite(favorite) == 0)
            {
                TempData["Result"] = "This item is already in your favorites";
                return(Redirect(returnUrl));
            }
            else
            {
                TempData["Result"] = "Something went wrong with adding this item";
                return(Redirect(returnUrl));
            }
        }
        /*
         * Pulls a users favorite items from the database
         * and displays a table for them to view the
         * items that they favorited
         *
         */
        public ViewResult MyFavorites()
        {
            List <FavoriteModel> favorites = repository.Items.Where(i => i.Username == HttpContext.User.Identity.Name).Distinct().ToList();
            var url = string.Empty;

            RootobjectOsrsGe[] favoritesArr = new RootobjectOsrsGe[favorites.Count()];
            for (int i = 0; i < favorites.Count(); i++)
            {
                url = "https://secure.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + favorites[i].ItemID;

                favoritesArr[i] = DownloadedItemOsrsGe.Download_serialized_json_data(url);
            }

            _Items[] itemFavorites = new _Items[favorites.Count()];
            for (int i = 0; i < favorites.Count(); i++)
            {
                url = "https://api.osrsbox.com/items?where={ \"name\": \"" + favoritesArr[i].item.name + "\", \"duplicate\": false }";
                itemFavorites[i]       = DownloadedItem.Download_serialized_json_data(url);
                itemFavorites[i].price = favoritesArr[i].item.current.price;
            }

            TempData["Username"] = HttpContext.User.Identity.Name;
            TempData["Favorite"] = "true";

            return(View("MyFavorites", itemFavorites));
        }
Exemple #3
0
        /*
         * Default landing page
         *
         * @variables:    tempArray, _Items[]- used to gather an ID for featured items from OsrsBox API
         *                arrFeatItems, RootobjectOsrsGe[]- used to gather GE price of items from OSRS GE API
         *
         *
         *
         * @returns: RootobjectOsrsGe[] arrFeatItems, used to find GE price of items
         */
        public ViewResult Index()
        {
            var url = string.Empty;

            List <string> featItems = new List <string>()
            {
                "Abyssal whip",
                "Elder maul",
                "Twisted bow",
            };

            _Items[] tempArray = new _Items[featItems.Count()];
            for (int i = 0; i < featItems.Count(); i++)
            {
                url          = "https://api.osrsbox.com/items?where={ \"name\": \"" + featItems[i] + "\", \"duplicate\": false }";
                tempArray[i] = DownloadedItem.Download_serialized_json_data(url);
            }
            RootobjectOsrsGe[] arrFeatItems = new RootobjectOsrsGe[featItems.Count()];
            for (int i = 0; i < featItems.Count(); i++)
            {
                url             = "https://secure.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + tempArray[i].id;
                arrFeatItems[i] = DownloadedItemOsrsGe.Download_serialized_json_data(url);
            }

            return(View(arrFeatItems));
        }
        public IActionResult NameFilter(int id)
        {
            var url = string.Empty;
            List <FavoriteModel> favorites = repository.Items.Where(i => i.Username == HttpContext.User.Identity.Name).Distinct().ToList();

            RootobjectOsrsGe[] favoritesArr = new RootobjectOsrsGe[favorites.Count()];

            for (int i = 0; i < favorites.Count; i++)
            {
                url             = "https://secure.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + favorites[i].ItemID;
                favoritesArr[i] = (DownloadedItemOsrsGe.Download_serialized_json_data(url));
            }
            _Items[] names = new _Items[favorites.Count()];
            for (int i = 0; i < favorites.Count; i++)
            {
                url            = "https://api.osrsbox.com/items?where={ \"name\": \"" + favoritesArr[i].item.name + "\", \"duplicate\": false }";
                names[i]       = (DownloadedItem.Download_serialized_json_data(url));
                names[i].price = favoritesArr[i].item.current.price;
            }

            List <_Items> sortedList = names.OrderBy(p => p.name).ToList();

            _Items[] sortedName = new _Items[favorites.Count()];
            sortedName           = sortedList.ToArray();
            TempData["Username"] = HttpContext.User.Identity.Name;
            if (TempData["Sorted"] == null || TempData["Sorted"].Equals("high"))
            {
                sortedName         = new _Items[favorites.Count()];
                sortedName         = sortedList.ToArray();
                TempData["Sorted"] = "low";

                return(View("MyFavorites", sortedName));
            }
            else
            {
                sortedList.Reverse();
                TempData["Sorted"] = "high";
                sortedName         = new _Items[Categories.Potions.Count()];
                sortedName         = sortedList.ToArray();
                return(View("MyFavorites", sortedName));
            }
        }
Exemple #5
0
        /*
         * Formats the search to input into OSRSBox Api
         *
         * @variables:  searchedItems, _Items- used to gather the ID from the OSRSBox api to pass to 2nd API
         *              specificItem, RootobjectOsrsGe- used to gather GE information from the OSRS GE API
         *
         */
        public IActionResult SingleItem(Items item)
        {
            item.Name        = item.Name.ToLower();
            item.Name        = char.ToUpper(item.Name[0]) + item.Name.Substring(1);
            ViewBag.ItemName = item.Name;
            RootobjectOsrsGe specificItem = new RootobjectOsrsGe();
            var    url           = "https://api.osrsbox.com/items?where={ \"name\": \"" + item.Name + "\", \"duplicate\": false }&max_results=1";
            _Items searchedItems = new _Items();

            searchedItems = DownloadedItem.Download_serialized_json_data(url);
            if (searchedItems.id != null)
            {
                url          = "https://secure.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + searchedItems.id;
                specificItem = DownloadedItemOsrsGe.Download_serialized_json_data(url);
                return(View(specificItem));
            }
            else
            {
                TempData["Error"] = "Please enter a valid item name";
                return(RedirectToAction("Stocks", "Home"));
            }
        }