Example #1
0
        // POST api/SupplierType
        public HttpResponseMessage PostSupplierType(SupplierType suppliertype)
        {
            if (ModelState.IsValid)
            {
                suppliertype.InsertBy = loginUser.UserID;
                db.SupplierTypes.Add(suppliertype);
                db.SaveChanges();

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

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }