コード例 #1
0
        // POST api/BankAccountType
        public HttpResponseMessage PostBankAccountType(BankAccountType bankaccounttype)
        {
            if (ModelState.IsValid)
            {
                bankaccounttype.InsertBy = loginUser.UserID;
                db.BankAccountTypes.Add(bankaccounttype);
                db.SaveChanges();

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

            if (id != bankaccounttype.BankAccountTypeID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            bankaccounttype.UpdateBy = loginUser.UserID;
            db.Entry(bankaccounttype).State = EntityState.Modified;

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }