public ActionResult CalcCalories(WeightData weightData, Distance distanceData) { if (!ModelState.IsValid) return new JsonResult { Data = new { Result = false } }; return new JsonResult { Data = new { Result = true, Calories = caloriesCalc.Calculate(distanceData, weightData) } }; }
public void FromStoneAndPounds(WeightData weightData) { if (!weightData.HasSt && !weightData.HasStLbs) return; weightData.Lbs = (weightData.HasSt ? weightData.St.Value * 14 : 0) + (weightData.HasStLbs ? weightData.StLbs.Value : 0); weightData.Kg = weightData.Lbs.Value * PoundsToKg; }
public void FromPounds(WeightData weightData) { if (!weightData.HasLbs) return; weightData.Kg = weightData.Lbs.Value * PoundsToKg; weightData.St = Math.Floor(weightData.Lbs.Value / 14); weightData.StLbs = weightData.Lbs.Value - (weightData.St.Value * 14); }
public void FromKilograms(WeightData weightData) { if (!weightData.HasKg) return; weightData.Lbs = weightData.Kg.Value * KgToPounds; weightData.St = Math.Floor(weightData.Lbs.Value / 14); weightData.StLbs = weightData.Lbs.Value - (weightData.St.Value * 14); }
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(); }
public int Calculate(Distance distance, WeightData weightData) { if (distance.BaseDistance == 0) return 0; if (!(weightData.HasKg || weightData.HasLbs || weightData.HasSt || weightData.HasStLbs)) return 0; if (string.IsNullOrWhiteSpace(weightData.Units)) return 0; // ensure the weight data has all the up-to-date values weightCalculator.Calculate(weightData); if (!weightData.HasKg || weightData.Kg.Value <= 0) return 0; distance = distance.ConvertTo(DistanceUnits.Kilometers); return (int)Math.Floor(distance.BaseDistance * weightData.Kg.Value * 1.036); }
public WeightData Calculate(WeightData weightData) { switch (weightData.Units) { case "kg": FromKilograms(weightData); break; case "lbs": FromPounds(weightData); break; case "st": FromStoneAndPounds(weightData); break; } return weightData; }
public ActionResult CalcWeight(WeightData weightCalculation) { if (!ModelState.IsValid) return new JsonResult { Data = new { Result = false, Calc = weightCalculation } }; weightCalc.Calculate(weightCalculation); return new JsonResult { Data = new { Result = true, Calc = weightCalculation } }; }