public void Delete(FitnessUser fitnessUser, WorkoutRegimen workoutRegimen)
 {
     if (!isAssociated(fitnessUser, workoutRegimen))
         throw new ApplicationException(
             String.Format("Workout regimen #{0} does not belong to user #{1}.", workoutRegimen.WorkoutRegimenId, fitnessUser.FitnessUserId)
         );
     DataContext.WorkoutRegimens.DeleteOnSubmit(workoutRegimen);
 }
Пример #2
0
 public Workout GetWorkout(FitnessUser fitnessUser, int workoutRegimenId, int workoutId)
 {
     IQueryable<Workout> workoutQuery = FindAllWorkoutsByUser(fitnessUser).Where(
         w => (w.WorkoutRegimenId == workoutRegimenId) &&
              (w.WorkoutRegimen.FitnessUserId == fitnessUser.FitnessUserId)
     );
     return workoutQuery.SingleOrDefault(d => d.WorkoutId == workoutId);
 }
 // Checks if user exists, and adds if non-existant
 public void AddUserByNameIfNotExists(string userName)
 {
     if (FindByUserName(userName).ToList().Count() == 0)
     {
         FitnessUser fitnessUser = new FitnessUser();
         fitnessUser.UserName = userName;
         fitnessUser.DateCreated = DateTime.Now;
         fitnessUser.DateLastVisited = DateTime.Now;
         Add(fitnessUser);
     }
 }
 public void Delete(FitnessUser fitnessUser)
 {
     DataContext.FitnessUsers.DeleteOnSubmit(fitnessUser);
 }
 //
 // Insert/Delete Methods
 public void Add(FitnessUser fitnessUser)
 {
     DataContext.FitnessUsers.InsertOnSubmit(fitnessUser);
 }
Пример #6
0
 public IQueryable<Workout> FindAllWorkoutsByUserAndRegimen(FitnessUser fitnessUser, WorkoutRegimen regimen)
 {
     return DataContext.Workouts.Where(w => (w.WorkoutRegimen.FitnessUserId == fitnessUser.FitnessUserId) &&
                                            (w.WorkoutRegimenId == regimen.WorkoutRegimenId));
 }
Пример #7
0
 //
 // Query Methods
 public IQueryable<Workout> FindAllWorkoutsByUser(FitnessUser fitnessUser)
 {
     return DataContext.Workouts.Where(w => (w.WorkoutRegimen.FitnessUserId == fitnessUser.FitnessUserId));
 }
 partial void DeleteFitnessUser(FitnessUser instance);
 partial void UpdateFitnessUser(FitnessUser instance);
 partial void InsertFitnessUser(FitnessUser instance);
 //
 // Insert/Delete Methods
 public bool isAssociated(FitnessUser fitnessUser, WorkoutRegimen workoutRegimen)
 {
     return (fitnessUser.WorkoutRegimens.Where(
         wr => (wr.WorkoutRegimenId == workoutRegimen.WorkoutRegimenId)
     ).ToList().Count() > 0);
 }
 public WorkoutRegimen GetWorkoutRegimen(FitnessUser fitnessUser, int id)
 {
     var wrbu = FindAllWorkoutRegimensByUser(fitnessUser);
     return wrbu.SingleOrDefault(d => d.WorkoutRegimenId == id);
 }
 public IQueryable<WorkoutRegimen> FindByExerciseType(FitnessUser fitnessUser, ExerciseType exerciseType)
 {
     var wrbu = FindAllWorkoutRegimensByUser(fitnessUser);
     return wrbu.Where(wr => (wr.ExerciseTypeId == exerciseType.ExerciseTypeId));
 }
 public IQueryable<WorkoutRegimen> FindAllFinishedWorkoutRegimens(FitnessUser fitnessUser, DateTime dateTime)
 {
     var wrbu = FindAllWorkoutRegimensByUser(fitnessUser);
     return wrbu.Where(wr => (wr.StartDate.AddDays(7 * wr.NumWeeks) < dateTime));
 }
 public IQueryable<WorkoutRegimen> FindAllCurrentWorkoutRegimensByDate(FitnessUser fitnessUser, DateTime dateTime)
 {
     var wrbu = FindAllWorkoutRegimensByUser(fitnessUser);
     return wrbu.Where(wr => ((wr.StartDate <= dateTime) &&
                              (wr.StartDate.AddDays(7 * wr.NumWeeks) >= dateTime)));
 }
 public void Add(FitnessUser fitnessUser, WorkoutRegimen workoutRegimen)
 {
     fitnessUser.WorkoutRegimens.Add(workoutRegimen);
     DataContext.WorkoutRegimens.InsertOnSubmit(workoutRegimen);
 }