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 }); }
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); } }
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(); }
public WorkoutController(PtDbContext db) { _db = db; }
private static async Task DropAndMigrate(PtDbContext db) { await db.Database.EnsureDeletedAsync(); await db.Database.MigrateAsync(); }
public WeightRegistrationController(PtDbContext db) { _db = db; }