Ejemplo n.º 1
0
        /*
         * [HttpGet]
         * [Route("daily-intakes")]
         * public IEnumerable<DailyIntake> DailyIntakes(Gender gender, DateTime dateOfBirth)
         * {
         *  var age = DateTime.Now - dateOfBirth;
         *  return nutritionRepository.GetDailyIntakes(gender, age);
         * }
         */
        private void CreateMeasures(IEnumerable <MeasurementRequest.Measurement> measurements)
        {
            if (!measurements.Any(m => m.MeasureId == null))
            {
                return;
            }
            var measures = new List <Measure>();

            measures.AddRange(measurementRepository.GetMeasures(CurrentUserId));
            foreach (var measurement in measurements.Where(m => m.MeasureId == null && !string.IsNullOrWhiteSpace(m.MeasureName)))
            {
                var measure = measures.FirstOrDefault(e => e.Name.Equals(measurement.MeasureName, StringComparison.CurrentCultureIgnoreCase));
                if (measure != null)
                {
                    measurement.MeasureId = measure.Id;
                }
                else
                {
                    var newMeasure = new Measure
                    {
                        UserId = CurrentUserId,
                        Name   = char.ToUpper(measurement.MeasureName[0]) + measurement.MeasureName.Substring(1).ToLower(),
                        Unit   = measurement.Unit
                    };
                    measurementRepository.CreateMeasure(newMeasure);
                    measures.Add(newMeasure);
                    measurement.MeasureId = newMeasure.Id;
                }
            }
        }