public HttpResponseMessage PostHospitalDetail(object HospitalDetailobj) { JavaScriptSerializer js = new JavaScriptSerializer(); var json = HospitalDetailobj; Hospital hospital = js.Deserialize <Hospital>(json.ToString()); if (ModelState.IsValid) { HospitalsRepository.Add(hospital); unitOfWork.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, hospital); response.Content = new StringContent(hospital.HospitalId.ToString()); return(response); } else { var errors = ModelState.Values.SelectMany(v => v.Errors); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public HttpResponseMessage Delete(int id) { Hospital hospital = HospitalsRepository.Get(t => t.HospitalId == id); if (hospital == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } HospitalsRepository.Delete(hospital); try { unitOfWork.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, hospital)); }
// PUT api/<controller> public HttpResponseMessage UpdateHospital(int id, Hospital hospital) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != hospital.HospitalId) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } HospitalsRepository.Attach(hospital); try { unitOfWork.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public Hospital Get(int id) { return(HospitalsRepository.Get(t => t.HospitalId == id)); }
public IEnumerable <Hospital> GetHospitals() { return(HospitalsRepository.GetAll()); }