private async Task <IResource> CreatePatient(IResource input) { var visiPatient = _resourceMapper.MapViSiPatient(input); await _visiContext.Patient.AddAsync(visiPatient); await _visiContext.SaveChangesAsync(); // return the new resource as it was stored by this server return(_resourceMapper.MapPatient(_visiContext.Patient.Last())); }
private async Task <IResource> CreatePatient(IResource input) { var visiPatient = _resourceMapper.MapViSiPatient(input); await _visiContext.Patient.AddAsync(visiPatient); if (visiPatient.Id < 0) //No Id is assigned yet, let the database create one. { await _visiContext.SaveChangesAsync(); } else { using (var transaction = await _visiContext.Database.BeginTransactionAsync()) { try { //It can happen that in the database you target, an IDENTITY column is used. You can use a provided id //by setting IDENTITY_INSERT to ON temporarily. await _visiContext.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT dbo.Patient ON"); await _visiContext.SaveChangesAsync(); await _visiContext.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT dbo.Patient OFF"); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } // return the new resource as it was stored by this server return(_resourceMapper.MapPatient(_visiContext.Patient.Last())); }
private async Task <SearchResult> SearchPatient(IArgumentCollection arguments, SearchOptions options) { var query = _queryContext.CreateQuery(new PatientQueryFactory(_visiContext), arguments, options); var count = await query.ExecuteCount(_visiContext); var patientResources = new List <IResource>(); if (count > 0) { var visiPatients = await query.Execute(_visiContext).ToListAsync(); foreach (var visiPatient in visiPatients) { patientResources.Add(_resourceMapper.MapPatient(visiPatient)); } } return(new SearchResult(patientResources, query.GetPageSize(), count, query.GetSkip())); }