Exemplo n.º 1
0
 public object Put(DtoPatient req)
 {
     var existing = Db.Select<Patient>(q => q.Id == req.Id).SingleOrDefault();
     if (existing == null)
         return new HttpResult {StatusCode = HttpStatusCode.NotFound};
     var updated = new Patient().PopulateWith(req);
     Db.Update(updated);
     var dtoPatients = new DtoPatient[] { new DtoPatient().PopulateWith(updated) };
     return new DtoPatientResponse(dtoPatients);
 }
Exemplo n.º 2
0
        public object Post(DtoPatient req)
        {
            var patient = Db.Select<Patient>(q => q.Id == req.Id).SingleOrDefault();
            if (patient != null)
                return new HttpResult { StatusCode = HttpStatusCode.Conflict };

            var newPatient = new Patient().PopulateWith(req);
            Db.Insert(newPatient);

            long id = Db.GetLastInsertId();

            return new HttpResult
            {
                StatusCode = HttpStatusCode.Created,
                Headers = {
                    { HttpHeaders.Location, string.Format("/api/patient/{0}", id) }
                }
            };
        }