Beispiel #1
0
        private double GetHeightInCm(int field)
        {
            var userProfileId = Helper_Classes.UserHelpers.GetUserProfile().Id;
            var heightInCm    = _context.UserProfiles
                                .SingleOrDefault(m => m.Id == userProfileId)
                                .HeightInCm
            ;
            var    heightUnit = Helper_Classes.UserHelpers.GetHeightUnit();
            double val        = 0;

            if (heightUnit == HeightUnits.Cm && field == 1)
            {
                val = heightInCm;
            }
            else if (heightUnit == HeightUnits.Feetandinches)
            {
                if (field == 1)
                {
                    val = Calculators.CmToFt(heightInCm);
                }
                else if (field == 2)
                {
                    val = Calculators.CmToInches(heightInCm);
                }
            }

            return(val);
        }
Beispiel #2
0
        // GET: Profile
        public ActionResult Index()
        {
            var userProfile = Helper_Classes.UserHelpers.GetUserProfile();

            if (userProfile == null)
            {
                return(RedirectToAction("Edit"));
            }



            var    userId          = userProfile.Id;
            string heightToDisplay = "";
            string heightUnit      = _context.UserProfiles.Where(m => m.Id == userId).Select(m => m.HeightUnit.Name).SingleOrDefault();
            double heightInCm      = _context.UserProfiles.Where(m => m.Id == userId).Select(m => m.HeightInCm)
                                     .SingleOrDefault();


            if (heightUnit == HeightUnits.Cm)
            {
                heightToDisplay = heightInCm.ToString() + "cm";
            }
            else if (heightUnit == HeightUnits.Feetandinches)
            {
                heightToDisplay = Calculators.CmToFt(heightInCm).ToString() + "ft" + Calculators.CmToInches(heightInCm).ToString() + "in";
            }

            ProfileViewModel viewModel = new ProfileViewModel
            {
                HeightToDisplay = heightToDisplay,
                UserProfile     = _context.UserProfiles.
                                  Include(m => m.Sex).
                                  Include(m => m.HeightUnit).
                                  Include(m => m.WeightUnit).
                                  Include(m => m.ActivityLevel).
                                  ToList().
                                  SingleOrDefault(m => m.Id == userId),
            };

            if (_context.UserPhotos.SingleOrDefault(m => m.Id == userProfile.UserPhotoId)?.Photo != null)
            {
                viewModel.Photo =
                    Convert.ToBase64String(_context.UserPhotos.SingleOrDefault(m => m.Id == userProfile.UserPhotoId)?.Photo);
            }


            return(View(viewModel));
        }