Example #1
0
        // POST api/VoucherType
        public HttpResponseMessage PostVoucherType(VoucherType vouchertype)
        {
            if (ModelState.IsValid)
            {
                vouchertype.InsertBy = loginUser.UserID;
                db.VoucherTypes.Add(vouchertype);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, vouchertype);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = vouchertype.VoucherTypeID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Example #2
0
        // PUT api/VoucherType/5
        public HttpResponseMessage PutVoucherType(long id, VoucherType vouchertype)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != vouchertype.VoucherTypeID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            vouchertype.UpdateBy = loginUser.UserID;

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }