Exemple #1
0
        public async Task <IActionResult> UpdateDeck(int deckId, AddDeckRequest request)
        {
            var deck = await context.Deck.Include(d => d.Faction).Include(d => d.DeckCards).SingleOrDefaultAsync(d => d.Id == deckId);

            if (deck == null)
            {
                return(NotFound());
            }

            var owner = await userManager.FindByNameAsync(User.Identity.Name);

            if (owner == null)
            {
                return(NotFound());
            }

            var cardsByCode = (await context.Card.ToListAsync()).ToDictionary(key => key.Code, value => value);

            deck.Name         = request.Deck.Name;
            deck.LastModified = DateTime.UtcNow;
            deck.FactionId    = (await context.Faction.SingleOrDefaultAsync(f => f.Code == request.Deck.Faction.Code)).Id;

            UpdateDeckCards(deck, request.Deck.Cards, DeckCardType.Normal, cardsByCode);
            UpdateDeckCards(deck, request.Deck.RookeryCards, DeckCardType.Rookery, cardsByCode);

            return(this.SuccessResponse());
        }
Exemple #2
0
        public async Task <IActionResult> AddDeck([FromBody] AddDeckRequest request)
        {
            var newDeck = await GetDeckFromApiDeckAsync(request.Deck);

            context.Deck.Add(newDeck);

            await context.SaveChangesAsync();

            return(this.SuccessResponse());
        }
Exemple #3
0
        public async Task <IActionResult> ValidateDeck(AddDeckRequest request)
        {
            var deck = await GetDeckFromApiDeckAsync(request.Deck);

            var validationResult = await deckValidationService.ValidateDeckAsync(deck);

            return(Json(new ValidateDeckResponse {
                Success = true, Result = validationResult
            }));
        }