Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        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();
                }
            }
        }