Esempio n. 1
0
        public HttpResponseMessage PutEnderecos(Endereco endereco)
        {
            if (endereco == null) return Request.CreateResponse(HttpStatusCode.BadRequest);

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

                var result = endereco;
                return Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao alterar endereço.");
            }
        }
Esempio n. 2
0
        public HttpResponseMessage PostEnderecos(Endereco endereco)
        {
            if (endereco == null) return Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {
                db.Enderecos.Add(endereco);
                db.SaveChanges();

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