コード例 #1
0
        public async Task <FermentableDto> GetSingleAsync(int id)
        {
            var fermentableDto = await _fermentableElasticsearch.GetSingleAsync(id);

            if (fermentableDto != null)
            {
                return(fermentableDto);
            }
            var fermentable = await _fermentableRepository.GetSingleAsync(id);

            fermentableDto = AutoMapper.Mapper.Map <Fermentable, FermentableDto>(fermentable);
            return(fermentableDto);
        }
コード例 #2
0
        public double CalculateOG(Recipe recipe)
        {
            var og = 0.0;

            foreach (var fermentable in recipe.MashSteps.SelectMany(mashStep => mashStep.Fermentables))
            {
                var efficency = recipe.Efficiency;
                //if (fermentable.PPG <= 0)
                //{
                var esFermentable = _fermentableElasticsearch.GetSingleAsync(fermentable.FermentableId).Result;
                if (esFermentable != null && esFermentable.PPG > 0)
                {
                    fermentable.PPG = esFermentable.PPG;
                    if (esFermentable.Type.Contains("Extract") || esFermentable.Type.Contains("Sugar"))
                    {
                        efficency = 100;
                    }
                    //og += Formulas.MaltOG(fermentable.Amount, esFermentable.PPG, recipe.Efficiency, recipe.Volume);
                }
                else
                {
                    var efFermentable = _fermentableRepository.GetSingleAsync(fermentable.FermentableId).Result;
                    if (efFermentable != null && efFermentable.PPG != null)
                    {
                        fermentable.PPG = (int)efFermentable.PPG;
                        if (efFermentable.Type.Contains("Extract") || efFermentable.Type.Contains("Sugar"))
                        {
                            efficency = 100;
                        }
                    }
                    //og += Formulas.MaltOG(fermentable.Amount, (int)efFermentable.PPG, recipe.Efficiency, recipe.Volume);
                }

                //}
                og += Formulas.MaltOG(fermentable.Amount, (int)fermentable.PPG, efficency, recipe.Volume);
            }
            return(Math.Round(1 + og / 1000, 4));
        }