Exemplo n.º 1
0
        public async Task <IActionResult> PutPost(Post post)
        {
            if (!PostExists(post.ID))
            {
                return(NotFound());
            }

            try
            {
                _context.Entry(post).State = EntityState.Modified;
            }
            catch (Exception e) { }


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostExists(post.ID))
                {
                    return(NotFound());
                }
                else
                {
                    return(Conflict());
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateProduct(Product product)
        {
            Product productToUpdate = await _context.Products.FindAsync(product.ID);

            ModelState.IsValid.ToString();

            if (productToUpdate == null)
            {
                return(NotFound());
            }

            productToUpdate.Name    = product.Name;
            productToUpdate.Details = product.Details;
            productToUpdate.Price   = product.Price;

            _context.Entry(productToUpdate).Property("RowVersion").OriginalValue = product.RowVersion;

            try
            {
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (DbUpdateConcurrencyException e) { return(Conflict()); }
        }