Exemplo n.º 1
0
        public IHttpActionResult GetDeck(int id)
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                var deckQuery = (
                    from deck in dbContext.Decks
                    where deck.Id == id
                    select new
                {
                    Id = deck.Id,
                    Name = deck.Name,
                    Cards =
                        from card in deck.Cards
                        orderby card.Suit, card.Value
                    select card
                });

                var result = deckQuery.FirstOrDefault();
                if (result == null)
                {
                    return(NotFound());
                }
                return(Ok(result));
            }
        }
Exemplo n.º 2
0
        public object[] GetAllLobbies()
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                var lobbyQuery =
                    from lobby in dbContext.Lobbies
                    select lobby;

                var result = lobbyQuery.ToArray();
                return(result);
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult GetLobby(string name)
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                var lobbyQuery =
                    from lobby in dbContext.Lobbies
                    where lobby.Name == name
                    select lobby;

                var result = lobbyQuery.FirstOrDefault();
                return(Ok(result));
            }
        }
Exemplo n.º 4
0
        public object[] GetAllCards()
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                var cards =
                    from card in dbContext.Cards
                    where card.DeckId == 1
                    orderby card.Suit, card.Value
                select card;

                var result = cards.ToArray();
                return(result);
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult Post([FromBody] Lobby lobby)
        {
            var newLobby = new Lobby
            {
                GameId  = lobby.GameId,
                GroupId = lobby.GroupId,
                Name    = lobby.Name
            };

            using (var dbContext = CardsContextManager.GetContext())
            {
                dbContext.Lobbies.Add(newLobby);
                dbContext.SaveChanges();
                return(Ok(newLobby));
            }
        }
Exemplo n.º 6
0
        public IHttpActionResult Put([FromBody] Card card, int id)
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                Card newCard   = null;
                var  cardQuery =
                    from c in dbContext.Cards
                    where c.Id == id
                    select c;

                var result = cardQuery.FirstOrDefault();

                if (result != null)
                {
                    result.DeckId             = card.DeckId;
                    result.Name               = card.Name;
                    result.Value              = card.Value;
                    result.BackImageFileName  = card.BackImageFileName;
                    result.FrontImageFileName = card.FrontImageFileName;
                    result.Suit               = card.Suit;
                }
                else
                {
                    newCard = new Card
                    {
                        DeckId             = card.DeckId,
                        Name               = card.Name,
                        Value              = card.Value,
                        BackImageFileName  = card.BackImageFileName,
                        FrontImageFileName = card.FrontImageFileName,
                        Suit               = card.Suit
                    };
                    dbContext.Cards.Add(newCard);
                }

                dbContext.SaveChanges();
                if (newCard != null)
                {
                    return(Ok(newCard));
                }
                else
                {
                    return(Ok(result));
                }
            }
        }
Exemplo n.º 7
0
        public IHttpActionResult GetCard(int value, string suit)
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                var cardQuery =
                    from card in dbContext.Cards
                    where card.DeckId == 1 && card.Value == value && card.Suit == suit
                    select card;

                var result = cardQuery.FirstOrDefault();
                if (result == null)
                {
                    return(NotFound());
                }
                return(Ok(result));
            }
        }
Exemplo n.º 8
0
        public IHttpActionResult Post([FromBody] Player player)
        {
            var newPlayer = new Player
            {
                WebSocketId = player.WebSocketId,
                Name        = player.Name,
                TeamId      = player.TeamId,
                Score       = player.Score
            };

            using (var dbContext = CardsContextManager.GetContext())
            {
                dbContext.Players.Add(newPlayer);
                dbContext.SaveChanges();
                return(Ok(newPlayer));
            }
        }
Exemplo n.º 9
0
        public IHttpActionResult GetPlayer(int id)
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                var playerQuery =
                    from player in dbContext.Players
                    where player.Id == id
                    select player;

                var result = playerQuery.FirstOrDefault();
                if (result == null)
                {
                    return(NotFound());
                }
                return(Ok(result));
            }
        }
Exemplo n.º 10
0
        public IHttpActionResult Post([FromBody] Card card)
        {
            var newCard = new Card
            {
                DeckId             = card.DeckId,
                Name               = card.Name,
                Value              = card.Value,
                BackImageFileName  = card.BackImageFileName,
                FrontImageFileName = card.FrontImageFileName,
                Suit               = card.Suit
            };

            using (var dbContext = CardsContextManager.GetContext())
            {
                dbContext.Cards.Add(newCard);
                dbContext.SaveChanges();
                return(Ok(newCard));
            }
        }
Exemplo n.º 11
0
        public object[] GetAllDecks()
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                var deckQuery = (
                    from deck in dbContext.Decks
                    select new
                {
                    Id = deck.Id,
                    Name = deck.Name,
                    Cards =
                        from card in deck.Cards
                        orderby card.Suit, card.Value
                    select card
                }).ToArray();

                var result = deckQuery.ToArray();
                return(result);
            }
        }
Exemplo n.º 12
0
        public IHttpActionResult Put([FromBody] Player player, int id)
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                Player newPlayer = null;

                var playerQuery =
                    from p in dbContext.Players
                    where p.Id == id
                    select p;

                var result = playerQuery.FirstOrDefault();

                if (result != null)
                {
                    result.TeamId = player.TeamId;
                    result.Score  = player.Score;
                }
                else
                {
                    newPlayer = new Player
                    {
                        WebSocketId = player.WebSocketId,
                        Name        = player.Name,
                        TeamId      = player.TeamId,
                        Score       = player.Score
                    };
                    dbContext.Players.Add(newPlayer);
                }

                dbContext.SaveChanges();
                if (newPlayer != null)
                {
                    return(Ok(newPlayer));
                }
                else
                {
                    return(Ok(result));
                }
            }
        }
Exemplo n.º 13
0
        public IHttpActionResult Put([FromBody] Lobby lobby, int id)
        {
            using (var dbContext = CardsContextManager.GetContext())
            {
                Lobby newLobby   = null;
                var   lobbyQuery =
                    from l in dbContext.Lobbies
                    where l.Id == id
                    select l;

                var result = lobbyQuery.FirstOrDefault();

                if (result != null)
                {
                    result.GameId  = lobby.GameId;
                    result.Name    = lobby.Name;
                    result.GroupId = lobby.GroupId;
                }
                else
                {
                    newLobby = new Lobby
                    {
                        GameId  = lobby.GameId,
                        Name    = lobby.Name,
                        GroupId = lobby.GroupId
                    };
                    dbContext.Lobbies.Add(newLobby);
                }

                dbContext.SaveChanges();
                if (newLobby != null)
                {
                    return(Ok(newLobby));
                }
                else
                {
                    return(Ok(result));
                }
            }
        }