// 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;
            }
        }
    }
        public ActionResult DeleteConfirmed(int id)
        {
            LoggedExercise loggedexercise = db.LoggedExercises.Find(id);

            db.LoggedExercises.Remove(loggedexercise);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int id = 0)
        {
            LoggedExercise loggedexercise = db.LoggedExercises.Find(id);

            if (loggedexercise == null)
            {
                return(HttpNotFound());
            }
            return(View(loggedexercise));
        }
Exemplo n.º 4
0
    public LoggedExercise createLoggedExerciseRoutine(int userID, int exerciseID, int routineID, int sets, DateTime logTime, string note)
    {
        using (var context = new Layer2Container())
        {
            LoggedExercise rc = new LoggedExercise();
            try
            {
                LimitBreaker lb = context.LimitBreakers.Where(x => x.id == userID).FirstOrDefault();
                Exercise ex = context.Exercises.Where(x => x.id == exerciseID).FirstOrDefault();
                Routine rtn = context.Routines.Where(x => x.id == routineID).FirstOrDefault();

                if (lb != null && ex != null)
                {

                    rc.LimitBreaker = lb;
                    rc.Exercise = ex;
                    rc.Routine = rtn;
                    rc.timeLogged = logTime;

                    context.LoggedExercises.AddObject(rc);
                    context.SaveChanges();
                }
            }
            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;
        }
    }