public JsonResult GetItemData() { //pullingg linkList from db List <EnemyItemDO> list = linkDAO.ViewAllLinks(); //stripping itemID's off of the list and storing them in a list List <int> idList = Mapper.BLLMapper.LinkListToItemIdList(list); //sending the idList to a BLL method to find unique id's and count their occurances Dictionary <int, int> countDictionary = AnalyzeItemList.ItemDropCount(idList); //instantiating a dictionary that will hold item names(based on ids) and how many times they were used Dictionary <string, int> itemDropCount = new Dictionary <string, int>(); //creating a list of ItemPO to hold item information, to pull names from items based on ids in idList List <ItemPO> itemList = new List <ItemPO>(); //foreach unique itemID, add that item's information to the itemList foreach (KeyValuePair <int, int> idLink in countDictionary) { ItemPO item = Mapper.Mapper.ItemDOtoPO(iDAO.ViewItemSingle(idLink.Key)); itemList.Add(item); } //foreach item in the itemList, create a key based on item name, and set its base value to 0 foreach (ItemPO item in itemList) { itemDropCount.Add(item.Name, 0); //for each key value pair in our count dictionary which holds our item id and how many times that item has been used //we check if the key value pair's key is the same as the item's id in the outer for each //if it matches we update the value of our itemDropCount foreach (KeyValuePair <int, int> itemCount in countDictionary) { if (itemCount.Key == item.ItemID) { itemDropCount[item.Name] = itemCount.Value; } } } //creating an object that holds 2 lists, one of type string, one of type int //holds our item names in one list, and our item occurance in the other ChartData <string, int> chartData = new ChartData <string, int>(); chartData.Labels = new List <string>(); chartData.Values = new List <int>(); foreach (KeyValuePair <string, int> itemDrop in itemDropCount) { chartData.Labels.Add(itemDrop.Key); chartData.Values.Add(itemDrop.Value); } return(Json(chartData, JsonRequestBehavior.AllowGet)); }
public ActionResult Index() { ActionResult response; HomePageVM items = new HomePageVM(); try { ItemPO mostCommonItem = new ItemPO(); ItemPO leastCommonItem = new ItemPO(); int mostCommonID; int leastCommonID; List <EnemyItemDO> fullLinkList = linkDAO.ViewAllLinks(); List <int> itemIdList = new List <int>(); itemIdList = Mapper.BLLMapper.LinkListToItemIdList(fullLinkList); mostCommonID = AnalyzeItemList.MostCommonID(itemIdList); leastCommonID = AnalyzeItemList.LeastCommonID(itemIdList); mostCommonItem = Mapper.Mapper.ItemDOtoPO(iDAO.ViewItemSingle(mostCommonID)); leastCommonItem = Mapper.Mapper.ItemDOtoPO(iDAO.ViewItemSingle(leastCommonID)); items.MostCommonItem = mostCommonItem; items.LeastCommonItem = leastCommonItem; response = View(items); } catch (SqlException sqlEx) { if (!sqlEx.Data.Contains("Logged") || (bool)sqlEx.Data["Logged"] == false) { Logger.LogSqlException(sqlEx); } response = View(items); } catch (Exception ex) { if (!ex.Data.Contains("Logged") || (bool)ex.Data["Logged"] == false) { Logger.LogException(ex); } response = View(items); } return(response); }