public HttpResponseMessage Post([FromBody] Nri nri) { try { using (loandbEntities entities = new loandbEntities()) { entities.Configuration.ProxyCreationEnabled = false; entities.Nris.Add(nri); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, nri); message.Headers.Location = new Uri(Request.RequestUri + nri.ID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] Nri nri) { try { using (loandbEntities entities = new loandbEntities()) { var entity = entities.Nris.FirstOrDefault(e => e.P_ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Person with P_Id " + id.ToString() + " Not Found!")); } else { entity.ID = entity.ID; entity.P_ID = entity.P_ID; entity.Nri_Country_Name = nri.Nri_Country_Name; entity.Nri_Country_Code = nri.Nri_Country_Code; entity.Nri_Tax_Resid = nri.Nri_Tax_Resid; entity.Nri_Jurid_Resid = nri.Nri_Jurid_Resid; entity.Nri_Tin = nri.Nri_Tin; entity.Nri_Birth_Country = nri.Nri_Birth_Country; entity.Nri_Birth_City = nri.Nri_Birth_City; entity.Nri_Jur_Addr = nri.Nri_Jur_Addr; entity.Nri_City = nri.Nri_City; entity.Nri_State = nri.Nri_State; entity.Nri_Zip_Post_Code = nri.Nri_Zip_Post_Code; entity.Nri_Iso = nri.Nri_Iso; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }