Ejemplo n.º 1
0
 internal static DeckModel GetUniqueDeck(DeckModel deck, string selectedCardList, HearthstoneContext context)
 {
     var deckList = context.Decks.Where(d=>d.CardsInDeck.Any()).ToList();
     foreach (var d in deckList)
     {
         if (d.HeroID != deck.HeroID) continue;
         if (d.IsArena != deck.IsArena) continue;
         var cardFound = true;
         var cardList = selectedCardList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
         foreach (var c in cardList)
         {
             var id = int.Parse(c.Split(new char[] { '-' })[0]);
             var count = int.Parse(c.Split(new char[] { '-' })[1]);
             if (d.CardsInDeck.Any(cid => cid.CardCount == count && cid.CardID == id))
             {
                 cardFound = cardFound && true;
             }
             else
             {
                 cardFound = false;
             }
         }
         if (cardFound)
         {
             return d;
         }
     }
     return deck;
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
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");
     }
 }
Ejemplo n.º 4
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");
 }
Ejemplo n.º 5
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");
 }
Ejemplo n.º 6
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");
 }
Ejemplo n.º 7
0
 public ActionResult Edit(int id)
 {
     using (var context = new HearthstoneContext())
     {
         var game = (from gfd in context.GamesForDecks.Include("Game")
                     where gfd.GamesForDeckID == id
                     select gfd).FirstOrDefault();
         ViewBag.Role = "Edit";
         return View("Create", game);
     }
 }
Ejemplo n.º 8
0
 public ActionResult Index()
 {
     using (var db = new HearthstoneContext())
     {
         var user = (from u in db.UserProfiles.Include("SimpleStats")
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var simplestats = user.SimpleStats.FirstOrDefault();
         if (simplestats == null) simplestats = new SimpleStatsModel();
         return View(simplestats);
     }
 }
Ejemplo n.º 9
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);
     }
 }
Ejemplo n.º 10
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");
 }
