Exemple #1
0
        private static void CreateMoreWorkouts(PtDbContext db)
        {
            AddNew("Cycling");
            AddNew("Running");
            AddNew("Swimming");
            AddNew("Walking");
            AddNew("Fitness");

            void AddNew(string name) => db.Workouts.Add(new Workout {
                Name = name
            });
        }
Exemple #2
0
        private static void CreateWorkoutCalenderItems(PtDbContext db, Workout workout)
        {
            var day = DateTimeOffset.Now.Date;

            for (int i = 0; i < 100; i++)
            {
                db.WorkoutCalenderItem.Add(new WorkoutCalenderItem
                {
                    Workout = workout,
                    Date    = day
                });

                day = day.AddDays(1);
            }
        }
Exemple #3
0
        private static async Task CreateSampleWorkoutCalenderItems()
        {
            var optionsBuilder = new DbContextOptionsBuilder <PtDbContext>();

            optionsBuilder.UseSqlServer("Server=(local);Database=PT;User Id=guest;Password=guest");

            await using var db = new PtDbContext(optionsBuilder.Options);
            await DropAndMigrate(db);

            var workout = CreateWorkout();

            db.Workouts.Add(workout);
            CreateMoreWorkouts(db);

            CreateWorkoutCalenderItems(db, workout);

            await db.SaveChangesAsync();
        }
Exemple #4
0
 public WorkoutController(PtDbContext db)
 {
     _db = db;
 }
Exemple #5
0
        private static async Task DropAndMigrate(PtDbContext db)
        {
            await db.Database.EnsureDeletedAsync();

            await db.Database.MigrateAsync();
        }
Exemple #6
0
 public WeightRegistrationController(PtDbContext db)
 {
     _db = db;
 }