public HttpResponseMessage Put(int id, [FromBody] EmpGold empgold) { try { using (loandbEntities entities = new loandbEntities()) { var entity = entities.EmpGolds.FirstOrDefault(e => e.P_ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Person with P_Id " + id.ToString() + " Not Found!")); } else { entity.Ge_Occ_Type = empgold.Ge_Occ_Type; entity.Ge_Org_Type = empgold.Ge_Org_Type; entity.Ge_Emp_Buss_Name = empgold.Ge_Emp_Buss_Name; entity.Ge_Designation = empgold.Ge_Designation; entity.Ge_Curr_Work_Years = empgold.Ge_Curr_Work_Years; entity.Ge_Total_work_Years = empgold.Ge_Total_work_Years; entity.Ge_Net_Ann_Inc = empgold.Ge_Net_Ann_Inc; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] EmpGold empgold) { try { using (loandbEntities entities = new loandbEntities()) { entities.Configuration.ProxyCreationEnabled = false; entities.EmpGolds.Add(empgold); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, empgold); message.Headers.Location = new Uri(Request.RequestUri + empgold.ID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }