コード例 #1
0
        public IActionResult HasPlayed(String[][] gameList)
        {
            try
            {
                using (var db = new WgsipContext())
                {
                    foreach (var gameA in gameList)
                    {
                        var   game  = gameA[0].Split(',');
                        Int16 rate  = 3;
                        var   query = db.PlayedGames.Include(pg => pg.User).Include(pg => pg.Game)
                                      .First(pg =>
                                             pg.Game.GameName.ToLower().Equals(game[0].ToLower()) &&
                                             pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                             );

                        query.PlayedGame = game[1] == "true" ? true : false;

                        // when a game is marked as played, set the rating to 3 as a default
                        if (query.Rating == null)
                        {
                            query.Rating = rate;
                        }
                    }

                    db.SaveChanges();
                }
                return(Json(new { message = "success" }));
            }
            catch (Exception e)
            {
                return(Json(new { message = e.Message }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> DeleteAccountAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Json(new { message = "You need to be logged in to delete your account" }));
            }

            try
            {
                using (WgsipContext db = new WgsipContext())
                {
                    Account user = db.Accounts.First(a => a.AccountEmail == User.Identity.Name);
                    db.Accounts.Remove(user);
                    db.Users.Remove(db.Users.Where(u => u.Email == user.AccountEmail).First());
                    await _signInManager.SignOutAsync();

                    db.SaveChanges();
                }
                return(Json(new { message = "Account Deleted", success = true }));
            }
            catch (Exception e)
            {
                return(Json(new { message = e.Message }));
            }
        }
コード例 #3
0
 public IActionResult AddGame(String gameName, String publisher, String genre, String rating, String platforms, string year)
 {
     try
     {
         DateTime Date = new DateTime(int.Parse(year), 1, 1);
         using (WgsipContext db = new WgsipContext())
         {
             Game  newGame  = new Game();
             Genre newGenre = db.Genres.First(g => g.GenreName.ToLower().Equals(genre.ToLower()));
             newGame.EsrbRating = rating;
             Publisher newPublisher;
             try
             {
                 newPublisher = db.Publishers.First(p => p.PublisherName.ToLower().Equals(publisher.ToLower()));
             }
             catch (Exception)
             {
                 newPublisher = new Publisher();
                 newPublisher.PublisherName = publisher;
                 db.Publishers.Add(newPublisher);
             }
             newGame.Genre         = newGenre;
             newGame.Publisher     = newPublisher;
             newGame.GameName      = gameName;
             newGame.Platforms     = platforms;
             newGame.DatePublished = Date;
             db.Games.Add(newGame);
             PlayedGames playedGame = new PlayedGames();
             playedGame.Game       = newGame;
             playedGame.PlayedGame = false;
             playedGame.User       = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
             db.PlayedGames.Add(playedGame);
             db.SaveChanges();
         }
         return(Json(new { message = "successfully added game to the Games database" }));
     }
     catch (Exception e)
     {
         return(Json(new { message = e.Message }));
     }
 }
コード例 #4
0
 public IActionResult AddGameToPlayed(String gameName)
 {
     try
     {
         using (WgsipContext db = new WgsipContext())
         {
             Game        newGame    = db.Games.Include(g => g.Publisher).Include(g => g.Genre).First(g => g.GameName.ToLower().Equals(gameName.ToLower()));
             PlayedGames playedGame = new PlayedGames();
             playedGame.Game       = newGame;
             playedGame.PlayedGame = false;
             playedGame.User       = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
             db.PlayedGames.Add(playedGame);
             db.SaveChanges();
         }
         return(Json(new { message = "successfully added game to played games list" }));
     }
     catch (Exception e)
     {
         return(Json(new { message = e.Message }));
     }
 }
コード例 #5
0
        public async Task <IActionResult> CreateAccount(String username, String password)
        {
            List <string> s = new List <string>();

            if (username == null)
            {
                s.Add("You must enter an email");
            }
            if (password == null)
            {
                s.Add("Password cannot be empty");
            }
            if (password == null || username == null)
            {
                return(Json(new { a = s }));
            }
            IdentityUser user = new IdentityUser {
                UserName = username, Email = username,
            };
            IdentityResult result = await _userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                await _signInManager.SignInAsync(user, isPersistent : false);

                ViewBag.loggedIn    = User.Identity.IsAuthenticated;
                ViewBag.accountName = User.Identity.Name;
                using (var db = new WgsipContext())
                {
                    Account account = new Account();
                    account.AccountEmail = username;
                    db.Accounts.Add(account);
                    db.SaveChanges();
                }
                return(Json(new { a = true }));
            }
            return(Json(new { a = result.Errors.ToArray() }));
        }
コード例 #6
0
        public IActionResult SoundsGood(String game)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Json(new { message = "You need to be logged in to add a game to your game list." }));
            }

            try
            {
                using (WgsipContext db = new WgsipContext())
                {
                    Account     user       = db.Accounts.First(a => a.AccountEmail == User.Identity.Name);
                    Game        gameEntry  = db.Games.First(g => g.GameName.ToLower().Equals(game.ToLower()));
                    PlayedGames playedGame = new PlayedGames();
                    playedGame.User       = user;
                    playedGame.Game       = gameEntry;
                    playedGame.PlayedGame = false;
                    if (!db.PlayedGames.Include(pg => pg.Game)
                        .Include(pg => pg.User)
                        .Any(pg => pg.Game == gameEntry &&
                             pg.User == user))
                    {
                        db.PlayedGames.Add(playedGame);
                        db.SaveChanges();
                        return(Json(new { message = "Game added to your games list! 😆" }));
                    }
                    else
                    {
                        return(Json(new { message = "The game is already in your games list." }));
                    }
                }
            }
            catch (Exception e)
            {
                return(Json(new { message = e.Message }));
            }
        }
コード例 #7
0
        public IActionResult Rate(String gameName, Int16 rating)
        {
            HttpContext.Session.Remove(list_key);
            try
            {
                using (var db = new WgsipContext())
                {
                    int weight = 0;
                    switch (rating)
                    {
                    case 1:
                        weight = -2;
                        break;

                    case 2:
                        weight = -1;
                        break;

                    case 3:
                        weight = 0;
                        break;

                    case 4:
                        weight = 1;
                        break;

                    case 5:
                        weight = 2;
                        break;
                    }
                    //get gameid
                    int gameid = db.Games.Where(g => g.GameName.ToLower().Equals(gameName.ToLower())).First().GameId;
                    //get publisherid
                    int publisherid = db.Games.Include(g => g.Publisher).Where(g => g.GameName.ToLower().Equals(gameName.ToLower())).First().Publisher.PublisherId;
                    //get genreid
                    int genreid = db.Games.Include(g => g.Genre).Where(g => g.GameName.ToLower().Equals(gameName.ToLower())).First().Genre.GenreId;

                    // create list of tags assosiated with this game
                    List <GameTag> tagsForGame = db.GameTags.Include(g => g.Game).Include(g => g.Tag)
                                                 .Where(g => g.Game.GameId == gameid).ToList();
                    var played_game = db.PlayedGames.Include(pg => pg.User).Include(pg => pg.Game)
                                      .First(pg =>
                                             pg.Game.GameName.ToLower().Equals(gameName.ToLower()) &&
                                             pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                             );

                    int prevWeight = 0;
                    switch (played_game.Rating)
                    {
                    case 1:
                        prevWeight = -2;
                        break;

                    case 2:
                        prevWeight = -1;
                        break;

                    case 3:
                        prevWeight = 0;
                        break;

                    case 4:
                        prevWeight = 1;
                        break;

                    case 5:
                        prevWeight = 2;
                        break;
                    }

                    played_game.Rating = rating;
                    // adjust weight of the publisher
                    try
                    {
                        var pub = db.PublisherWeights.Include(pg => pg.User).Include(pg => pg.Publisher)
                                  .First(pg =>
                                         pg.Publisher.PublisherId == publisherid &&
                                         pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                         );
                        pub.Weight += prevWeight * -1; //remove the change from the previous rating.
                        pub.Weight += weight;
                    }
                    catch (Exception)
                    {
                        PublisherWeights pW = new PublisherWeights();
                        pW.Publisher = db.Publishers.First(p => p.PublisherId == publisherid);
                        pW.User      = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
                        pW.Weight    = weight;
                        db.PublisherWeights.Add(pW);
                    }

                    //adjust weight for the genre
                    try
                    {
                        var gen = db.GenreWeights.Include(pg => pg.User).Include(pg => pg.Genre)
                                  .First(pg =>
                                         pg.Genre.GenreId == genreid &&
                                         pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                         );
                        gen.Weight += prevWeight * -1; //remove the change from the previous rating.
                        gen.Weight += weight;
                    }
                    catch (Exception)
                    {
                        GenreWeights gW = new GenreWeights();
                        gW.Genre  = db.Genres.First(g => g.GenreId == genreid);
                        gW.User   = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
                        gW.Weight = weight;
                        db.GenreWeights.Add(gW);
                    }

                    /*tag weight is assigned for each tag a game has the tag weight is assigned
                     * the weight dived by the number of tagsa game has*/
                    foreach (GameTag tag in tagsForGame)
                    {
                        //get the tagid
                        int tagid = tag.Tag.TagId;

                        //adjust weight for each tag
                        try
                        {
                            var t = db.TagWeights.Include(pg => pg.User).Include(pg => pg.Tag)
                                    .First(pg =>
                                           pg.Tag.TagId == tagid &&
                                           pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                           );
                            t.Weight += (prevWeight / tagsForGame.Count) * -1; //remove the change from the previous rating.
                            t.Weight += (weight / tagsForGame.Count);
                        }
                        catch (Exception)
                        {
                            TagWeights tW = new TagWeights();
                            tW.Tag    = db.Tags.First(t => t.TagId == tagid);
                            tW.User   = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
                            tW.Weight = weight;
                            db.TagWeights.Add(tW);
                        }
                    }

                    db.SaveChanges();
                }
                return(Json(new { message = "success" }));
            }
            catch (Exception e)
            {
                return(Json(new { message = e.Message }));
            }
        }