public void SaveChanges() { try { var stats = new SqlTableStats { Tablename = "PatientPhoneNumbers", PreSaveCount = CompletedMappings.Count() }; // Ensure pateint id exist (has been commited) before updating database var q = from cm in CompletedMappings from ps in map.GetPatients() where cm.UserId == ps.UserId select cm; TransactionManager.DatabaseContext.PatientPhoneNumbers.AddRange(q); stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <PatientPhoneNumber>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); var saved = TransactionManager.DatabaseContext.SaveChanges(); stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved; MappingStatistics.SqlTableStatistics.Add(stats); } catch (DbEntityValidationException e) { throw new Exception("Error validating PatientPhonenumber entity", e); } catch (Exception e) { throw new Exception("Error saving PatientPhonenumber entity", e); } }
public void SaveChanges() { try { Array.ForEach(tempCompanyId.ToArray(), a => a.Item2.CompanyId = nHelper.GetInsuranceCompanyId(a.Item1)); var stats = new SqlTableStats { Tablename = "InsurancePlans", PreSaveCount = CompletedMappings.Count() }; // Ensure pateint id exist (has been commited) before updating database var q = from cm in CompletedMappings from ps in map.GetPatients() where cm.UserId == ps.UserId select cm; TransactionManager.DatabaseContext.InsurancePlans.AddRange(q); stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <InsurancePlan>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); var saved = TransactionManager.DatabaseContext.SaveChanges(); stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved; MappingStatistics.SqlTableStatistics.Add(stats); } catch (DbEntityValidationException e) { throw new Exception("Error validating InsurancePlan entity", e); } catch (Exception e) { throw new Exception("Error saving InsurancePlan entity", e); } }
public void SaveChanges() { try { var stats = new SqlTableStats("CareSettings"); var dcStats = new SqlTableStats("DiabetesControlTypes"); // Ensure pateint id exist (has been commited) before updating database var q = from cm in CompletedMappings from ps in mu.GetPatients() where cm.UserId == ps.UserId select cm; TransactionManager.DatabaseContext.CareSettings.AddRange(q); stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <CareSetting>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); dcStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <DiabetesControlType>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); var saved = TransactionManager.DatabaseContext.SaveChanges(); stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved; dcStats.PostSaveCount = (saved > dcStats.PreSaveCount) ? dcStats.PreSaveCount : saved; MappingStatistics.SqlTableStatistics.Add(stats); MappingStatistics.SqlTableStatistics.Add(dcStats); } catch (DbEntityValidationException e) { throw new Exception("Error validating CareSetting entity", e); } catch (Exception e) { throw new Exception("Error saving CareSetting entity", e); } }
public void SaveChanges() { try { var stats = new SqlTableStats { Tablename = "BloodGlucoseReadings", PreSaveCount = CompletedBGMappings.Count }; // Ensure pateint id exist (has been commited) before updating database var q = from cm in CompletedBGMappings from ps in mu.GetPatients() where cm.UserId == ps.UserId select cm; TransactionManager.DatabaseContext.BloodGlucoseReadings.AddRange(q); stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <BloodGlucoseReading>() .Where(w => w.State == System.Data.Entity.EntityState.Added) .Count(); var saved = TransactionManager.DatabaseContext.SaveChanges(); stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved; MappingStatistics.SqlTableStatistics.Add(stats); SaveTotalDailyInsulinDeliveries(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { throw new Exception("Error validating Blood Glucose Reading mapped entity", e); } catch (Exception e) { throw new Exception("Error saving Blood Glucose Reading mapped entity", e); } }
public void SaveChanges() { try { var stats = new SqlTableStats("Subscriptions"); var payStats = new SqlTableStats("Payments"); var chkStats = new SqlTableStats("Checks"); var palStats = new SqlTableStats("PayPal"); // Ensure pateint id exist (has been commited) before updating database var q = from cm in CompletedMappings from ps in mu.GetPatients() where cm.UserId == ps.UserId select cm; // Ensure subscription has a matching institution id associated var r = from m in q from i in TransactionManager.DatabaseContext.Institutions where m.InstitutionId == i.InstitutionId select m; TransactionManager.DatabaseContext.Subscriptions.AddRange(r); stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Subscription>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); payStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Payment>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); chkStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Check>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); palStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <PayPal>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); var saved = TransactionManager.DatabaseContext.SaveChanges(); stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved; payStats.PostSaveCount = (saved > payStats.PreSaveCount) ? payStats.PreSaveCount : saved; chkStats.PostSaveCount = (saved > chkStats.PreSaveCount) ? chkStats.PreSaveCount : saved; palStats.PostSaveCount = (saved > palStats.PreSaveCount) ? palStats.PreSaveCount : saved; MappingStatistics.SqlTableStatistics.Add(stats); MappingStatistics.SqlTableStatistics.Add(payStats); MappingStatistics.SqlTableStatistics.Add(chkStats); MappingStatistics.SqlTableStatistics.Add(palStats); } catch (DbEntityValidationException e) { throw new Exception("Error validating Subscription entity", e); } catch (Exception e) { throw new Exception("Error saving Subscription entity", e); } }
public void SaveChanges() { try { var stats = new SqlTableStats("PatientDevices"); var rhStats = new SqlTableStats("ReadingHeaders"); var dmStats = new SqlTableStats("DiabetesManagementData"); var pmpstats = new SqlTableStats("Pumps"); // Ensure pateint id exist (has been commited) before updating database var q = from cm in CompletedMappings from ps in mu.GetPatients() where cm.UserId == ps.UserId select cm; TransactionManager.DatabaseContext.PatientDevices.AddRange(q); stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <PatientDevice>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); rhStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <ReadingHeader>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); dmStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <DiabetesManagementData>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); pmpstats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Pump>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count(); var saved = TransactionManager.DatabaseContext.SaveChanges(); stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved; rhStats.PostSaveCount = (saved > rhStats.PreSaveCount) ? rhStats.PreSaveCount : saved; dmStats.PostSaveCount = (saved > dmStats.PreSaveCount) ? dmStats.PreSaveCount : saved; pmpstats.PostSaveCount = (saved > pmpstats.PreSaveCount) ? pmpstats.PreSaveCount : saved; MappingStatistics.SqlTableStatistics.Add(stats); MappingStatistics.SqlTableStatistics.Add(rhStats); MappingStatistics.SqlTableStatistics.Add(dmStats); MappingStatistics.SqlTableStatistics.Add(pmpstats); } catch (DbEntityValidationException e) { throw new Exception("Error validating PatientDevice entity", e); } catch (Exception e) { throw new Exception("Error saving PatientDevice entity", e); } SaveCompletedPumpSettingMappings(); }