public async Task <ActionResult> Details(EditGameListViewModel editGame) { if (ModelState.IsValid) { string currentUserID = User.Identity.GetUserId(); GameDescrip editedGame = Database.GDescriptions.Where(x => x.userId == currentUserID && x.appID == editGame.AppId).Single(); editedGame.userComments = editGame.Comment; List <Tag> tags = new List <Tag>(); foreach (var item in editGame.GameTagIds) { tags.Add(Database.Tags.Find(item)); } TagList taglist = new TagList() { appID = editGame.AppId, userID = currentUserID, Tags = tags }; editedGame.Tags = taglist; Database.Entry(editedGame).State = EntityState.Modified; await Database.SaveChangesAsync(); return(RedirectToAction("Details")); } return(View(editGame)); }
// GET: GameLists/Create public ActionResult Create() { string currentUserID = User.Identity.GetUserId(); ApplicationUser currentUser = Database.Users.Find(currentUserID); string providerKey = currentUser.Logins.First().ProviderKey; providerKey = providerKey.Substring(providerKey.Length - 17); SteamWebAPI.SetGlobalKey(Security.apiKey); var identity = SteamIdentity.FromSteamID(Int64.Parse(providerKey)); //JSON response from Steam var response = SteamWebAPI.General().IPlayerService().GetOwnedGames(identity).IncludeAppInfo().GetResponse(); //Iterate through each item and add it to database foreach (var res in response.Data.Games) { TimeSpan timeSpan = res.PlayTimeTotal; int totalHours = (int)timeSpan.TotalHours; TagList tagList = new TagList() { appID = res.AppID, userID = currentUserID }; GameDescrip gameDesc = new GameDescrip() { appID = res.AppID, playtime_forever = totalHours, userId = currentUserID, visible = true, //True by default for now. Tags = tagList }; Game game = new Game(); if (res.Name != null) { game.name = res.Name; } else { game.name = res.AppID.ToString(); } game.appID = res.AppID; game.img_header_url = "http://cdn.akamai.steamstatic.com/steam/apps/" + res.AppID + "/header.jpg"; game.img_icon_url = "http://media.steampowered.com/steamcommunity/public/images/apps/" + res.AppID + "/" + res.IconUrl + ".jpg"; game.img_logo_url = "http://media.steampowered.com/steamcommunity/public/images/apps/" + res.AppID + "/" + res.LogoUrl + ".jpg"; //Ensure User entry for game doesn't exist in table bool doesLibraryExist = (Database.GDescriptions.Any(u => u.userId.Equals(gameDesc.userId)) && Database.GDescriptions.Any(a => a.appID.Equals(game.appID))); //AppID //Ensure Game doesn't already exist in game table bool doesGameExist = Database.Games.Any(a => a.appID.Equals(game.appID)); if (doesLibraryExist) { // Do nothing } else { if (doesGameExist) { //Add existing game object gameDesc.Game = Database.Games.Where(a => a.appID == game.appID).SingleOrDefault(); } else { //add newly created game object gameDesc.Game = game; Database.Games.Add(game); } //Add User Record for game Database.GDescriptions.Add(gameDesc); } } currentUser.GameCount = response.Data.GameCount; Database.SaveChanges(); return(RedirectToAction("Index")); }