Beispiel #1
0
        // POST api/AccType
        public HttpResponseMessage PostAccType(AccType acctype)
        {
            if (ModelState.IsValid)
            {
                acctype.InsertBy = loginUser.UserID;
                db.AccTypes.Add(acctype);
                db.SaveChanges();

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

            if (id != acctype.AccTypeID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }