Пример #1
0
        // PUT api/PaymentMethod/5
        public HttpResponseMessage PutPaymentMethod(long id, PaymentMethod paymentmethod)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != paymentmethod.PaymentMethodID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Пример #2
0
        // POST api/PaymentMethod
        public HttpResponseMessage PostPaymentMethod(PaymentMethod paymentmethod)
        {
            if (ModelState.IsValid)
            {
                paymentmethod.InsertBy = loginUser.UserID;
                db.PaymentMethods.Add(paymentmethod);
                db.SaveChanges();

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