// POST api/Company public HttpResponseMessage PostCompany(Company company) { if (ModelState.IsValid) { company.InsertBy = loginUser.UserID; db.Companies.Add(company); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, company); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = company.CompanyID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/Company/5 public HttpResponseMessage PutCompany(long id, Company company) { company.CompanyType = null; company.CompanyCategory = null; company.Country = null; company.City =null; company.Currency = null; company.Language = null; company.UpdateBy = loginUser.UserID; if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != company.CompanyID) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(company).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }