コード例 #1
0
ファイル: PassportController.cs プロジェクト: pooranprasad/c2
        // POST api/Passport
        public HttpResponseMessage PostPassport(Passport passport)
        {
            if (ModelState.IsValid)
            {
                db.Passports.Add(passport);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, passport);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = passport.PassportId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
ファイル: PassportController.cs プロジェクト: pooranprasad/c2
        // PUT api/Passport/5
        public HttpResponseMessage PutPassport(Guid id, Passport passport)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != passport.PassportId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }