private void SeedPatient(PatientViewModel[] patientList) { using (IServiceScope scope = this.server.Host.Services.GetService <IServiceScopeFactory>().CreateScope()) { IMapper mapper = this.server.Host.Services.GetService <IMapper>(); using (SeedDotnetContext context = scope.ServiceProvider.GetRequiredService <SeedDotnetContext>()) { foreach (PatientViewModel patient in patientList) { context.Patients.Add(mapper.Map <Patient>(patient)); } context.SaveChanges(); } } }
private void ClearPatientData() { using (IServiceScope scope = this.server.Host.Services.GetService <IServiceScopeFactory>().CreateScope()) { using (SeedDotnetContext context = scope.ServiceProvider.GetRequiredService <SeedDotnetContext>()) { List <Patient> patients = context.Patients.ToList(); foreach (Patient patient in patients) { context.Patients.Remove(patient); } context.SaveChanges(); } } }
/// <summary> /// /// </summary> /// <param name="context"></param> public UnitOfWork(SeedDotnetContext context) { this.context = context; this.Patients = new PatientRepository(this.context); this.Allergies = new AllergyRepository(this.context); }
/// <summary> /// Set the context of the app /// </summary> /// <param name="_context"></param> public RepositoryBase(SeedDotnetContext _context) { this.context = _context; }
/// <summary> /// Set the context of the app /// </summary> /// <param name="_context"></param> public SeedDotnetRepository(SeedDotnetContext _context) { this.context = _context; }
public AllergyRepository(SeedDotnetContext context) : base(context) { }
public PatientRepository(SeedDotnetContext context) : base(context) { }