Esempio n. 1
0
        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");
            }
        }
Esempio n. 2
0
        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");
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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");
            }
        }
Esempio n. 5
0
        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);
            }
        }