Beispiel #1
0
        // POST api/Designation
        public HttpResponseMessage PostDesignation(Designation designation)
        {
            if (ModelState.IsValid)
            {
                designation.InsertBy = loginUser.UserID;
                db.Designations.Add(designation);
                db.SaveChanges();

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

            if (id != designation.DesignationID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            designation.UpdateBy = loginUser.UserID;

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }