Ejemplo n.º 1
0
        public async Task <IActionResult> CreateAsync(DeckCreateModel deckCreateModel)
        {
            var userId   = HttpContext.User.GetUserId();
            var newCards = await Task.WhenAll(deckCreateModel.Cards
                                              .Select(newCard => cardsService.CreateAsync(userId, newCard.Question, newCard.Answer)));

            var newDeck = await decksService.CreateAsync(userId, deckCreateModel.Name, newCards);

            return(CreatedAtAction(nameof(FindAsync), new { id = newDeck.Id }, new DeckModel
            {
                Id = newDeck.Id,
                Name = newDeck.Name,
                Cards = newCards
                        .ToList()
            }));
        }