// POST api/PurchaseRequisition
        public HttpResponseMessage PostPurchaseRequisition(PurchaseRequisition purchaserequisition)
        {
            if (ModelState.IsValid)
            {
                string CustomCode = "APR-" + DateTime.Now.ToString("yyyyMMdd");

                int? MaxCode = Convert.ToInt32((db.PurchaseRequisitions.Where(r => r.PurchaseRequisitionCode.StartsWith(CustomCode)).Select(r => r.PurchaseRequisitionCode.Substring(CustomCode.Length, 4)).ToList()).Max());
                string PQCode = CustomCode + ((MaxCode + 1).ToString()).PadLeft(4, '0');
                purchaserequisition.PurchaseRequisitionCode = PQCode;
                purchaserequisition.InsertBy = loginUser.UserID;

                db.PurchaseRequisitions.Add(purchaserequisition);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, purchaserequisition);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = purchaserequisition.PurchaseRequisitionID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
        // PUT api/PurchaseRequisition/5
        public HttpResponseMessage PutPurchaseRequisition(long id, PurchaseRequisition purchaserequisition)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != purchaserequisition.PurchaseRequisitionID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            purchaserequisition.ProcesStatus = null;
            purchaserequisition.Collaborator = null;
            purchaserequisition.WorkPlant = null;
            purchaserequisition.UpdateBy = loginUser.UserID;

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }