public async Task <IActionResult> AddCard([FromRoute] Guid deckId, [FromForm] CreationCardDto dto) { if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } var deck = await deckRepo.FindAsync(deckId); if (deck is null) { return(NotFound()); } var cardDbo = mapper.Map <CreationCardDto, CardDbo>(dto); cardDbo.ImagePath = await ImageStore.SaveImage(dto.Image?.OpenReadStream(), '.' + dto.Image?.FileName.Split('.')[1]); cardDbo = await deckRepo.AddCard(deckId, cardDbo); if (cardDbo is null) { throw new AggregateException(); } return(CreatedAtRoute(nameof(GetCardById), new { deckId, cardId = cardDbo.Id }, mapper.Map <CardDbo, CardResult>(cardDbo))); }
public async Task IsCreationCardWithoutImageSuccessful(CreationCardDto dto) { var dbo = mapper.Map <CardDbo>(dto); var result = await cardRepository.AddAsync(dbo); var found = await cardRepository.FindAsync(result.Id); result.Answer.Should().BeEquivalentTo(dbo.Answer); result.Question.Should().BeEquivalentTo(dbo.Question); result.ImagePath.Should().BeNull(); found.Should().Be(result); }