Example #1
0
        /// <summary>
        /// Sets the hops on the Recipe
        /// </summary>
        void SetHops(Recipe recipe, XElement entryPoint)
        {
            var allHops = this.BrewDataService.GetUsableIngredients <Hop>(this.UserId);

            recipe.Hops = new List <RecipeHop>();
            if (entryPoint.Element("HOPS") != null)
            {
                foreach (var hopElement in entryPoint.Element("HOPS").Elements("HOP"))
                {
                    var hop = new RecipeHop();

                    var matchingHop = allHops.FirstOrDefault(x => x.Name.Trim().ToLower() == hopElement.Element("NAME").Value.Trim().ToLower());

                    if (matchingHop != null)
                    {
                        hop.IngredientId = matchingHop.IngredientId;
                        hop.Hop          = matchingHop;
                    }
                    else
                    {
                        hop.IngredientId = 0;
                        hop.Hop          = new Hop();
                        hop.Hop.Name     = hopElement.Element("NAME").Value;
                        hop.Hop.AA       = Convert.ToDouble(hopElement.Element("ALPHA").Value);
                    }

                    hop.AlphaAcidAmount = Convert.ToDouble(hopElement.Element("ALPHA").Value);
                    hop.Amount          = Math.Round(this.RecipeUnitConverter.ConvertKilogramsToOunces(Convert.ToDouble(hopElement.Element("AMOUNT").Value)) * 10000) / 10000;
                    hop.TimeInMinutes   = Convert.ToInt16(hopElement.Element("TIME").Value);
                    hop.HopTypeId       = (int)HopType.Pellet;

                    var hopUsageType = hopElement.Element("USE").Value.Trim().ToLower();
                    if (hopUsageType == "boil")
                    {
                        hop.HopUsageTypeId = (int)HopUsageType.Boil;
                    }
                    else if (hopUsageType == "mash")
                    {
                        hop.HopUsageTypeId = (int)HopUsageType.Mash;
                    }
                    else if (hopUsageType == "dry hop")
                    {
                        hop.HopUsageTypeId = (int)HopUsageType.DryHop;
                    }
                    else
                    {
                        hop.HopUsageTypeId = (int)HopUsageType.Boil;
                    }

                    recipe.Hops.Add(hop);
                }
            }
        }
		/// <summary>
		/// Sets the hops on the Recipe
		/// </summary>
		void SetHops(Recipe recipe, XElement entryPoint)
		{
			var allHops = this.BrewDataService.GetUsableIngredients<Hop>(this.UserId);
			recipe.Hops = new List<RecipeHop>();
			if (entryPoint.Element("HOPS") != null)
			{
				foreach (var hopElement in entryPoint.Element("HOPS").Elements("HOP"))
				{
					var hop = new RecipeHop();

					var matchingHop = allHops.FirstOrDefault(x => x.Name.Trim().ToLower() == hopElement.Element("NAME").Value.Trim().ToLower());

					if (matchingHop != null)
					{
						hop.IngredientId = matchingHop.IngredientId;
						hop.Hop = matchingHop;
					}
					else
					{
						hop.IngredientId = 0;
						hop.Hop = new Hop();
						hop.Hop.Name = hopElement.Element("NAME").Value;
						hop.Hop.AA = Convert.ToDouble(hopElement.Element("ALPHA").Value);
					}

					hop.AlphaAcidAmount = Convert.ToDouble(hopElement.Element("ALPHA").Value);
					hop.Amount = Math.Round(this.RecipeUnitConverter.ConvertKilogramsToOunces(Convert.ToDouble(hopElement.Element("AMOUNT").Value)) * 10000) / 10000;
					hop.TimeInMinutes = Convert.ToInt16(hopElement.Element("TIME").Value);
					hop.HopTypeId = (int) HopType.Pellet;

					var hopUsageType = hopElement.Element("USE").Value.Trim().ToLower();
					if (hopUsageType == "boil")
					{
						hop.HopUsageTypeId = (int) HopUsageType.Boil;
					}
					else if (hopUsageType == "mash")
					{
						hop.HopUsageTypeId = (int) HopUsageType.Mash;
					}
					else if (hopUsageType == "dry hop")
					{
						hop.HopUsageTypeId = (int) HopUsageType.DryHop;
					}
					else
					{
						hop.HopUsageTypeId = (int) HopUsageType.Boil;
					}

					recipe.Hops.Add(hop);
				}
			}
		}