Пример #1
0
        // POST api/metodopagoes
        public HttpResponseMessage Postmetodopago(metodopago metodopago)
        {
            if (ModelState.IsValid)
            {
                db.metodopagoes.Add(metodopago);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, metodopago);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = metodopago.id }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Пример #2
0
        // DELETE api/metodopagoes/5
        public HttpResponseMessage Deletemetodopago(int id)
        {
            metodopago metodopago = db.metodopagoes.Find(id);

            if (metodopago == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.metodopagoes.Remove(metodopago);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, metodopago));
        }
Пример #3
0
        // PUT api/metodopagoes/5
        public HttpResponseMessage Putmetodopago(int id, metodopago metodopago)
        {
            if (ModelState.IsValid && id == metodopago.id)
            {
                db.Entry(metodopago).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }