Beispiel #1
0
        // POST api/AccCOAMapping
        public HttpResponseMessage PostAccCOAMapping(AccCOAMapping acccoamapping)
        {
            if (ModelState.IsValid)
            {
                acccoamapping.InsertBy = loginUser.UserID;
                db.Entry(acccoamapping).State = acccoamapping.COAMappingID == 0 ?
                  EntityState.Added : EntityState.Modified;
                //db.AccCOAMappings.Add(acccoamapping);
                db.SaveChanges();

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

            if (id != acccoamapping.COAMappingID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }