Пример #1
0
        public HttpResponseMessage PutUsuarios(Categoria categoria)
        {
            if (categoria == null) return Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {
                db.Entry<Categoria>(categoria).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                var result = categoria;
                return Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao alterar categoria.");
            }
        }
Пример #2
0
        public HttpResponseMessage PostCategorias(Categoria categoria)
        {
            if (categoria == null) return Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {
                db.Categorias.Add(categoria);
                db.SaveChanges();

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