Exemplo n.º 1
0
        public async Task <IHttpActionResult> GetCards([FromBody] CardsRequest request)
        {
            try
            {
                var response = await _deckService.GetCardsForDecks(request.DeckList);

                if (response.Succeeded)
                {
                    return(Ok(response.ResponseBody));
                }

                return(BadRequest(response.ErrorMessage));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutCards(int id, CardsRequest cards)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid card id"));
            }

            try
            {
                var entity = _context.Cards.FirstOrDefault(item => item.Id == id);

                if (entity != null)
                {
                    entity.Name    = cards.Name;
                    entity.Title   = cards.Title;
                    entity.Phone   = cards.Phone;
                    entity.Email   = cards.Email;
                    entity.Address = cards.Address;

                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CardsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(new CardsResponse()
            {
                Success = true
            }));
        }