コード例 #1
0
ファイル: DeckController.cs プロジェクト: Okiesmokie/mtgcards
        private string cardDbPath = "~/Content/xml/cards.xml"; // The path to the XML Card Database on the server

        #endregion Fields

        #region Methods

        /// <summary>
        /// GET /Deck/Create/[id]
        /// The deck editor
        /// </summary>
        /// <param name="id">The id of the deck to edit, or -1 to create a new deck.</param>
        /// <returns>The view.</returns>
        public ActionResult Create(int id = -1)
        {
            if(!Models.AccountUtils.isLoggedIn(this)) return RedirectToAction("LogIn", "Account");

            CardDatabase db = new CardDatabase(Server.MapPath(cardDbPath));

            var model = new Models.DeckCreateViewModel();

            List<string> deckCardList = new List<string>();

            if(id >= 0) {
                var accountDB = new Models.AccountsDataContext();

                var loginHash = Request.Cookies["loginHash"].Value;
                var accountId = (from a in accountDB.Accounts
                                 where a.LoginHash == loginHash
                                 select a.Id).ToArray();

                if(accountId.Length <= 0) return RedirectToAction("LogOut", "Account");

                // Check if this account is the owner of the deck
                var deckDB = new Models.DecksDataContext();
                var deck = (from d in deckDB.Decks
                            where (d.Id == id) &&
                                  (d.OwnerId == accountId[0])
                            select d).ToArray();

                if(deck.Length <= 0) {
                    // This account does not own the deck
                    return RedirectToAction("Create", "Deck", new { id = -1 });
                }

                model.DeckName = deck[0].Name;

                var cardDB = new Models.CardsDataContext();
                var cards = from c in cardDB.Cards
                            where c.DeckId == id
                            select c.CardName;

                foreach(var card in cards) {
                    deckCardList.Add(card);
                }
            }

            model.deckCards = new List<Core.Card>();
            model.deckCards = (from c in deckCardList
                               orderby c
                               select db.GetCardByName(c)
                              ).ToList();

            model.sets = db.sets;
            model.DeckId = id;

            return View(model);
        }
コード例 #2
0
ファイル: DeckController.cs プロジェクト: Okiesmokie/mtgcards
        /// <summary>
        /// GET /Deck/GetFilteredCardList?nameFilter&setFilter&colorFilter
        /// Gets the filtered card list.
        /// </summary>
        /// <param name="nameFilter">The partial card name.</param>
        /// <param name="setFilter">A comma-separated list of sets to include.</param>
        /// <param name="colorFilter">A comma-separated list of colors to include.</param>
        /// <returns>A JSON array of cards in the format Color|Set|Name.</returns>
        public string GetFilteredCardList(string nameFilter = "", string setFilter = "", string colorFilter = "")
        {
            CardDatabase db = new CardDatabase(Server.MapPath(cardDbPath));

            string[] cardList = (from c in db.cards
                                 where (c.Name.ToLower().Contains(nameFilter.ToLower())) &&
                                       (CheckFilterConditions(c, setFilter, colorFilter))
                                 orderby c.Name
                                 select string.Format("{0}|{1}|{2}", c.Color, c.Set, c.Name)).ToArray();

            if(cardList.Length > 0) {
                JavaScriptSerializer js = new JavaScriptSerializer();
                return js.Serialize(cardList);
            }

            return string.Empty;
        }
コード例 #3
0
ファイル: DeckController.cs プロジェクト: Okiesmokie/mtgcards
        /// <summary>
        /// GET /Deck/GetCardInfo/[id]
        /// Gets a JSON object containing the info for the specified card.
        /// </summary>
        /// <param name="id">The name of the card.</param>
        /// <returns>A JSON object containing the info for the specified card.</returns>
        public string GetCardInfo(string id)
        {
            CardDatabase db = new CardDatabase(Server.MapPath(cardDbPath));

            Card card = db.GetCardByName(id);

            if(card != null) {
                JavaScriptSerializer js = new JavaScriptSerializer();
                return js.Serialize(card);
            }

            return string.Empty;
        }