コード例 #1
0
 public IEnumerable <Pacient> GetAllPacients()
 {
     using (PacientContext ctx = new PacientContext())
     {
         return(ctx.Pacients.ToList());
     }
 }
コード例 #2
0
 public Pacient GetPacient(int id)
 {
     using (PacientContext ctx = new PacientContext())
     {
         return(ctx.Pacients.Where(p => p.PacientId == id).First());
     }
 }
コード例 #3
0
        public Pacient AddPacient(Pacient pacient)
        {
            using (PacientContext ctx = new PacientContext())
            {
                ctx.Pacients.Add(pacient);
                ctx.SaveChanges();

                return(pacient);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 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));
     }
 }