public async Task <IActionResult> GetCardFromDeckById(int id, int cardId) { bool isDeckExist = await _flashcardDataRepository.isDeckExist(id); if (!isDeckExist) { var resp = new ErrorResponse() { Errors = new List <string>() { $"Deck with Id {id} not found" } }; return(NotFound(resp)); } Card _card = await _flashcardDataRepository.GetCardFromDeckByCardId(id, cardId); CardResponseDto _cardResponseDto = _mapper.Map <CardResponseDto>(_card); return(Ok(_cardResponseDto)); }
public async Task <IActionResult> Post(int id, [FromBody] CardRequest cardRequest) { bool isDeckExist = await _flashcardDataRepository.isDeckExist(id); if (!isDeckExist) { var resp = new ErrorResponse() { Errors = new List <string>() { $"Deck with Id {id} not found" } }; return(NotFound(resp)); } Card _card = await _flashcardDataRepository.AddCardToDeck(id, cardRequest.QuestionText, cardRequest.AnswerText); CardResponseDto _cardResponseDto = _mapper.Map <CardResponseDto>(_card); return(CreatedAtAction(nameof(GetCardFromDeckById), new { id, cardId = _cardResponseDto.Id }, _cardResponseDto)); }