Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "BodyPartID,Title,Description,Location,Image")] BodyPart bodyPart)
        {
            if (ModelState.IsValid)
            {
                db.BodyParts.Add(bodyPart);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bodyPart));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "ExerciseID,Title,BodyPart,Description,VideoUrl,Rating,Type")] string[] selectedBodyParts, [Bind(Exclude = "Image")] Exercise exercise, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (selectedBodyParts != null)
                    {
                        exercise.BodyParts = new List <BodyPart>();
                        foreach (var bodyPart in selectedBodyParts)
                        {
                            var bodyPartToAdd = db.BodyParts.Find(int.Parse(bodyPart));
                            exercise.BodyParts.Add(bodyPartToAdd);
                        }
                    }


                    if (ModelState.IsValid)
                    {
                        byte[] imageData = null;
                        if (Request.Files.Count > 0)
                        {
                            HttpPostedFileBase poImgFile = Request.Files["Image"];

                            using (var binary = new BinaryReader(poImgFile.InputStream))
                            {
                                imageData = binary.ReadBytes(poImgFile.ContentLength);
                            }
                        }
                        //string fileName = Path.GetFileNameWithoutExtension(exercise.ImageURL.FileName);
                        //string extension = Path.GetExtension(exercise.ImageURL.FileName);
                        //fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        //exercise.ImagePath = "~/Images/" + fileName;
                        //fileName = Path.Combine(Server.MapPath("~/Images/"), fileName);
                        //exercise.ImageURL.SaveAs(fileName);

                        db.Exercises.Add(exercise);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }

                PopulateAssignedBodyPartData(exercise);
                return(View(exercise));
            }

            return(View(exercise));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> EditPost(string id, string[] selectedExercisePlans, HttpPostedFileBase file)
        {
            var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var userToUpdate = db.Users
                               .Include(i => i.ExercisePlans)
                               .Where(i => i.Id == id)
                               .Single();

            byte[] imageData2 = null;
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase poImgFile = Request.Files["Image"];

                using (var binary = new BinaryReader(poImgFile.InputStream))
                {
                    imageData2 = binary.ReadBytes(poImgFile.ContentLength);
                }
            }
            else
            {
                userToUpdate.Image     = currentUser.Image;
                userToUpdate.ImagePath = currentUser.ImagePath;
            }

            if (TryUpdateModel(userToUpdate, "",
                               new string[] { "LastName", "FirstName", "Email", "TargetAim" }))
            {
                try
                {
                    UpdateUserExercisePlans(selectedExercisePlans, userToUpdate);
                    userToUpdate.Image = imageData2;
                    db.SaveChanges();

                    return(RedirectToAction("UserProfile", "User"));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            PopulateAssignedExercisePlanData(userToUpdate);
            return(View(userToUpdate));
        }
Exemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Achievement achievement = db.Achievements.Find(id);

            db.Achievements.Remove(achievement);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Done(int id, Achievement achievement)
        {
            var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());

            // Retrieve the plan from the database
            var chosenExercise = db.ChosenExercises
                                 .Single(exercise => exercise.ChosenExerciseID == id);

            chosenExercise.IsDone = true;
            chosenExercise.Complete++;
            currentUser.ExercisesCompleted++;
            db.SaveChanges();

            var myExercisePlan2 = db.MyExercisePlans
                                  .Single(exercisePlan => exercisePlan.MyExercisePlanID == chosenExercise.ExercisePlanID);
            double?exerciseCount = 0;

            foreach (var exercise in db.ChosenExercises)
            {
                if (exercise.ExercisePlanID == chosenExercise.ExercisePlanID)
                {
                    exerciseCount++;

                    ViewBag.exerciseCount2 = exerciseCount;
                }
            }
            double?exerciseIsDone = 0;

            foreach (var exercise in db.ChosenExercises)
            {
                if (exercise.ExercisePlanID == chosenExercise.ExercisePlanID && exercise.IsDone == true)
                {
                    exerciseIsDone++;
                }
            }

            if (exerciseCount == null)
            {
                exerciseCount = 0;
            }

            if (exerciseCount >= 1 && exerciseIsDone == exerciseCount)
            {
                ViewBag.exerciseMessage = "Wow!! You have completed all of your Exercise! ";
                myExercisePlan2.IsDone  = true;
                myExercisePlan2.IsComplete++;
                currentUser.PlansCompleted++;
                db.SaveChanges();
            }

            else if (exerciseCount >= 1 && exerciseIsDone != exerciseCount)
            {
                myExercisePlan2.IsDone = false;
                db.SaveChanges();
            }


            if (myExercisePlan2.IsComplete == 5)
            {
                achievement = new Achievement {
                    UserId = currentUser.Id, ExercisePlanName = myExercisePlan2.Title, Date = DateTime.Now, Description = "Congratulations, you have completed your Exercise Plan 5 times! Keep up the good work!"
                };
                db.Achievements.Add(achievement);
                db.SaveChanges();
            }
            if (myExercisePlan2.IsComplete == 10)
            {
                achievement = new Achievement {
                    UserId = currentUser.Id, ExercisePlanName = myExercisePlan2.Title, Date = DateTime.Now, Description = "Congratulations, you have completed your Exercise Plan 10 times! You are really putting in some effort. Here have this online voucher on us! Use the code provided on WWW.SportingClothingShop.COM to get 15% off any clothing! Voucher Code : X2342J21"
                };
                db.Achievements.Add(achievement);
                db.SaveChanges();
            }
            if (myExercisePlan2.IsComplete == 20)
            {
                achievement = new Achievement {
                    UserId = currentUser.Id, ExercisePlanName = myExercisePlan2.Title, Date = DateTime.Now, Description = "Congratulations, you have completed your Exercise Plan 20! You must be working your ass off. Here have this online voucher code! Use the code provided on WWW.SportingClothesShop.COM to get 25% off any clothing or footwear! Voucher Code : P1324gre908. "
                };
                db.Achievements.Add(achievement);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", new { id = chosenExercise.ExercisePlanID }));
        }
Exemplo n.º 6
0
        public async System.Threading.Tasks.Task <ActionResult> Create([Bind(Include = "")] BMI bMI)
        {
            var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());

            bMI.AddedOn = DateTime.Now;
            bMI.UserId  = currentUser.Id;
            if (bMI.Height == null)
            {
                bMI.Height = currentUser.Height;
            }
            if (bMI.Weight == null)
            {
                bMI.Weight = currentUser.Weight;
            }
            var weight = db.Users
                         .Single(u => u.Id == bMI.UserId);

            if (weight.Weight == null)
            {
                bMI.Weight = 1;
            }

            bMI.Result = (bMI.Weight.Value) / (bMI.Height.Value * bMI.Height.Value);

            if (currentUser.TargetAim == TargetAim.GainMuscle)
            {
                if (bMI.Result <= 18.5)
                {
                    bMI.Verdict = "you are under average and should attempt to gain more weight, eat loads of carbs and calories. Don't forget Protein!";
                }
                else if (bMI.Result <= 24.9)
                {
                    bMI.Verdict = "you are average weight and seem healthy, include more protein and calories in your diet to continue to gain weight";
                }
                else if (bMI.Result <= 29.9)
                {
                    bMI.Verdict = "You are going above the average weight now. I hope that's the extra muscle you have been piling on and not loosey-goosey flab handles!";
                }
                else if (bMI.Result >= 30)
                {
                    bMI.Verdict = "You're well above average now! If i come across you on the street I hope you are looking like a wall with arms as strong as rock instead of a couch potato with a plump belly!";
                }
            }

            else
            {
                if (bMI.Result <= 18.5)
                {
                    bMI.Verdict = "you are under average and should attempt to gain more wieght";
                }
                else if (bMI.Result <= 24.9)
                {
                    bMI.Verdict = "you are average weight and seem healthy";
                }
                else if (bMI.Result <= 29.9)
                {
                    bMI.Verdict = "You are going above average now, either you have gained extra muscle which in that case good for you, or, you have eaten a few too many pies or sneaky McDonalds. Get back to worl!";
                }
                else if (bMI.Result >= 30)
                {
                    bMI.Verdict = "Seriously time to get back to work and pump some steam. You need to lose weight unless it is pure steel you are rocking!";
                }
            }

            if (ModelState.IsValid)
            {
                db.BMI.Add(bMI);
                db.SaveChanges();
                currentUser.Height = bMI.Height;
                currentUser.Weight = bMI.Weight;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(bMI));
        }