Esempio n. 1
0
        /// <summary>
        /// Sets the fermentables on the recipe
        /// </summary>
        void SetFermentables(Recipe recipe, XElement entryPoint)
        {
            var allFermentables = this.BrewDataService.GetUsableIngredients <Fermentable>(this.UserId);

            recipe.Fermentables = new List <RecipeFermentable>();
            if (entryPoint.Element("FERMENTABLES") != null)
            {
                foreach (var fermentableElement in entryPoint.Element("FERMENTABLES").Elements("FERMENTABLE"))
                {
                    var fermentable = new RecipeFermentable();

                    var matchingFermentable =
                        allFermentables.FirstOrDefault(
                            x => x.Name.Trim().ToLower() == fermentableElement.Element("NAME").Value.Trim().ToLower());
                    if (matchingFermentable != null)
                    {
                        fermentable.IngredientId = matchingFermentable.IngredientId;
                        fermentable.Fermentable  = matchingFermentable;
                    }
                    else
                    {
                        fermentable.IngredientId     = 0;
                        fermentable.Fermentable      = new Fermentable();
                        fermentable.Fermentable.Name = fermentableElement.Element("NAME").Value;
                    }

                    var kilograms = Convert.ToDouble(fermentableElement.Element("AMOUNT").Value);
                    var pounds    = this.RecipeUnitConverter.ConvertKilogramsToPounds(kilograms);
                    fermentable.Amount = Math.Round(pounds * 10000) / 10000;

                    fermentable.Ppg      = Convert.ToInt16(Math.Round(Convert.ToDouble(fermentableElement.Element("YIELD").Value) * 46.214 * 0.01, 2));
                    fermentable.Lovibond = Convert.ToInt32(Math.Round(Convert.ToDouble(fermentableElement.Element("COLOR").Value), 0));

                    var fermentableUsageType = fermentableElement.Element("TYPE").Value.ToLower();
                    fermentable.FermentableUsageTypeId = (int)FermentableUsageType.Mash;

                    if (fermentableUsageType == "grain")
                    {
                        fermentable.FermentableUsageTypeId = (int)FermentableUsageType.Mash;
                    }
                    else if (fermentableUsageType.IndexOf("extract") > -1)
                    {
                        fermentable.FermentableUsageTypeId = (int)FermentableUsageType.Extract;
                    }
                    else if (fermentableUsageType == "sugar")
                    {
                        fermentable.FermentableUsageTypeId = (int)FermentableUsageType.Late;
                    }

                    recipe.Fermentables.Add(fermentable);
                }
            }
        }
		/// <summary>
		/// Sets the fermentables on the recipe
		/// </summary>
		void SetFermentables(Recipe recipe, XElement entryPoint)
		{
			var allFermentables = this.BrewDataService.GetUsableIngredients<Fermentable>(this.UserId);
			recipe.Fermentables = new List<RecipeFermentable>();
			if (entryPoint.Element("FERMENTABLES") != null)
			{
				foreach (var fermentableElement in entryPoint.Element("FERMENTABLES").Elements("FERMENTABLE"))
				{
					var fermentable = new RecipeFermentable();

					var matchingFermentable =
						allFermentables.FirstOrDefault(
							x => x.Name.Trim().ToLower() == fermentableElement.Element("NAME").Value.Trim().ToLower());
					if (matchingFermentable != null)
					{
						fermentable.IngredientId = matchingFermentable.IngredientId;
						fermentable.Fermentable = matchingFermentable;
					}
					else
					{
						fermentable.IngredientId = 0;
						fermentable.Fermentable = new Fermentable();
						fermentable.Fermentable.Name = fermentableElement.Element("NAME").Value;
					}

					var kilograms = Convert.ToDouble(fermentableElement.Element("AMOUNT").Value);
					var pounds = this.RecipeUnitConverter.ConvertKilogramsToPounds(kilograms);
					fermentable.Amount = Math.Round(pounds * 10000) / 10000;

					fermentable.Ppg = Convert.ToInt16(Math.Round(Convert.ToDouble(fermentableElement.Element("YIELD").Value)*46.214*0.01, 2));
					fermentable.Lovibond = Convert.ToInt32(Math.Round(Convert.ToDouble(fermentableElement.Element("COLOR").Value), 0));

					var fermentableUsageType = fermentableElement.Element("TYPE").Value.ToLower();
					fermentable.FermentableUsageTypeId = (int) FermentableUsageType.Mash;

					if (fermentableUsageType == "grain")
					{
						fermentable.FermentableUsageTypeId = (int) FermentableUsageType.Mash;
					}
					else if (fermentableUsageType.IndexOf("extract") > -1)
					{
						fermentable.FermentableUsageTypeId = (int) FermentableUsageType.Extract;
					}
					else if (fermentableUsageType == "sugar")
					{
						fermentable.FermentableUsageTypeId = (int) FermentableUsageType.Late;
					}

					recipe.Fermentables.Add(fermentable);
				}
			}
		}