Ejemplo n.º 1
0
        // PUT api/DetailType/5
        public HttpResponseMessage PutDetailType(int id, DetailType detailtype)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != detailtype.DetailTypeId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Ejemplo n.º 2
0
        // POST api/DetailType
        public HttpResponseMessage PostDetailType(DetailType detailtype)
        {
            if (ModelState.IsValid)
            {
                db.DetailTypes.Add(detailtype);
                db.SaveChanges();

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