示例#1
0
        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
        /// <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;
        }