Exemple #1
0
        // POST api/CompanyType
        public HttpResponseMessage PostCompanyType(CompanyType companytype)
        {
            if (ModelState.IsValid)
            {
                db.CompanyTypes.Add(companytype);
                db.SaveChanges();

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

            if (id != companytype.CompanyTypeID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }