Exemple #1
0
        public async Task <ActionResult <CardDto> > PostCard(CardDto card)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CardDto cardDto;

            try
            {
                cardDto = await cardService.CreateCardAsync(card, User.Identity.Name);

                if (cardDto != null)
                {
                    this.RemoveCache(CacheKeys.Card);
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            // var cardDto = await _context.Cards.Select(CardDto.AsCardDto).SingleOrDefaultAsync(m => m.Id == card.Id);

            return(CreatedAtAction("GetCard", new { id = cardDto.Id }, cardDto));
        }