Esempio n. 1
0
        public async Task <IActionResult> PutToy(int id, ToyViewModel toyModel)
        {
            if (id != toyModel.Id)
            {
                return(BadRequest());
            }

            var toy = new Toy
            {
                Id    = id,
                Name  = toyModel.Name,
                Price = Currency.Parse(toyModel.Price)
            };

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

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

            return(Ok());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutMessage(long id, Message message)
        {
            if (id != message.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutAddress(long id, [FromForm] Address address)
        {
            if (id != address.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }