public HttpResponseMessage put(int id, WORKEXPERIENCE workexperience) { try { using (WorkExperienceEntities entities = new WorkExperienceEntities()) { var entity = entities.WORKEXPERIENCE.FirstOrDefault(e => e.WorkExperienceId == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "WorkExperience doesnt exist")); } else { entity.WorkExperienceId = workexperience.WorkExperienceId; entity.EmployeeId = workexperience.EmployeeId; entity.DocumentId = workexperience.DocumentId; entity.CompanyName = workexperience.CompanyName; entity.JobTitle = workexperience.JobTitle; entity.StartDate = workexperience.StartDate; entity.Enddate = workexperience.Enddate; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage post([FromBody] WORKEXPERIENCE workexperience) { try { using (WorkExperienceEntities entities = new WorkExperienceEntities()) { entities.WORKEXPERIENCE.Add(workexperience); entities.SaveChanges(); HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, workexperience); message.Headers.Location = new Uri(Request.RequestUri + workexperience.WorkExperienceId.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage delete(int id) { try { using (WorkExperienceEntities entities = new WorkExperienceEntities()) { var entity = entities.WORKEXPERIENCE.FirstOrDefault(e => e.WorkExperienceId == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "WorkExperience doesnt exist")); } else { entities.WORKEXPERIENCE.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }