Ejemplo n.º 1
0
        // POST api/Default1
        public HttpResponseMessage PostCustomers(Customer customers)
        {
            if (ModelState.IsValid)
             {
                 db.Add(customers);
                 db.SaveChanges();

                 HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, customers);
                 response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = customers.IdCustomer }));
                 return response;
             }
             else
             {
                 return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
             }
        }
Ejemplo n.º 2
0
 public void Remove(Customer cst)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
        // PUT api/Default1/5
        public HttpResponseMessage PutCustomers(int id, Customer customers)
        {
            if (!ModelState.IsValid)
             {
                 return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
             }

             if (id != customers.IdCustomer)
             {
                 return Request.CreateResponse(HttpStatusCode.BadRequest);
             }

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

             return Request.CreateResponse(HttpStatusCode.OK);
        }