public IEnumerable <Pacient> GetAllPacients() { using (PacientContext ctx = new PacientContext()) { return(ctx.Pacients.ToList()); } }
public Pacient GetPacient(int id) { using (PacientContext ctx = new PacientContext()) { return(ctx.Pacients.Where(p => p.PacientId == id).First()); } }
public Pacient AddPacient(Pacient pacient) { using (PacientContext ctx = new PacientContext()) { ctx.Pacients.Add(pacient); ctx.SaveChanges(); return(pacient); } }
public Pacient RemovePacient(int id) { using (PacientContext ctx = new PacientContext()) { //trow exception if only one Pacient pacient = ctx.Pacients.Where(p => p.PacientId == id).First(); ctx.Pacients.Remove(pacient); ctx.SaveChanges(); return(pacient); } }
public HttpResponseMessage Post([FromBody] Pacient pacient) { try { using (PacientContext ctx = new PacientContext()) { Pacient newPacient = _pacientService.AddPacient(pacient); //return 201 Created var msg = Request.CreateResponse(HttpStatusCode.Created, pacient); //included location msg.Headers.Location = new Uri(Request.RequestUri + pacient.PacientId.ToString()); return(msg); } }catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e)); } }