/// <summary> /// GET /Deck/Statistics/[id] /// Gives a statistical analysis of a deck. /// </summary> /// <param name="id">The id of the deck to analyze.</param> /// <returns>The view on success, a redirect to /Deck/List on failure.</returns> public ActionResult Statistics(int id = -1) { if (id < 0) { return(RedirectToAction("List")); } if (!Models.AccountUtils.isLoggedIn(this)) { return(RedirectToAction("LogIn", "Account")); } var loginHash = Request.Cookies["loginHash"].Value; var accountId = Models.AccountUtils.GetAccountID(loginHash); if (accountId < 0) { return(RedirectToAction("LogOut", "Account")); } // Check if this account is the owner of the deck var deckDB = new Models.DecksDataContext(); var isOwner = (from d in deckDB.Decks where (d.Id == id) && (d.OwnerId == accountId) select true).ToArray().Length > 0 ? true : false; if (!isOwner) { return(RedirectToAction("List")); } var model = new Models.DeckStatisticsViewModel(); List <string> cardList = new List <string>(); var cardsDB = new Models.CardsDataContext(); var cardsInDeck = from c in cardsDB.Cards where c.DeckId == id select c; foreach (var card in cardsInDeck) { cardList.Add(card.CardName); } model.PopulateDeck(cardList.ToArray(), Server.MapPath(cardDbPath)); model.GenerateStatistics(); return(View(model)); }
/// <summary> /// GET /Deck/Statistics/[id] /// Gives a statistical analysis of a deck. /// </summary> /// <param name="id">The id of the deck to analyze.</param> /// <returns>The view on success, a redirect to /Deck/List on failure.</returns> public ActionResult Statistics(int id = -1) { if(id < 0) return RedirectToAction("List"); if(!Models.AccountUtils.isLoggedIn(this)) return RedirectToAction("LogIn", "Account"); var loginHash = Request.Cookies["loginHash"].Value; var accountId = Models.AccountUtils.GetAccountID(loginHash); if(accountId < 0) return RedirectToAction("LogOut", "Account"); // Check if this account is the owner of the deck var deckDB = new Models.DecksDataContext(); var isOwner = (from d in deckDB.Decks where (d.Id == id) && (d.OwnerId == accountId) select true).ToArray().Length > 0 ? true : false; if(!isOwner) return RedirectToAction("List"); var model = new Models.DeckStatisticsViewModel(); List<string> cardList = new List<string>(); var cardsDB = new Models.CardsDataContext(); var cardsInDeck = from c in cardsDB.Cards where c.DeckId == id select c; foreach(var card in cardsInDeck) { cardList.Add(card.CardName); } model.PopulateDeck(cardList.ToArray(), Server.MapPath(cardDbPath)); model.GenerateStatistics(); return View(model); }