コード例 #1
0
        // POST api/PassportVisa
        public HttpResponseMessage PostPassportVisa(PassportVisa passportvisa)
        {
            if (ModelState.IsValid)
            {
                db.PassportVisas.Add(passportvisa);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, passportvisa);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = passportvisa.PassportVisaId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
        // PUT api/PassportVisa/5
        public HttpResponseMessage PutPassportVisa(Guid id, PassportVisa passportvisa)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != passportvisa.PassportVisaId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }