public ActionResult DeleteConfirmed(int id)
        {
            ExpectedProgramTotal expectedProgramTotal = db.ExpectedProgramTotals.Find(id);

            db.ExpectedProgramTotals.Remove(expectedProgramTotal);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ExpectedTotalId,Exercise,Reps,Weight,SavedWorkoutDateId,UserId")] ExpectedProgramTotal expectedProgramTotal)
 {
     if (ModelState.IsValid)
     {
         db.Entry(expectedProgramTotal).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "FirstName", expectedProgramTotal.UserId);
     return(View(expectedProgramTotal));
 }
        // GET: ExpectedProgramTotals/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExpectedProgramTotal expectedProgramTotal = db.ExpectedProgramTotals.Find(id);

            if (expectedProgramTotal == null)
            {
                return(HttpNotFound());
            }
            return(View(expectedProgramTotal));
        }
        // GET: ExpectedProgramTotals/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExpectedProgramTotal expectedProgramTotal = db.ExpectedProgramTotals.Find(id);

            if (expectedProgramTotal == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "FirstName", expectedProgramTotal.UserId);
            return(View(expectedProgramTotal));
        }
        public void DetermineExpectedProgramTotals(int userId)
        {
            var allLifts = db.Lifts.Where(l => l.UserId == userId).ToList();
            ExpectedProgramTotal expectedProgramTotal = new ExpectedProgramTotal();

            foreach (var item in allLifts)
            {
                if (item.Exercise == "Squat")
                {
                    var squatTotalsCount = db.ExpectedProgramTotals.Where(s => s.Exercise == "Squat" && s.UserId == userId).Count();
                    if (squatTotalsCount < 1)
                    {
                        ExpectedProgramTotal programTotals = new ExpectedProgramTotal();
                        programTotals.Exercise = "Squat";
                        programTotals.Reps     = 0;
                        programTotals.Weight   = 0;
                        programTotals.UserId   = userId;
                        db.ExpectedProgramTotals.Add(programTotals);
                        db.SaveChanges();
                        var foundProgramTotals = db.ExpectedProgramTotals.Where(f => f.UserId == userId && f.Exercise == "Squat").FirstOrDefault();
                        foundProgramTotals.Reps   += item.Reps;
                        foundProgramTotals.Weight += item.Weight * item.Reps;
                        db.SaveChanges();
                    }
                    else
                    {
                        var foundProgramTotals = db.ExpectedProgramTotals.Where(f => f.UserId == userId && f.Exercise == "Squat").FirstOrDefault();
                        foundProgramTotals.Reps   += item.Reps;
                        foundProgramTotals.Weight += item.Weight * item.Reps;
                        db.SaveChanges();
                    }
                }
                else if (item.Exercise == "Benchpress")
                {
                    var benchTotalsCount = db.ExpectedProgramTotals.Where(s => s.Exercise == "Benchpress" && s.UserId == userId).Count();
                    if (benchTotalsCount < 1)
                    {
                        ExpectedProgramTotal programTotals = new ExpectedProgramTotal();
                        programTotals.Exercise = "Benchpress";
                        programTotals.Reps     = 0;
                        programTotals.Weight   = 0;
                        programTotals.UserId   = userId;
                        db.ExpectedProgramTotals.Add(programTotals);
                        db.SaveChanges();
                        var foundProgramTotals = db.ExpectedProgramTotals.Where(f => f.UserId == userId && f.Exercise == "Benchpress").FirstOrDefault();
                        foundProgramTotals.Reps   += item.Reps;
                        foundProgramTotals.Weight += item.Weight * item.Reps;
                        db.SaveChanges();
                    }
                    else
                    {
                        var foundProgramTotals = db.ExpectedProgramTotals.Where(f => f.UserId == userId && f.Exercise == "Benchpress").FirstOrDefault();
                        foundProgramTotals.Reps   += item.Reps;
                        foundProgramTotals.Weight += item.Weight * item.Reps;
                        db.SaveChanges();
                    }
                }
                else if (item.Exercise == "Deadlift" || item.Exercise == "Deadlift^Knee" || item.Exercise == "Def Deadlift")
                {
                    var deadTotalsCount = db.ExpectedProgramTotals.Where(s => s.Exercise == "Deadlift" && s.UserId == userId).Count();
                    if (deadTotalsCount < 1)
                    {
                        ExpectedProgramTotal programTotals = new ExpectedProgramTotal();
                        programTotals.Exercise = "Deadlift";
                        programTotals.Reps     = 0;
                        programTotals.Weight   = 0;
                        programTotals.UserId   = userId;
                        db.ExpectedProgramTotals.Add(programTotals);
                        db.SaveChanges();
                        var foundProgramTotals = db.ExpectedProgramTotals.Where(f => f.UserId == userId && f.Exercise == "Deadlift").FirstOrDefault();
                        foundProgramTotals.Reps   += item.Reps;
                        foundProgramTotals.Weight += item.Weight * item.Reps;
                        db.SaveChanges();
                    }
                    else
                    {
                        var foundProgramTotals = db.ExpectedProgramTotals.Where(f => f.UserId == userId && f.Exercise == "Deadlift").FirstOrDefault();
                        foundProgramTotals.Reps   += item.Reps;
                        foundProgramTotals.Weight += item.Weight * item.Reps;
                        db.SaveChanges();
                    }
                }
            }
            db.SaveChanges();
        }