public CaloriesCalculatorModel(ControllerContext context)
        {
            Weight = ProfileModel.DefaultWeightData();
            if (!context.HasValidUserAccount())
                return;

            var userAccount = context.UserAccount();

            var userPref = ((object)userAccount).UserPrefs().Latest();
            if (userPref != null)
            {
                Weight.Units = userPref.WeightUnits;
                switch (Weight.Units)
                {
                    case "kg":
                        Weight.Kg = userPref.Weight;
                        break;
                    case "lbs":
                    case "st":
                        Weight.Lbs = userPref.Weight;
                        Weight.Units = "lbs";
                        break;
                }
                Weight.UpdateFromUnits();
                if (userPref.WeightUnits == "st")
                    Weight.Units = "st";
            }
        }
예제 #2
0
        public ProfileModel(ControllerContext context)
        {
            if (!context.HasValidUserAccount())
            {
                Name = "";
                Weight = new WeightData();
                return;
            }

            var userAccount = context.UserAccount();
            Name = userAccount.DisplayName;

            Weight = DefaultWeightData();
            var userPref = ((object)userAccount).UserPrefs().Latest();
            if (userPref != null)
            {
                Weight.Units = userPref.WeightUnits;
                switch (Weight.Units)
                {
                    case "kg":
                        Weight.Kg = userPref.Weight;
                        break;
                    case "lbs":
                    case "st":
                        Weight.Lbs = userPref.Weight;
                        Weight.Units = "lbs";
                        break;
                }
                Weight.UpdateFromUnits();
                if (userPref.WeightUnits == "st")
                    Weight.Units = "st";
            }

            DistUnits = (int)context.UserDistanceUnits();
        }
예제 #3
0
        public static IEnumerable<RoutePalViewModel.RouteModel> RoutesForCurrentUser(ControllerContext context)
        {
            dynamic currentUser = context.HasValidUserAccount() ? context.UserAccount() : null;

            IEnumerable<dynamic> routes = MassiveDB.Current.FindRoutes(currentUser);
            routes = routes.Where(r => !string.IsNullOrWhiteSpace(r.MapPoints));

            IEnumerable<dynamic> runInfos = MassiveDB.Current.FindLatestRunLogForRoutes(routes.Select(r => (long)r.Id));

            var routeModels = routes.Select(route => new RoutePalViewModel.RouteModel(context, route)).ToList();
            foreach (var route in routeModels)
            {
                var runInfo = runInfos.FirstOrDefault(r => r.RouteId == route.Id);
                if (runInfo == null) continue;
                route.LastRunBy = runInfo.DisplayName;
                route.LastRunDate = runInfo.Date;
            }

            return routeModels.OrderByDescending(r => r.LastRunDate ?? r.CreatedDate);
        }