コード例 #1
0
 public ActionResult Index(SimpleStatsModel simplestatsmodel)
 {
     using (var db = new HearthstoneContext())
     {
         if (ModelState.IsValid)
         {
             var user = (from u in db.UserProfiles.Include("SimpleStats")
                         where u.UserName == User.Identity.Name
                         select u).FirstOrDefault();
             simplestatsmodel.UserID = user.UserId;
             //if ID is 0, need to add, not update
             if (simplestatsmodel.SimpleStatsID == 0)
             {
                 db.SimpleStats.Add(simplestatsmodel);
             }
             else
             {
                 var ssm = db.SimpleStats.Find(simplestatsmodel.SimpleStatsID);
                 simplestatsmodel.CopyTo(ssm);
                 db.Entry(ssm).State = EntityState.Modified;
             }
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(simplestatsmodel);
     }
 }
コード例 #2
0
 public ActionResult Create(DecksForUsersModel deckForUser, string SelectedCardList)
 {
     using (var context = new HearthstoneContext())
     {
         var user = (from u in context.UserProfiles
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var exists = (from dfu in context.DecksForUsers where dfu.UserID == user.UserId && dfu.DeckName.ToLower() == deckForUser.DeckName.ToLower() && dfu.IsActive select dfu).Any();
         var cardList = SelectedCardList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
         var cardCount = 0;
         for (var i = 0; i < cardList.Count; i++)
         {
             cardCount += int.Parse(cardList[i].Split(new char[] { '-' })[1]);
         }
         if (cardCount < 30)
         {
             ModelState.AddModelError("CardCount", new Exception("Not enough cards."));
             ViewBag.SelectedCardList = SelectedCardList;
             ViewBag.Error = "Not enough cards.";
             return View(deckForUser);
         }
         if (cardList.Count > 30)
         {
             ModelState.AddModelError("CardCount", new Exception("Too Many cards."));
             ViewBag.SelectedCardList = SelectedCardList;
             ViewBag.Error = "Too Many cards.";
             return View(deckForUser);
         }
         if (exists)
         {
             ModelState.AddModelError("DuplicateDeck", new Exception("You already have a deck with this name."));
             ViewBag.SelectedCardList = SelectedCardList;
             ViewBag.Error = "You already have a deck with this name.";
             return View(deckForUser);
         }
         DeckModel newDeck = DeckModel.GetUniqueDeck(deckForUser.Deck, SelectedCardList, context);
         deckForUser.Deck = newDeck;
         deckForUser.IsActive = true;
         deckForUser.UserID = user.UserId;
         if (newDeck.DeckID == 0)
         {
             foreach (var cardID in cardList)
             {
                 var id = int.Parse(cardID.Split(new char[] { '-' })[0]);
                 var count = int.Parse(cardID.Split(new char[] { '-' })[1]);
                 if (id > 0 && context.Cards.Find(id) != null)
                 {
                     var card = new CardsInDeckModel() { CardID = id, Deck = newDeck, CardCount = count };
                     context.CardsInDecks.Add(card);
                 }
             }
         }
         context.DecksForUsers.Add(deckForUser);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
コード例 #3
0
 public ActionResult Delete(int id)
 {
     using (var context = new HearthstoneContext())
     {
         var game = context.GamesForDecks.Find(id);
         game.IsActive = false;
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
コード例 #4
0
 public ActionResult Create(GamesForDeckModel newGame)
 {
     using (var context = new HearthstoneContext())
     {
         newGame.Game.DatePlayed = DateTime.Now;
         newGame.IsActive = true;
         context.GamesForDecks.Add(newGame);
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
コード例 #5
0
 //
 // GET: /Metrics/
 public ActionResult Index(UserSettingsModel newSettings = null)
 {
     using (var context = new HearthstoneContext())
     {
         var user = (from u in context.UserProfiles.Include("DecksForUsers").Include("DecksForUsers.Deck").Include("SimpleStats")
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         if (newSettings == null)
         {
             newSettings = user.UserSettings.FirstOrDefault();
         }
         else
         {
             var oldSettings = user.UserSettings.FirstOrDefault();
             if (oldSettings == null)
             {
                 if (newSettings.Metrics == null) newSettings.Metrics = new MetricsModel();
                 if (newSettings.UserID == 0) newSettings.UserID = user.UserId;
                 context.Settings.Add(newSettings);
                 context.Metrics.Add(newSettings.Metrics);
             }
             else
             {
                 if (newSettings.Metrics != null)
                 {
                     oldSettings.Metrics.BadgeID = newSettings.Metrics.BadgeID;
                     oldSettings.Metrics.DeckID = newSettings.Metrics.DeckID;
                     oldSettings.Metrics.deckType = newSettings.Metrics.deckType;
                     oldSettings.Metrics.EndDate = newSettings.Metrics.EndDate;
                     oldSettings.Metrics.StartDate = newSettings.Metrics.StartDate;
                     oldSettings.Metrics.HeroID = newSettings.Metrics.HeroID;
                     newSettings.Metrics.MetricsModelID = oldSettings.Metrics.MetricsModelID;
                     oldSettings.Metrics.IncludeBaseStats = newSettings.Metrics.IncludeBaseStats;
                 }
                 else
                 {
                     newSettings = oldSettings;
                 }
             }
             context.SaveChanges();
         }
         if (newSettings == null) newSettings = new UserSettingsModel();
         if (newSettings.Metrics == null) newSettings.Metrics = new MetricsModel();
         if (newSettings.User == null) newSettings.User = user;
         return View(newSettings);
     }
 }
コード例 #6
0
 public ActionResult Edit(GamesForDeckModel newGame)
 {
     using (var context = new HearthstoneContext())
     {
         var gm = context.GamesForDecks.Find(newGame.GamesForDeckID);
         gm.GameID = newGame.GameID;
         gm.Game.GameWon = newGame.Game.GameWon;
         gm.Game.BadgeID = newGame.Game.BadgeID;
         gm.Game.EndLifeTotal = newGame.Game.EndLifeTotal;
         gm.Game.GameNotes = newGame.Game.GameNotes;
         gm.Game.OnTheDraw = newGame.Game.OnTheDraw;
         gm.Game.Opponent = newGame.Game.Opponent;
         gm.Game.VsHeroID = newGame.Game.VsHeroID;
         gm.DecksForUsersID = newGame.DecksForUsersID;
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
コード例 #7
0
 public ActionResult Delete(int id)
 {
     using (var context = new HearthstoneContext())
     {
         var deck = context.DecksForUsers.Find(id);
         deck.IsActive = false;
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
コード例 #8
0
 public ActionResult Edit(DecksForUsersModel deckForUser, string SelectedCardList)
 {
     using (var context = new HearthstoneContext())
     {
         var user = (from u in context.UserProfiles
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var cardList = SelectedCardList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
         var cardCount = 0;
         for (var i = 0; i < cardList.Count; i++)
         {
             cardCount += int.Parse(cardList[i].Split(new char[] { '-' })[1]);
         }
         if (cardCount < 30)
         {
             ModelState.AddModelError("CardCount", new Exception("Not enough cards."));
             ViewBag.SelectedCardList = SelectedCardList;
             ViewBag.Error = "Not enough cards.";
             return View(deckForUser);
         }
         if (cardList.Count > 30)
         {
             ModelState.AddModelError("CardCount", new Exception("Too Many cards."));
             ViewBag.SelectedCardList = SelectedCardList;
             ViewBag.Error = "Too Many cards.";
             return View(deckForUser);
         }
         DeckModel newDeck = DeckModel.GetUniqueDeck(deckForUser.Deck, SelectedCardList, context);
         deckForUser.Deck = newDeck;
         deckForUser.IsActive = true;
         deckForUser.UserID = user.UserId;
         var lastDeck = (from dfu in context.DecksForUsers
                                    where dfu.DecksForUsersID == deckForUser.DecksForUsersID
                                    orderby dfu.DeckVersion descending
                                    select dfu).FirstOrDefault();
         if (newDeck.DeckID == lastDeck.DeckID) deckForUser.DeckVersion = lastDeck.DeckVersion;
         else deckForUser.DeckVersion = lastDeck.DeckVersion + 1;
         if (lastDeck.DeckName != deckForUser.DeckName)
         {
             //find a way to ensure unique deckname, but still allow deck name to be changeable
         }
         foreach (var d in context.DecksForUsers.Where(dfu => dfu.DeckName == deckForUser.DeckName))
         {
             d.IsActive = false;
         }
         if (newDeck.DeckID == 0)
         {
             foreach (var cardID in cardList)
             {
                 var id = int.Parse(cardID.Split(new char[] { '-' })[0]);
                 var count = int.Parse(cardID.Split(new char[] { '-' })[1]);
                 if (id > 0 && context.Cards.Find(id) != null)
                 {
                     var card = new CardsInDeckModel() { CardID = id, Deck = newDeck, CardCount = count };
                     context.CardsInDecks.Add(card);
                 }
             }
         }
         context.DecksForUsers.Add(deckForUser);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
コード例 #9
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (HearthstoneContext db = new HearthstoneContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }