コード例 #1
0
        private static void AddDoctors(
            DentalSystemDbContext context,
            UserManager <User> userManager)
        {
            var current    = System.IO.Directory.GetCurrentDirectory();
            var imagePaths = System.IO.Directory.EnumerateFiles(
                $"{System.IO.Directory.GetParent(current)}\\assets".ToString())
                             .ToList();

            for (int i = 0; i < 4; ++i)
            {
                var file = new File
                {
                    Data        = System.IO.File.ReadAllBytes(imagePaths[i]),
                    ContentType = "image/png"
                };
                context.Files.Add(file);
                context.SaveChanges();

                var email  = Faker.Internet.Email();
                var doctor = new User
                {
                    File           = file,
                    UserName       = email,
                    Email          = email,
                    Type           = UserType.Doctor,
                    PhoneNumber    = Faker.Phone.Number(),
                    Name           = Faker.Name.FullName(),
                    EmailConfirmed = true,
                };

                userManager.CreateAsync(doctor, DEFAULT_PASS).Wait();
            }
        }
コード例 #2
0
 private static void AddManipulations(DentalSystemDbContext context)
 {
     context.Manipulations.AddRange(
         new Manipulation {
         Name = "Teeth Whitening", Duration = TimeSpan.FromMinutes(40), Price = 80
     },
         new Manipulation {
         Name = "Bonding", Duration = TimeSpan.FromMinutes(90), Price = 150
     },
         new Manipulation {
         Name = "Braces", Duration = TimeSpan.FromMinutes(60), Price = 100
     },
         new Manipulation {
         Name = "Extractions ", Duration = TimeSpan.FromMinutes(30), Price = 50
     },
         new Manipulation {
         Name = "Root Canals", Duration = TimeSpan.FromMinutes(120), Price = 300
     });
     context.SaveChanges();
 }
コード例 #3
0
        private static void AddAppointments(
            DentalSystemDbContext context,
            UserManager <User> userManager,
            int count)
        {
            var random = new Random();

            var patients = context.Users
                           .Where(x => x.Type == UserType.Ordinary)
                           .ToList();

            var doctors = context.Users
                          .Where(x => x.Type == UserType.Doctor)
                          .ToList();

            var manupilations = context.Manipulations.ToList();

            for (int i = 0; i < count; ++i)
            {
                var patient = patients[random.Next(patients.Count)];
                var doctor  = doctors[random.Next(doctors.Count)];

                DateTime dateTime = DateTime.Now;

                var num = random.Next();
                if (num % 2 == 0)
                {
                    dateTime = dateTime.AddDays(random.Next(10, 1000));
                }
                else
                {
                    dateTime = dateTime.Subtract(TimeSpan.FromDays(random.Next(10, 1000)));
                }

                var appointment = new Appointment()
                {
                    User     = patient,
                    Doctor   = doctor,
                    DateTime = dateTime,
                    Status   = num % 7 == 0
                        ? AppointmentStatus.Canceled
                        : dateTime > DateTime.Now
                            ? AppointmentStatus.Scheduled
                            : AppointmentStatus.Done,
                };
                context.Appointments.Add(appointment);

                var manipulatioIds = Enumerable
                                     .Range(1, 4)
                                     .Select(x => random.Next(manupilations.Count))
                                     .Distinct();

                appointment.Manipulations = manipulatioIds
                                            .Select(mId => new ManipulationAppointment
                {
                    Appointment  = appointment,
                    Manipulation = manupilations.ToList()[mId]
                })
                                            .ToList();

                context.ManipulationsAppointments.AddRange(appointment.Manipulations);
                context.SaveChanges();
            }
        }