public void LinkGamesOwnedToMember(Member member) { try { using (var dbo = new websiteContext()) { foreach (Game game in member.OwnedGames) { MemberOwnedGames exists = dbo.MemberOwnedGames.FirstOrDefault(x => x.MemberId == member.MemberId && x.GameId == game.GameId); if (exists is null) { MemberOwnedGames newRecord = new MemberOwnedGames(); //newRecord.Member = member; newRecord.MemberId = member.MemberId; // newRecord.Game = game; newRecord.GameId = game.GameId; dbo.MemberOwnedGames.Add(newRecord); } } dbo.SaveChanges(); } } catch (Exception e) { throw new Exception("Couold not save MemberGamesOwned"); } }
public string SaveMember(Member member) { try { Member alreadyThere = null; using (var dbo = new websiteContext()) { alreadyThere = dbo.Members.FirstOrDefault(m => m.MemberId == member.MemberId); } if (alreadyThere is null) { db.Add <Member>(member); } else { db.Update(member); } db.SaveChanges(); return("success"); }catch (Exception e) { return("failure"); } }
public Member GetMemberById(int id) { Member member = null; try { using (var dbo = new websiteContext()) { member = dbo.Members.FirstOrDefault(m => m.MemberId == id); } }catch (Exception e) { return(member); } return(member); }
public List <Game> GetMemberOwnedGames(int memberId) { try { List <Game> games; using (var dbo = new websiteContext()) { games = dbo.MemberOwnedGames .Where(x => x.MemberId == memberId) .Select(x => x.Game).ToList(); } return(games); }catch (Exception e) { throw new Exception("Could not get want to play games"); } }
public List <Game> SaveGamesToDatabase(List <Game> games) { using (var dbo = new websiteContext()) { foreach (Game game in games) { int test = 5; Game gameExists = dbo.Games.FirstOrDefault(g => g.ApiId == game.ApiId); if (gameExists is null) { dbo.Games.Add(game); } else { game.GameId = gameExists.GameId; } } dbo.SaveChanges(); return(games); } }