public override bool Equals(object obj) { Recepta recepta = obj as Recepta; bool iguals = recepta != null; bool potPrimer = true, potSegon = false; IEnumerator <Ingredient> ingredients = null, ingredientsAComparar = null; if (iguals) { iguals = PrimaryKey == recepta.PrimaryKey; if (iguals) { ingredients = this.GetEnumerator(); ingredientsAComparar = recepta.GetEnumerator(); while (iguals && potPrimer) { potPrimer = ingredients.MoveNext(); potSegon = ingredientsAComparar.MoveNext(); if (potSegon.Equals(potPrimer)) { if (potPrimer) { iguals = ingredients.Current.Equals(ingredientsAComparar.Current); } } else { iguals = false; } } if (iguals) { iguals = ingredients.MoveNext().Equals(ingredientsAComparar.MoveNext()); } } } return(iguals); }
public static UnitatProducte Fabrica(Producte producte, Recepta recepta, IEnumerable <Producte> productesPerFerLo) { UnitatProducte unitatFeta = null; SortedList <string, Producte> productesIndex = new SortedList <string, Producte>(); foreach (Producte productePerFer in productesPerFerLo) { try { productesIndex.Add(productePerFer.PrimaryKey, productePerFer); } catch { } } bool esPotFer = true; bool acabat = false; IEnumerator <Ingredient> ingredients = recepta.GetEnumerator(); while (esPotFer && !acabat) { acabat = !ingredients.MoveNext(); if (!acabat) { esPotFer = productesIndex.ContainsKey(ingredients.Current.Producte.PrimaryKey); if (esPotFer) { esPotFer = (productesIndex[ingredients.Current.Producte.PrimaryKey].QuantitatTotal / ingredients.Current.Quantitat) >= 1; } } } if (esPotFer) { foreach (Ingredient ingredient in recepta) { productesIndex[ingredient.Producte.PrimaryKey].TreuQuantitat(ingredient.Quantitat); } unitatFeta = new UnitatProducte(producte, 1M, new DateTime(), new DateTime(), recepta); } return(unitatFeta); }