public RecommendedDailyIntake GetRecommendedDailyIntake(GetRecommendedDailyIntake model, IValidator <GetRecommendedDailyIntake> validator) { ValidateAndThrow(model, validator); IEnumerable <DailyIntakeAgeGroup> intakeByGender = model.Gender == "Male" ? _dailyIntakeRef.Male : _dailyIntakeRef.Female; short age = model.GetAge(); RecommendedIntake intake = intakeByGender.FirstOrDefault(x => age >= x.AgeFrom && age <= x.AgeTo).RecommendedIntake; // Find height float height = 0; if (model.HeightFeet.HasValue && !model.HeightCm.HasValue) { short heightInchesValue = model.HeightInches ?? 0; height = _conversion.FeetAndInchesToCentimeters(model.HeightFeet.Value, heightInchesValue); } else { height = (float)Math.Floor((double)model.HeightCm.Value); } // Find weight float weight = 0; if (model.WeightLbs.HasValue && !model.WeightKg.HasValue) { weight = _conversion.PoundsToKilos(model.WeightLbs.Value); } else { weight = (float)Math.Floor((double)model.WeightKg.Value); } var recommendedDailyIntake = new RecommendedDailyIntake { Calories = _dailyIntakeHelper.DeriveDailyCaloriesIntake(model.GetAge(), model.Gender, height, weight, model.ActivityLevel, model.Goal), //Fat = intake.Fat, SaturatedFat = intake.SaturatedFatMax, Carbohydrate = intake.Carbohydrate, AddedSugars = intake.AddedSugarsMax, Fiber = intake.Fiber, Protein = intake.Protein, Sodium = intake.Sodium, Cholesterol = intake.CholesterolMax, VitaminA = intake.VitaminA, VitaminC = intake.VitaminC, VitaminD = intake.VitaminD, Calcium = intake.Calcium, Iron = intake.Iron, Potassium = intake.Potassium, Magnesium = intake.Magnesium }; return(recommendedDailyIntake); }
public IActionResult GetDailyIntake([FromBody] GetRecommendedDailyIntake dto) { if (dto == null) { return(BadRequest()); } int userId; try { userId = IdentityHelper.GetUserId(User); } catch (UnauthorizedAccessException) { return(Unauthorized()); } RecommendedDailyIntake recommended = _dietaryProfileService.GetRecommendedDailyIntake(dto, _getRecommendedDailyIntakeValidator); return(Ok(recommended)); }