コード例 #1
0
        public HttpResponseMessage PutProduct(Product product)
        {
            if (product == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {
                _context.Entry<Product>(product).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();

                var result = product;
                return Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao alterar produto");
            }
        }
コード例 #2
0
ファイル: ProductsController.cs プロジェクト: imatos/DevStore
        public HttpResponseMessage PatchProduct(Product product)
        {
            if (product == null)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            try
            {
                _db.Entry(product).State = EntityState.Modified;
                _db.SaveChanges();

                return Request.CreateResponse(HttpStatusCode.OK, product);
            }
            catch (Exception)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Falha ao alterar produto");
            }
        }
コード例 #3
0
        public HttpResponseMessage PostProducts(Product product)
        {
            if (product == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {
                _context.Products.Add(product);
                _context.SaveChanges();

                var result = product;
                return Request.CreateResponse(HttpStatusCode.Created, result);
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao incluir produto");
            }

        }
コード例 #4
0
ファイル: ProductsController.cs プロジェクト: imatos/DevStore
        public HttpResponseMessage PostProduct(Product product)
        {
            if (product == null)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            try
            {
                _db.Products.Add(product);
                _db.SaveChanges();

                return Request.CreateResponse(HttpStatusCode.Created, product);
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Falha ao incluir produto");
            }
        }