public UnitTranslation GetTranslation(UnitType BaseType, UnitType TargetType, Ingredient Ingred) { UnitTranslation ReturnObject = null; var TList = this .Where(s => (s.AffectedIngredient != null) && (s.AffectedIngredient == Ingred) && (s.TranslationStatus != ListEntryStatus.IsNotConfirmed) && (((s.BaseUnit.Type == BaseType) && (s.TargetUnit.Type == TargetType)) || ((s.BaseUnit.Type == TargetType) && (s.TargetUnit.Type == BaseType)))); if (TList.Count() == 1) { ReturnObject = TList.ElementAt(0); if (ReturnObject.BaseUnit.Type != BaseType) { ReturnObject.Inverse(); } } return(ReturnObject); }
public RecipeIngredient(double Quantity, Unit Unit, Ingredient Ingredient) { _Quantity = Quantity; _Unit = Unit; _Ingredient = Ingredient; }
public UnitTranslation GetTranslation(Unit Base, Unit Target, Ingredient Ingred) { UnitTranslation BaseTranslation; UnitTranslation InterTypeTranslation; UnitTranslation ReturnObject = null; UnitTranslation TargetTranslation; if (Base.Type == Target.Type) { ReturnObject = GetTranslation(Base, Target); } else { InterTypeTranslation = GetTranslation(Base.Type, Target.Type, Ingred); if (InterTypeTranslation != null) { BaseTranslation = GetTranslation(Base, InterTypeTranslation.BaseUnit); TargetTranslation = GetTranslation(InterTypeTranslation.TargetUnit, Target); if ((BaseTranslation != null) && (TargetTranslation != null)) { ReturnObject = new UnitTranslation(); ReturnObject.BaseUnit = Base; ReturnObject.TargetUnit = Target; ReturnObject.AffectedIngredient = Ingred; ReturnObject.IngredientType = Ingred.Type; ReturnObject.TranslationFlag = TranslationType.IsTypeChange | TranslationType.IsIngredientDependent; ReturnObject.TranslationFactor = BaseTranslation.TranslationFactor * InterTypeTranslation.TranslationFactor * TargetTranslation.TranslationFactor; } } else { AddInactiveItem(Base, Target, Ingred); InterTypeTranslation = GetTranslation(Base, Target, Ingred.Type); if (InterTypeTranslation != null) { BaseTranslation = GetTranslation(Base, InterTypeTranslation.BaseUnit); TargetTranslation = GetTranslation(InterTypeTranslation.TargetUnit, Target); if ((BaseTranslation != null) && (TargetTranslation != null)) { ReturnObject = new UnitTranslation(); ReturnObject.BaseUnit = Base; ReturnObject.TargetUnit = Target; ReturnObject.AffectedIngredient = null; ReturnObject.IngredientType = Ingred.Type; ReturnObject.TranslationFlag = TranslationType.IsTypeChange; ReturnObject.TranslationFactor = BaseTranslation.TranslationFactor * InterTypeTranslation.TranslationFactor * TargetTranslation.TranslationFactor; } } else { AddInactiveItem(Base, Target, Ingred.Type); } } } return(ReturnObject); }