예제 #1
0
        /// <summary>
        /// GET /Deck/Delete/[id]
        /// Deletes the specified deck from the database.
        /// </summary>
        /// <param name="id">The deck id.</param>
        /// <returns>A redirect to /Deck/List.</returns>
        public ActionResult Delete(int id)
        {
            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"));
            }

            var deckDB = new Models.DecksDataContext();

            var decks = from d in deckDB.Decks
                        where (d.OwnerId == accountId) &&
                        (d.Id == id)
                        select d;

            deckDB.Decks.DeleteAllOnSubmit(decks);
            deckDB.SubmitChanges();

            return(RedirectToAction("List"));
        }
예제 #2
0
        /// <summary>
        /// GET /Deck/Delete/[id]
        /// Deletes the specified deck from the database.
        /// </summary>
        /// <param name="id">The deck id.</param>
        /// <returns>A redirect to /Deck/List.</returns>
        public ActionResult Delete(int id)
        {
            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");

            var deckDB = new Models.DecksDataContext();

            var decks = from d in deckDB.Decks
                        where (d.OwnerId == accountId) &&
                              (d.Id == id)
                        select d;

            deckDB.Decks.DeleteAllOnSubmit(decks);
            deckDB.SubmitChanges();

            return RedirectToAction("List");
        }
예제 #3
0
        public ActionResult SaveDeck(string[] cardList, string deckName = "", int deckId = -1)
        {
            if (deckName == string.Empty)
            {
                return(RedirectToAction("Create", new { deckId = deckId }));
            }

            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"));
            }

            if (deckId < 0)
            {
                // New deck
                var deckDB  = new Models.DecksDataContext();
                var newDeck = new Models.Deck {
                    OwnerId = accountId,
                    Name    = deckName
                };

                deckDB.Decks.InsertOnSubmit(newDeck);
                deckDB.SubmitChanges();

                var cards = new List <Models.Card>();

                Array.ForEach(cardList, c => {
                    cards.Add(new Models.Card {
                        DeckId   = newDeck.Id,
                        CardName = c
                    });
                });

                var cardsDB = new Models.CardsDataContext();
                cardsDB.Cards.InsertAllOnSubmit(cards);
                cardsDB.SubmitChanges();
            }
            else
            {
                // Existing deck
                var deckDB = new Models.DecksDataContext();
                var deck   = from d in deckDB.Decks
                             where (d.Id == deckId) &&
                             (d.OwnerId == accountId)
                             select d;

                if (deck.ToArray().Length <= 0)
                {
                    return(RedirectToAction("Create"));
                }

                deck.First().Name = deckName;
                deckDB.SubmitChanges();

                var cardsDB = new Models.CardsDataContext();

                // Clear the deck before inserting the cards
                var currentCards = from c in cardsDB.Cards
                                   where c.DeckId == deckId
                                   select c;

                cardsDB.Cards.DeleteAllOnSubmit(currentCards);

                // Add the new cards to the deck
                var cards = new List <Models.Card>();

                Array.ForEach(cardList, c => {
                    cards.Add(new Models.Card {
                        DeckId   = deckId,
                        CardName = c
                    });
                });

                cardsDB.Cards.InsertAllOnSubmit(cards);
                cardsDB.SubmitChanges();
            }

            return(RedirectToAction("List"));
        }
예제 #4
0
        public ActionResult SaveDeck(string[] cardList, string deckName = "", int deckId = -1)
        {
            if(deckName == string.Empty) {
                return RedirectToAction("Create", new { deckId = deckId });
            }

            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");

            if(deckId < 0) {
                // New deck
                var deckDB = new Models.DecksDataContext();
                var newDeck = new Models.Deck {
                    OwnerId = accountId,
                    Name = deckName
                };

                deckDB.Decks.InsertOnSubmit(newDeck);
                deckDB.SubmitChanges();

                var cards = new List<Models.Card>();

                Array.ForEach(cardList, c => {
                    cards.Add(new Models.Card {
                        DeckId = newDeck.Id,
                        CardName = c
                    });
                });

                var cardsDB = new Models.CardsDataContext();
                cardsDB.Cards.InsertAllOnSubmit(cards);
                cardsDB.SubmitChanges();
            } else {
                // Existing deck
                var deckDB = new Models.DecksDataContext();
                var deck = from d in deckDB.Decks
                           where (d.Id == deckId) &&
                                 (d.OwnerId == accountId)
                           select d;

                if(deck.ToArray().Length <= 0) return RedirectToAction("Create");

                deck.First().Name = deckName;
                deckDB.SubmitChanges();

                var cardsDB = new Models.CardsDataContext();

                // Clear the deck before inserting the cards
                var currentCards = from c in cardsDB.Cards
                                   where c.DeckId == deckId
                                   select c;

                cardsDB.Cards.DeleteAllOnSubmit(currentCards);

                // Add the new cards to the deck
                var cards = new List<Models.Card>();

                Array.ForEach(cardList, c => {
                    cards.Add(new Models.Card {
                        DeckId = deckId,
                        CardName = c
                    });
                });

                cardsDB.Cards.InsertAllOnSubmit(cards);
                cardsDB.SubmitChanges();
            }

            return RedirectToAction("List");
        }