Ejemplo n.º 1
0
        // POST api/ProcesStatus
        public HttpResponseMessage PostProcesStatus(ProcesStatus processtatus)
        {
            if (ModelState.IsValid)
            {
                processtatus.InsertBy = loginUser.UserID;
                db.ProcesStatus.Add(processtatus);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, processtatus);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = processtatus.ProcesStatusID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Ejemplo n.º 2
0
        // PUT api/ProcesStatus/5
        public HttpResponseMessage PutProcesStatus(long id, ProcesStatus processtatus)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != processtatus.ProcesStatusID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }