Exemplo n.º 1
0
        public IActionResult GetDeckByName(string name)
        {
            var deck = deckStorage.Get(name);

            return(deck != null
                ? (IActionResult)Ok(deck)
                : BadRequest(DeckErrorMessages.NotFound(name)));
        }
Exemplo n.º 2
0
        public IActionResult DeleteDeck(string name)
        {
            if (name == "names")
            {
                return(BadRequest(DeckErrorMessages.ForbiddenName(name)));
            }

            var success = deckStorage.Delete(name);

            return(success
                ? (IActionResult)Ok()
                : BadRequest(DeckErrorMessages.NotFound(name)));
        }
Exemplo n.º 3
0
        public IActionResult ShuffleDeck(string name)
        {
            if (name == "names")
            {
                return(BadRequest(DeckErrorMessages.ForbiddenName(name)));
            }

            var deck = deckStorage.Get(name);

            if (deck == null)
            {
                return(BadRequest(DeckErrorMessages.NotFound(name)));
            }

            deck = new Deck(deck.Name, shuffler.Shuffle(deck.Cards));
            var success = deckStorage.InsertOrUpdate(deck);

            return(success
                ? (IActionResult)Ok(deck)
                : StatusCode(500));
        }
Exemplo n.º 4
0
        public IActionResult CreateDeck([FromBody] CreateArguments args)
        {
            var name = args.Name;

            if (name == "names")
            {
                return(BadRequest(DeckErrorMessages.ForbiddenName(name)));
            }

            if (deckStorage.Get(name) != null)
            {
                return(BadRequest(DeckErrorMessages.AlreadyExists(name)));
            }

            var deck    = Deck.Create52Deck(name);
            var success = deckStorage.InsertOrUpdate(deck);

            return(success
                ? (IActionResult)Ok(deck)
                : StatusCode(500));
        }