/* * 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)); } }
/* * 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)); }
/* * 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)); }
/* * Populates an instance of the _Items[] class * with predefined items to be gathered from the api * gathered from the Categories class * * Every action in this controller uses the same logic * * * @returns: _Items[] Des Weapons, data gathered from API */ public ViewResult Weapons() { var url = string.Empty; _Items[] DesWeapons = new _Items[Categories.Weapons.Count]; for (int i = 0; i < Categories.Weapons.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Weapons[i] + "\", \"duplicate\": false }"; DesWeapons[i] = DownloadedItem.Download_serialized_json_data(url); } TempData["Category"] = "Weapons"; return(View("Categories", DesWeapons)); }
public ViewResult Food() { var url = string.Empty; List <_Items> DesFood = new List <_Items>(); for (int i = 0; i < Categories.Food.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Food[i] + "\", \"duplicate\": false }"; DesFood.Add(DownloadedItem.Download_serialized_json_data(url)); } TempData["Category"] = "Food"; _Items[] food = new _Items[Categories.Potions.Count()]; food = DesFood.ToArray(); return(View("Categories", food)); }
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)); } }
/* * 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")); } }
/* * Gathers the predefined item list from the categories * class based on which category is being sorted * * Sorts the items displayed by high alch value * */ public ViewResult HAFilter(int id) { var category = TempData["Category"]; switch (category) { case "Potions": var url = string.Empty; List <_Items> DesPotions = new List <_Items>(); for (int i = 0; i < Categories.Potions.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Potions[i] + "\", \"duplicate\": false }"; DesPotions.Add(DownloadedItem.Download_serialized_json_data(url)); } TempData["Category"] = "Potions"; List <_Items> sortedList = DesPotions.OrderBy(n => n.highalch).ToList(); if (TempData["Sorted"] == null || TempData["Sorted"].Equals("high")) { _Items[] desPotionsSortedHA = new _Items[Categories.Potions.Count()]; desPotionsSortedHA = sortedList.ToArray(); TempData["Sorted"] = "low"; return(View("Categories", desPotionsSortedHA)); } else { sortedList.Reverse(); TempData["Sorted"] = "high"; _Items[] desPotionsSortedHA = new _Items[Categories.Potions.Count()]; desPotionsSortedHA = sortedList.ToArray(); return(View("Categories", desPotionsSortedHA)); } case "Weapons": url = string.Empty; List <_Items> DesWeapons = new List <_Items>(); for (int i = 0; i < Categories.Weapons.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Weapons[i] + "\", \"duplicate\": false }"; DesWeapons.Add(DownloadedItem.Download_serialized_json_data(url)); } TempData["Category"] = "Weapons"; sortedList = DesWeapons.OrderBy(p => p.highalch).ToList(); if (TempData["Sorted"] == null || TempData["Sorted"].Equals("high")) { _Items[] desWeaponsSortedHA = new _Items[Categories.Potions.Count()]; desWeaponsSortedHA = sortedList.ToArray(); TempData["Sorted"] = "low"; return(View("Categories", desWeaponsSortedHA)); } else { sortedList.Reverse(); TempData["Sorted"] = "high"; _Items[] desWeaponsSortedHA = new _Items[Categories.Potions.Count()]; desWeaponsSortedHA = sortedList.ToArray(); return(View("Categories", desWeaponsSortedHA)); } case "Food": url = string.Empty; List <_Items> DesFood = new List <_Items>(); for (int i = 0; i < Categories.Food.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Food[i] + "\", \"duplicate\": false }"; DesFood.Add(DownloadedItem.Download_serialized_json_data(url)); } TempData["Category"] = "Food"; sortedList = DesFood.OrderBy(p => p.highalch).ToList(); if (TempData["Sorted"] == null || TempData["Sorted"].Equals("high")) { _Items[] desFoodSortedHA = new _Items[Categories.Potions.Count()]; desFoodSortedHA = sortedList.ToArray(); TempData["Sorted"] = "low"; return(View("Categories", desFoodSortedHA)); } else { sortedList.Reverse(); TempData["Sorted"] = "high"; _Items[] desFoodSortedHA = new _Items[Categories.Potions.Count()]; desFoodSortedHA = sortedList.ToArray(); return(View("Categories", desFoodSortedHA)); } case "Armor": url = string.Empty; List <_Items> DesArmor = new List <_Items>(); for (int i = 0; i < Categories.Armor.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Armor[i] + "\", \"duplicate\": false }"; DesArmor.Add(DownloadedItem.Download_serialized_json_data(url)); } TempData["Category"] = "Armor"; sortedList = DesArmor.OrderBy(p => p.highalch).ToList(); if (TempData["Sorted"] == null || TempData["Sorted"].Equals("high")) { _Items[] desArmorSortedHA = new _Items[Categories.Potions.Count()]; desArmorSortedHA = sortedList.ToArray(); TempData["Sorted"] = "low"; return(View("Categories", desArmorSortedHA)); } else { sortedList.Reverse(); TempData["Sorted"] = "high"; _Items[] desArmorSortedHA = new _Items[Categories.Potions.Count()]; desArmorSortedHA = sortedList.ToArray(); return(View("Categories", desArmorSortedHA)); } case "Woodcutting": url = string.Empty; List <_Items> DesWoodcutting = new List <_Items>(); for (int i = 0; i < Categories.Woodcutting.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Woodcutting[i] + "\", \"duplicate\": false }"; DesWoodcutting.Add(DownloadedItem.Download_serialized_json_data(url)); } TempData["Category"] = "Woodcutting"; sortedList = DesWoodcutting.OrderBy(p => p.highalch).ToList(); if (TempData["Sorted"] == null || TempData["Sorted"].Equals("high")) { _Items[] desWoodcuttingSortedHA = new _Items[Categories.Potions.Count()]; desWoodcuttingSortedHA = sortedList.ToArray(); TempData["Sorted"] = "low"; return(View("Categories", desWoodcuttingSortedHA)); } else { sortedList.Reverse(); TempData["Sorted"] = "high"; _Items[] desWoodcuttingSortedHA = new _Items[Categories.Potions.Count()]; desWoodcuttingSortedHA = sortedList.ToArray(); return(View("Categories", desWoodcuttingSortedHA)); } case "Mining": url = string.Empty; List <_Items> DesMining = new List <_Items>(); for (int i = 0; i < Categories.Mining.Count(); i++) { url = "https://api.osrsbox.com/items?where={ \"name\": \"" + Categories.Mining[i] + "\", \"duplicate\": false }"; DesMining.Add(DownloadedItem.Download_serialized_json_data(url)); } TempData["Category"] = "Mining"; sortedList = DesMining.OrderBy(p => p.highalch).ToList(); if (TempData["Sorted"] == null || TempData["Sorted"].Equals("high")) { _Items[] desMiningSortedHA = new _Items[Categories.Potions.Count()]; desMiningSortedHA = sortedList.ToArray(); TempData["Sorted"] = "low"; return(View("Categories", desMiningSortedHA)); } else { sortedList.Reverse(); TempData["Sorted"] = "high"; _Items[] desMiningSortedHA = new _Items[Categories.Potions.Count()]; desMiningSortedHA = sortedList.ToArray(); return(View("Categories", desMiningSortedHA)); } } return(View()); }