public List<ScheduledRoutine> getRoutines()
 {
     using (var context = new Layer2Container())
     {
         return context.ScheduledRoutines.OrderBy(o => o.startTime).ToList();
     }
 }
    public List<scheduledItem> getScheduledItemsByDay(Int32 userID, DateTime day)
    {
        using (var context = new Layer2Container())
        {
            var ruleDate = Convert.ToDateTime(day).Date;
            var routines = from r in context.ScheduledRoutines
                           orderby r.startTime
                           where (r.LimitBreaker.id == userID && r.startTime.Day == day.Day)
                           select new scheduledItem
                           {
                               itemName = r.Routine.name,
                               startTime = r.startTime,
                               user = r.LimitBreaker,
                               isExericse = false
                           };
            var exercises = from e in context.ScheduledExercises
                            orderby e.startTime
                            where (e.LimitBreakers.id == userID && e.startTime.Day == day.Day)
                            select new scheduledItem
                            {
                                itemName = e.Exercise.name,
                                startTime = e.startTime,
                                user = e.LimitBreakers,
                                isExericse = true
                            };
            var items = routines.Concat(exercises).ToList();

            return items.ToList();
        }
    }
    //BIG F*****G ISSUE WITH THIS FUNCTION ON LINE 68!! This is a note for future reference.
    //The logic fault is that if you clear a LoggedExercise's refernece to an exercise and the exercise still exists, then wtf?! Solution: deleting an exercise is NOT allowed, only disabling
    public bool deleteExerciseByName(string name)
    {
        bool result = true;
        using (var context = new Layer2Container())
        {
            try
            {
                var exercise = context.Exercises.Where(s => s.name == name).FirstOrDefault();

                exercise.LoggedExercise.Clear();
                exercise.ScheduledExercises.Clear();
                exercise.Routines.Clear();
                exercise.ExerciseGoals.Clear();

                var exp = context.ExerciseExps.Where(s => s.Exercise.name == name).FirstOrDefault();
                if (exp != null)
                {
                    context.ExerciseExps.DeleteObject(exp);
                }

                context.Exercises.DeleteObject(exercise);
                context.SaveChanges();
            }

            catch (Exception e)
            {
                result = false;
            }
        }

        return result;
    }
    public Routine changeRoutineName(int routineID, string name)
    {
        using (var context = new Layer2Container())
        {
            Routine rc = new Routine();
            try
            {
                Routine rtn = context.Routines.Where(x => x.id == routineID).FirstOrDefault();
                if (rtn != null && rtn.name != name.Trim())
                {
                    rtn.name = name.Trim();
                    context.Routines.ApplyCurrentValues(rtn);
                    context.SaveChanges();
                }
                rc = rtn;
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
                // write off the execeptions to my error.log file
                StreamWriter wrtr = new StreamWriter(System.Web.HttpContext.Current.ApplicationInstance.Server.MapPath("~/assets/documents/" + @"\" + "error.log"), true);

                wrtr.WriteLine(DateTime.Now.ToString() + " | Error: " + e);

                wrtr.Close();
            }

            return rc;
        }
    }
 public List<Exercise> getExercises()
 {
     using (var context = new Layer2Container())
     {
         return context.Exercises.OrderBy(s => s.name).ToList();
     }
 }
    public bool scheduleNewExercise(Int32 exerciseID, DateTime start, Int32 userID, bool notification)
    {
        bool rc = false;

        using (var context = new Layer2Container())
        {

            LimitBreaker lb = context.LimitBreakers.Where(x => x.id == userID).FirstOrDefault();
            if (lb != null)
            {
                List<scheduledItem> scheduledItemsForThatDay = new List<scheduledItem>();
                ScheduledExercise newScheduledExercise = new ScheduledExercise();

                //This part is for validating if the exercise can be scheduled for a certain time
                /* scheduledItemsForThatDay = getScheduledItemsByDay(userID, start);
                foreach (var item in scheduledItemsForThatDay)
                {
                    if (item != null && start.AddHours(-1) <= item.startTime && start.AddHours(1) >= item.startTime)
                    {
                        return false;
                    }
                }
                */
                Exercise exercise = context.Exercises.Where(e => e.id == exerciseID).FirstOrDefault();
                newScheduledExercise.Exercise = exercise;
                newScheduledExercise.startTime = start;
                newScheduledExercise.LimitBreakers = lb;
                newScheduledExercise.needEmailNotification = notification;
                context.ScheduledExercises.AddObject(newScheduledExercise);
                context.SaveChanges();
                rc = true;
            }
            return rc;
        }
    }
 public List<Exercise> getAllExercises()
 {
     using (var context = new Layer2Container())
     {
         return context.Exercises.OrderBy(o => o.id).ToList();
     }
 }
    public bool createNewExercise(string exerciseName, string muscleGroups, string equipment, string videoLink, bool rep, bool weight, bool distance, bool time, bool enabled)
    {
        bool rc = false;

        using (var context = new Layer2Container())
        {
            Exercise newExercise = new Exercise();
            try
            {
                if ((context.Exercises.FirstOrDefault(exercise => exercise.name == exerciseName).name == exerciseName))
                    rc = false;
            }
            catch (NullReferenceException e)
            {
                newExercise.name = exerciseName;
                newExercise.muscleGroups = muscleGroups;
                newExercise.equipment = equipment;
                newExercise.videoLink = videoLink;
                newExercise.rep = rep;
                newExercise.weight = weight;
                newExercise.distance = distance;
                newExercise.time = time;
                newExercise.enabled = enabled;

                context.Exercises.AddObject(newExercise);
                context.SaveChanges();
                rc = true;
            }
            return rc;
        }
    }
 public ExerciseExp getExerciseExpByExerciseName(string name)
 {
     using (var context = new Layer2Container())
     {
         return context.ExerciseExps.Where(s => s.Exercise.name == name).FirstOrDefault();
     }
 }
 public Exercise getExerciseById(int ID)
 {
     using (var context = new Layer2Container())
     {
         return context.Exercises.Where(e => e.id == ID).FirstOrDefault();
     }
 }
Esempio n. 11
0
    public bool addNewExerciseGoal(int weight, double distance, int time, int reps, string userName, string exerciseName)
    {
        bool rc = false;

        using (var context = new Layer2Container())
        {
            try
            {
                ExerciseGoal newExerciseGoal = new ExerciseGoal();
                Exercise exercise = context.Exercises.Where(s => s.name == exerciseName).FirstOrDefault();
                LimitBreaker user = context.LimitBreakers.Where(s => s.username == userName).FirstOrDefault();

                newExerciseGoal.LimitBreaker = user;
                newExerciseGoal.Exercise = exercise;
                newExerciseGoal.weight = weight;
                newExerciseGoal.distance = distance;
                newExerciseGoal.time = time;
                newExerciseGoal.reps = reps;

                context.ExerciseGoals.AddObject(newExerciseGoal);
                context.SaveChanges();

                rc = true;
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }

        return rc;
    }
 public LevelFormula getLevelFormulaValues()
 {
     using (var context = new Layer2Container())
     {
         return context.LevelFormulas.FirstOrDefault();
     }
 }
    public bool modifyExerciseExpByName(string exerciseName, double baseExp, double weightMod, double repMod, double distanceMod, double timeMod)
    {
        bool rc = false;

        using (var context = new Layer2Container())
        {
            try
            {
                ExerciseExp exerciseExp = context.ExerciseExps.Where(s => s.Exercise.name == exerciseName).FirstOrDefault();

                exerciseExp.baseExperience = baseExp;
                exerciseExp.weightModifier = weightMod;
                exerciseExp.repModifier = repMod;
                exerciseExp.distanceModifier = distanceMod;
                exerciseExp.timeModifier = timeMod;

                context.SaveChanges();
                rc = true;
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }

        return rc;
    }
 //temp user for testing
 public List<LimitBreaker> getUsers()
 {
     using (var context = new Layer2Container())
     {
         return context.LimitBreakers.OrderBy(o => o.id).ToList();
     }
 }
 public ExperienceAtrophy getExperienceAtrophy()
 {
     using (var context = new Layer2Container())
     {
         return context.ExperienceAtrophies.FirstOrDefault();
     }
 }
    public bool deleteExerciseById(int id)
    {
        bool result = true;
        using (var context = new Layer2Container())
        {
            try
            {
                var exercise = context.Exercises.Where(s => s.id == id).FirstOrDefault();

                //var exp = context.ExerciseExps.Where(s => s.Exercise.id == id).FirstOrDefault(); // Make it so it only works when there is a related ExerciseExp
                //context.ExerciseExps.DeleteObject(exp);

                exercise.LoggedExercise.Clear();
                exercise.ScheduledExercises.Clear();
                //ExerciseGoal doesn't have a navigation property

                context.Exercises.DeleteObject(exercise);
                context.SaveChanges();
            }

            catch (Exception e)
            {
                result = false;
            }
        }

        return result;
    }
    public bool createNewExerciseExp(string exerciseName, double baseExp, double weightMod, double repMod, double distanceMod, double timeMod)
    {
        bool rc = false;

        using (var context = new Layer2Container())
        {
            try
            {
                ExerciseExp newExerciseExp = new ExerciseExp();
                Exercise exercise = context.Exercises.Where(s => s.name == exerciseName).FirstOrDefault();

                newExerciseExp.Exercise = exercise;
                newExerciseExp.baseExperience = baseExp;
                newExerciseExp.weightModifier = weightMod;
                newExerciseExp.repModifier = repMod;
                newExerciseExp.distanceModifier = distanceMod;
                newExerciseExp.timeModifier = timeMod;

                context.ExerciseExps.AddObject(newExerciseExp);
                context.SaveChanges();
                rc = true;
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
            }
        }

        return rc;
    }
 public Exercise getExercise(string exerciseName)
 {
     using (var context = new Layer2Container())
     {
         return context.Exercises.FirstOrDefault(exercise => exercise.name == exerciseName);
     }
 }
Esempio n. 19
0
 public ExerciseGoal getExerciseGoalByExerciseNameAndUserName(string name, string userName)
 {
     using (var context = new Layer2Container())
     {
         return context.ExerciseGoals.Where(s => s.Exercise.name == name && s.LimitBreaker.username == userName).FirstOrDefault();
     }
 }
 public Int32 getExerciseID(String name)
 {
     using (var context = new Layer2Container())
     {
         return context.Exercises.Where(x => x.name == name).Select(x => x.id).FirstOrDefault();
     }
 }
 public SetAttributes createSet(Int32 rep, Int32 time, Int32 weight, Double distance, Int64 logID)
 {
     using (var context = new Layer2Container())
     {
         LoggedExercise existingLog = context.LoggedExercises.Where(log => log.id == logID).FirstOrDefault();
         if (existingLog != null)
         {
             SetAttributes set;
             set = new SetAttributes();
             set.reps = rep;
             set.time = time;
             set.weight = weight;
             set.distance = distance;
             set.timeLogged = DateTime.Now;
             set.LoggedExercise = existingLog;
             context.SetAttributes.AddObject(set);
             context.SaveChanges();
             return set;
         }
         else
         {
             return null;
         }
     }
 }
    // neil - create logged exercise with a routine
    public LoggedExercise createLoggedExercise(Int32 userID, Int32 exerciseID, Int32 routineID)
    {
        using (var context = new Layer2Container())
        {
            Exercise exercise = context.Exercises.Where(e => e.id == exerciseID).FirstOrDefault();
            LimitBreaker limitBreaker = context.LimitBreakers.Where(l => l.id == userID).FirstOrDefault();
            Routine routine = context.Routines.Where(r => r.id == routineID).FirstOrDefault();

            if (exercise != null && limitBreaker != null && routine != null)
            {
                LoggedExercise log;
                log = new LoggedExercise();
                log.timeLogged = DateTime.Now;
                log.Exercise = exercise;
                log.LimitBreaker = limitBreaker;
                log.Routine = routine;
                context.LoggedExercises.AddObject(log);
                context.SaveChanges();
                return log;
            }
            else
            {
                return null;
            }
        }
    }
    // Return a list of routines
    public ICollection<Routine> viewRoutines()
    {
        using (var context = new Layer2Container())
        {
            ICollection<Routine> rc = context.Routines.ToList();

            return rc;
        }
    }
    // Return a single routine object based on routine ID parameter
    public Routine getRoutine(int routineID)
    {
        using (var context = new Layer2Container())
        {
            Routine rc = context.Routines.Where(x => x.id == routineID).FirstOrDefault();

            return rc;
        }
    }
    public LimitBreaker getUser(int userID)
    {
        using (var context = new Layer2Container())
        {
            context.ContextOptions.LazyLoadingEnabled = false;

            return context.LimitBreakers.FirstOrDefault(x => x.id == userID);

        }
    }
    //if top3 is true it only returns the top 3 users
    public List<LeaderBoardItem> getLeaderBoardValues(int orderBy, bool top3)
    {
        using (var context = new Layer2Container())
        {
            List<LimitBreaker> lbSet;
            List<LeaderBoardItem> leaderBoardItemSet = new List<LeaderBoardItem>();

            switch (orderBy)
            {
                //order by level then experience
                case 1:
                    lbSet = context.LimitBreakers.OrderByDescending(l => l.Statistics.level).ThenByDescending(l => l.Statistics.experience).ThenBy(l => l.username).ToList();
                    break;
                //order by number of achieved goals
                case 2:
                    lbSet = context.LimitBreakers.OrderByDescending(l => l.ExerciseGoals.Where(g => g.achieved == true).Count()).ThenBy(l => l.username).ToList();
                    break;
                //order by number of logged exercises
                case 3:
                    lbSet = context.LimitBreakers.OrderByDescending(l => l.LoggedExercises.Count()).ThenBy(l => l.username).ToList();
                    break;
                default:
                    lbSet = context.LimitBreakers.OrderByDescending(l => l.Statistics.level).ThenByDescending(l => l.Statistics.experience).ThenBy(l => l.username).ToList();
                    break;
            }

            int i = 1;

            if (!top3)
            {
                foreach (LimitBreaker lb in lbSet)
                {
                    context.LoadProperty(lb, "ExerciseGoals");
                    context.LoadProperty(lb, "Statistics");
                    context.LoadProperty(lb, "LoggedExercises");
                    leaderBoardItemSet.Add(new LeaderBoardItem(i, lb.username, lb.Statistics.level, Convert.ToInt32(lb.Statistics.experience), lb.ExerciseGoals.Where(g => g.achieved == true).Count(), lb.LoggedExercises.Count()));
                    i++;
                }
            }

            else
            {
                foreach (LimitBreaker lb in lbSet)
                {
                    context.LoadProperty(lb, "ExerciseGoals");
                    context.LoadProperty(lb, "Statistics");
                    context.LoadProperty(lb, "LoggedExercises");
                    leaderBoardItemSet.Add(new LeaderBoardItem(i, lb.username, lb.Statistics.level, Convert.ToInt32(lb.Statistics.experience), lb.ExerciseGoals.Where(g => g.achieved == true).Count(), lb.LoggedExercises.Count()));
                    i++;
                }
            }

            return leaderBoardItemSet;
        }
    }
Esempio n. 27
0
    public bool achieveGoal(ExerciseGoal eg, int reps, int time, int weight, double distance)
    {
        bool achieved = false;

        if (reps >= eg.reps && time >= eg.time && weight >= eg.weight && distance >= eg.distance)
        {
            using (var context = new Layer2Container())
            {
                ExerciseGoal saveGoal = context.ExerciseGoals.Where(s => s.id == eg.id).FirstOrDefault();
                saveGoal.achieved = true;
                context.SaveChanges();
                achieved = true;
            }
        }

        return achieved;
    }
    public bool disableExerciseByName(string name)
    {
        bool result = true;

        using (var context = new Layer2Container())
        {
            try
            {
                Exercise exercise = context.Exercises.Where(s => s.name == name).FirstOrDefault();
                exercise.enabled = false;
                context.SaveChanges();
            }

            catch (Exception e)
            {
                result = false;
            }

            return result;
        }
    }
    public bool enableExerciseById(int id)
    {
        bool result = true;

        using (var context = new Layer2Container())
        {
            try
            {
                Exercise exercise = context.Exercises.Where(s => s.id == id).FirstOrDefault();
                exercise.enabled = true;
                context.SaveChanges();
            }

            catch (Exception e)
            {
                result = false;
            }

            return result;
        }
    }
Esempio n. 30
0
    public bool deleteExerciseGoalByExerciseNameAndUserName(string userName, string exerciseName)
    {
        bool rc = false;

        try
        {
            using (var context = new Layer2Container())
            {
                ExerciseGoal eg = context.ExerciseGoals.Where(s => s.Exercise.name == exerciseName && s.LimitBreaker.username == userName).FirstOrDefault();

                context.ExerciseGoals.DeleteObject(eg);
                context.SaveChanges();
                rc = true;
            }
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
        }

        return rc;
    }