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));
        }
        public SRMDto CalculateSRMDto(RecipeDto recipe)
        {
            var srm = new SRMDto();

            foreach (var item in recipe.Steps.OfType <MashStepDto>())
            {
                var mashStepDto = item;
                var volume      = recipe.Volume;
                if (mashStepDto.Volume > 0)
                {
                    volume = mashStepDto.Volume;
                }
                foreach (var fermentable in mashStepDto.Ingredients.OfType <FermentableStepDto>())
                {
                    var temp = fermentable;
                    srm.Standard += Math.Round(Formulas.MaltColourUnits(temp.Amount, temp.Lovibond, volume), 0);
                    srm.Morey    += Math.Round(Formulas.Morey(temp.Amount, temp.Lovibond, volume), 0);
                    srm.Mosher   += Math.Round(Formulas.Morey(temp.Amount, temp.Lovibond, volume), 0);
                    srm.Daniels  += Math.Round(Formulas.Daniels(temp.Amount, temp.Lovibond, volume), 0);
                }
            }

            return(srm);
        }
        public SRM CalculateSRM(Recipe recipe)
        {
            var srm = new SRM {
                SrmId = recipe.RecipeId
            };

            foreach (var mashStep in recipe.MashSteps)
            {
                var volume = recipe.Volume;
                if (mashStep.Volume > 0)
                {
                    volume = mashStep.Volume;
                }
                foreach (var fermentable in mashStep.Fermentables)
                {
                    srm.Standard += Math.Round(Formulas.MaltColourUnits(fermentable.Amount, fermentable.Lovibond, volume), 0);
                    srm.Morey    += Math.Round(Formulas.Morey(fermentable.Amount, fermentable.Lovibond, volume), 0);
                    srm.Mosher   += Math.Round(Formulas.Morey(fermentable.Amount, fermentable.Lovibond, volume), 0);
                    srm.Daniels  += Math.Round(Formulas.Daniels(fermentable.Amount, fermentable.Lovibond, volume), 0);
                }
            }

            return(srm);
        }