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());
        }
Exemple #2
0
        public async Task <ActionResult <Product> > PostProduct(Product product)
        {
            _context.Products.Add(product);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetProduct), new { id = product.ID }, product));
        }