Ejemplo n.º 11
0
 public ActionResult Create()
 {
     ViewBag.Role = "Create";
     using (var context = new HearthstoneContext())
     {
         var user = (from u in context.UserProfiles
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var lastGame = (from gfu in context.GamesForDecks.Include("Game")
                         where gfu.Deck.UserID == user.UserId
                         orderby gfu.GamesForDeckID descending
                         select gfu).FirstOrDefault();
         var gfd = new GamesForDeckModel();
         if (lastGame != null) gfd.DecksForUsersID = lastGame.DecksForUsersID;
         gfd.Game = new GameModel();
         if (lastGame != null) gfd.Game.BadgeID = lastGame.Game.BadgeID;
         gfd.Game.EndLifeTotal = 30;
         return View(gfd);
     }
 }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<HearthstoneContext>(null);

                try
                {
                    using (var context = new HearthstoneContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 public JsonResult GetTopDecks(string orderby)
 {
     using (var context = new HearthstoneContext())
     {
         var user = (from u in context.UserProfiles
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var decks = user.UserSettings.FirstOrDefault().TopDecks;
         switch (orderby)
         {
             case "WINS ASC":
                 decks = decks.OrderBy(d => d.Wins).ToList();
                 break;
             case "WINS DESC":
                 decks = decks.OrderByDescending(d => d.Wins).ToList();
                 break;
             case "DECKNAME ASC":
                 decks = decks.OrderBy(d => d.DeckName).ToList();
                 break;
             case "DECKNAME DESC":
                 decks = decks.OrderByDescending(d => d.DeckName).ToList();
                 break;
             case "HERO ASC":
                 decks = decks.OrderBy(d => d.Hero).ToList();
                 break;
             case "HERO DESC":
                 decks = decks.OrderByDescending(d => d.Hero).ToList();
                 break;
             case "CREATOR ASC":
                 decks = decks.OrderBy(d => d.CreatedBy).ToList();
                 break;
             case "CREATOR DESC":
                 decks = decks.OrderByDescending(d => d.CreatedBy).ToList();
                 break;
             case "LOSSES ASC":
                 decks = decks.OrderBy(d => d.Losses).ToList();
                 break;
             case "LOSSES DESC":
                 decks = decks.OrderByDescending(d => d.Losses).ToList();
                 break;
             case "GAMESPLAYED ASC":
                 decks = decks.OrderBy(d => d.Wins + d.Losses).ToList();
                 break;
             case "GAMESPLAYED DESC":
                 decks = decks.OrderByDescending(d => d.Wins + d.Losses).ToList();
                 break;
             case "PERCENT ASC":
                 decks = decks.OrderBy(d => Math.Round((double)d.Wins / (d.Wins + d.Losses) * 100, 2)).ToList();
                 break;
             case "PERCENT DESC":
                 decks = decks.OrderByDescending(d => Math.Round((double)d.Wins / (d.Wins + d.Losses) * 100, 2)).ToList();
                 break;
             case "USERS ASC":
                 decks = decks.OrderBy(d => d.Wins + d.UserCount).ToList();
                 break;
             case "USERS DESC":
                 decks = decks.OrderByDescending(d => d.Wins + d.UserCount).ToList();
                 break;
         }
         return Json(decks);
     }
 }
Ejemplo n.º 15
0
 public ActionResult Details(DecksForUsersModel d, string SelectedCardList)
 {
     using (var context = new HearthstoneContext())
     {
         var user = (from u in new HearthstoneContext().UserProfiles
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var deck = (from dfu in context.DecksForUsers.Include("Deck").Include("Deck.Hero").Include("Deck.CardsInDeck").Include("Deck.CardsInDeck.Card")
                     where dfu.DecksForUsersID == d.DecksForUsersID && (dfu.IsPublic || dfu.UserID == user.UserId)
                     select dfu).FirstOrDefault();
         if (deck == null)
         {
             ViewBag.Message = "Invalid ID";
             return RedirectToAction("Index");
         }
         deck.DeckName = "Copy of " + deck.DeckName;
         deck.DeckVersion = 1;
         deck.DecksForUsersID = 0;
         ViewBag.Role = "Create";
         return View("Create", deck);
     }
 }
Ejemplo n.º 16
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");
     }
 }
Ejemplo n.º 17
0
 public ActionResult EditVersion(string name, int version)
 {
     using (var context = new HearthstoneContext())
     {
         var deck = (from dfu in context.DecksForUsers.Include("Deck").Include("Deck.CardsInDeck").Include("Deck.CardsInDeck.Card")
                     where dfu.DeckName == name && dfu.DeckVersion == version
                     select dfu).FirstOrDefault();
         ViewBag.Role = "Edit";
         ViewBag.Title = "Edit";
         var retVal = "";
         var cardList = deck.Deck.CardsInDeck.ToList();
         for (var i = 0; i < cardList.Count; i++)
         {
             if (i > 0) { retVal += ","; }
             retVal += cardList[i].CardID.ToString() + "-" + cardList[i].CardCount.ToString();
         }
         ViewBag.SelectedCardList = retVal;
         return View("Create", deck);
     }
 }
Ejemplo n.º 18
0
 public ActionResult Index(int userID = 0)
 {
     var context = new HearthstoneContext();
     var user = userID == 0 ? (from u in context.UserProfiles
                               where u.UserName == User.Identity.Name
                               select u).FirstOrDefault().UserId : userID;
     return View(context.GamesForDecks.Include("Deck").Include("Game").Include("Deck.Deck.Hero").Include("Deck.Deck").Include("Game.VsHero")
                 .Where(gfd => gfd.Deck.UserID == user && gfd.IsActive)
                 .OrderByDescending(gfd => gfd.Game.DatePlayed));
 }
Ejemplo n.º 19
0
 public ActionResult Details(int id)
 {
     using (var context = new HearthstoneContext())
     {
         var user = (from u in new HearthstoneContext().UserProfiles
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var deck = (from dfu in context.DecksForUsers.Include("Deck").Include("Deck.Hero").Include("Deck.CardsInDeck").Include("Deck.CardsInDeck.Card")
                     where dfu.DecksForUsersID == id && (dfu.IsPublic || dfu.UserID == user.UserId)
                     select dfu).FirstOrDefault();
         if (deck == null)
         {
             ViewBag.Message = "Invalid ID";
             return RedirectToAction("Index");
         }
         ViewBag.Copyable = deck.UserID != user.UserId;
         return View(deck);
     }
 }