public async Task <IActionResult> PutCustomers(int id, Customers customers)
        {
            if (id != customers.Id)
            {
                return(BadRequest());
            }

            _context.Entry(customers).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #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
            }));
        }