예제 #1
0
        public ActionResult NewCheckInForm(string pageFrom)
        {
            //Used when creating a new check in

            //If no log found for that date, fetch blank log page. If existing log found, fetch existing info into page
            CheckInFormViewModel viewModel;
            var    userProfileId = Helper_Classes.UserHelpers.GetUserProfile().Id;
            string weightInputA  = "";
            string weightInputB  = "";
            var    weightUnit    = Helper_Classes.UserHelpers.GetWeightUnit();
            double weight        = 0.0;

            if (_context.UserProgressLogs.SingleOrDefault(g =>
                                                          g.UserProfileId == userProfileId && g.Date == DateTime.Today) == null)
            {
                viewModel = new CheckInFormViewModel
                {
                    UserProgressLog = new UserProgressLog()
                }
            }
            ;

            else
            {
                viewModel = new CheckInFormViewModel
                {
                    UserProgressLog = _context.UserProgressLogs.SingleOrDefault(g =>
                                                                                g.UserProfileId == userProfileId && g.Date == DateTime.Today),
                };
                weight = (double)viewModel.UserProgressLog.WeightInKg;
            }

            viewModel.BodyFat = viewModel.UserProgressLog.BodyFat;



            if (weightUnit.Equals(WeightUnits.Kg))
            {
                weightInputA = Convert.ToInt32(weight).ToString();
            }
            else if (weightUnit.Equals(WeightUnits.Lbs))
            {
                weightInputA = Convert.ToInt32(Calculators.KgsToLbs(weight)).ToString();
            }
            else if (weightUnit.Equals(WeightUnits.LbsAndStone))
            {
                weightInputA = Convert.ToInt32(Calculators.KgsToStone(weight)).ToString();
                weightInputB = Convert.ToInt32(Calculators.KgsToLbsRemainingFromStone(weight)).ToString();
            }
            viewModel.WeightInputA    = weightInputA;
            viewModel.WeightInputB    = weightInputB;
            viewModel.WeightUnit      = weightUnit;
            viewModel.RedirectionPage = pageFrom;

            viewModel.IsBodyFatCalculation =
                Helper_Classes.UserHelpers.GetCurrentGoal().CalculationBasis == CalculationBasis.BodyFat ? true : false;

            return(View(viewModel));
        }
예제 #2
0
        private static string GetWeightString(double val)
        {
            switch (Helper_Classes.UserHelpers.GetWeightUnit())
            {
            case WeightUnits.Kg:
                return(Math.Round(val, 1) + "kg");

            case WeightUnits.Lbs:
                return(Convert.ToInt32(Calculators.KgsToLbs(val)) + "lbs");

            case WeightUnits.LbsAndStone:
                return(Convert.ToInt32(Calculators.KgsToStone(val)) + "st" + Convert.ToInt32(Calculators.KgsToLbsRemainingFromStone(val)) + "lb");
            }

            return("Weight Unit Not Found");
        }
예제 #3
0
        //Used when 'editing' a check in from the tracker
        public ActionResult NewCheckInForm(int id)
        {
            //If no log found for that date, fetch blank log page. If existing log found, fetch existing info into page
            CheckInFormViewModel viewModel;
            var             userProfileId   = Helper_Classes.UserHelpers.GetUserProfile().Id;
            string          weightInputA    = "";
            string          weightInputB    = "";
            var             weightUnit      = Helper_Classes.UserHelpers.GetWeightUnit();
            UserProgressLog userProgressLog = _context.UserProgressLogs.SingleOrDefault(m => m.Id == id);
            double          weight          = userProgressLog.WeightInKg.Value;

            if (weightUnit.Equals(WeightUnits.Kg))
            {
                weightInputA = Convert.ToInt32(weight).ToString();
            }
            else if (weightUnit.Equals(WeightUnits.Lbs))
            {
                weightInputA = Convert.ToInt32(Calculators.KgsToLbs(weight)).ToString();
            }
            else if (weightUnit.Equals(WeightUnits.LbsAndStone))
            {
                weightInputA = Convert.ToInt32(Calculators.KgsToStone(weight)).ToString();
                weightInputB = Convert.ToInt32(Calculators.KgsToLbsRemainingFromStone(weight)).ToString();
            }

            viewModel = new CheckInFormViewModel
            {
                UserProgressLog = userProgressLog,
                WeightInputA    = weightInputA,
                WeightInputB    = weightInputB,
                WeightUnit      = weightUnit,
                PageTitlePrefix = "Edit",
                RedirectionPage = "Tracker"
            };

            viewModel.BodyFat = viewModel.UserProgressLog.BodyFat;
            viewModel.IsBodyFatCalculation =
                Helper_Classes.UserHelpers.GetCurrentGoal().CalculationBasis == CalculationBasis.BodyFat ? true : false;

            return(View("NewCheckInForm", viewModel));
        }
