Exemplo n.º 1
0
        // PUT api/BD/5
        public HttpResponseMessage Puttb_empresa(long id, tb_empresa tb_empresa)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != tb_empresa.id_empresa)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(tb_empresa).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Exemplo n.º 2
0
        // POST api/BD
        public HttpResponseMessage Posttb_empresa(tb_empresa tb_empresa)
        {
            if (ModelState.IsValid)
            {
                db.tb_empresa.Add(tb_empresa);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, tb_empresa);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = tb_empresa.id_empresa }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }