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);
        }
Exemple #2
0
        /// <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));
        }