예제 #4
0
        public ActionResult NewGoalForm()
        {
            //If no goal found, fetch blank goal page. If existing goal found, fetch existing info into page
            EditGoalViewModel viewModel;
            var    userProfileId      = Helper_Classes.UserHelpers.GetUserProfile().Id;
            string startWeightInputA  = "";
            string startWeightInputB  = "";
            string targetWeightInputA = "";
            string targetWeightInputB = "";

            string weightUnit = Helper_Classes.UserHelpers.GetWeightUnit();
            var    dbGoal     = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId);



            //No existing goal
            if (_context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId) == null)
            {
                viewModel = new EditGoalViewModel()
                {
                    Goal = new Goal
                    {
                        UserProfileId = userProfileId,
                        StartDate     = DateTime.Today,
                        EndDate       = DateTime.Today.AddDays(30)
                    },
                    StartWeightInputA  = startWeightInputA,
                    StartWeightInputB  = startWeightInputB,
                    TargetWeightInputA = targetWeightInputA,
                    TargetWeightInputB = targetWeightInputB,
                    WeightUnit         = weightUnit,
                    Title            = "New Goal",
                    CalculationBasis = new SelectList(new List <string> {
                        "Weight", "Body Fat"
                    }, "Weight")
                }
            }
            ;
            //Existing goal
            else
            {
                double startWeight  = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId).StartWeightInKg;
                double targetWeight = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId).TargetWeightInKg;
                if (weightUnit.Equals(WeightUnits.Kg))
                {
                    startWeightInputA  = Convert.ToInt32(startWeight).ToString();
                    targetWeightInputA = Convert.ToInt32(targetWeight).ToString();
                }
                if (weightUnit.Equals(WeightUnits.Lbs))
                {
                    startWeightInputA  = Convert.ToInt32(Calculators.KgsToLbs(startWeight)).ToString();
                    targetWeightInputA = Convert.ToInt32(Calculators.KgsToLbs(targetWeight)).ToString();
                }
                else if (weightUnit == WeightUnits.LbsAndStone)
                {
                    startWeightInputA  = Convert.ToInt32(Calculators.KgsToStone(startWeight)).ToString();
                    startWeightInputB  = Convert.ToInt32(Calculators.KgsToLbsRemainingFromStone(startWeight)).ToString();
                    targetWeightInputA = Convert.ToInt32(Calculators.KgsToStone(targetWeight)).ToString();
                    targetWeightInputB = Convert.ToInt32(Calculators.KgsToLbsRemainingFromStone(targetWeight)).ToString();
                }

                viewModel = new EditGoalViewModel
                {
                    Goal = dbGoal,
                    StartWeightInputA  = startWeightInputA,
                    StartWeightInputB  = startWeightInputB,
                    TargetWeightInputA = targetWeightInputA,
                    TargetWeightInputB = targetWeightInputB,
                    WeightUnit         = weightUnit,
                    Title            = "Edit Goal",
                    CalculationBasis = new SelectList(new List <string> {
                        "Weight", "Body Fat"
                    }, dbGoal.CalculationBasis)
                };
            }

            viewModel.StartBodyFat  = viewModel.Goal.StartBodyFat;
            viewModel.TargetBodyFat = viewModel.Goal.TargetBodyFat;
            viewModel.TrackBodyFat  = viewModel.Goal.TrackBodyFat;

            return(View(viewModel));
        }