public ICollection <IngredientDescription> GetAllPizzaIngredients(int pizzaId)
        {
            SqlDataReader reader = this.ExecuteReader(
                @"SELECT i.Id, i.Name
                     FROM Pizzas AS p
                     JOIN Pizzas_Ingredients AS pi
                       ON pi.PizzaId = p.Id
                     JOIN Ingredients AS i
                       ON pi.IngredientId = i.Id
                    WHERE p.Id = @pizzaId",
                new Dictionary <string, object>()
            {
                { "@pizzaId", pizzaId }
            });

            ICollection <IngredientDescription> pizzaIngredients = new List <IngredientDescription>();

            using (reader)
            {
                while (reader.Read())
                {
                    int    ingredientId   = reader.GetInt32(0);
                    string ingredientName = reader.GetString(1);
                    IngredientDescription pizzaIngredient = new IngredientDescription(ingredientId, ingredientName);

                    pizzaIngredients.Add(pizzaIngredient);
                }
            }

            return(pizzaIngredients);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            IngredientDescription ingredientdescription = db.IngredientDescriptions.Single(i => i.IngredientDescriptionID == id);

            db.IngredientDescriptions.DeleteObject(ingredientdescription);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
    /* Determins whether a recipe is orderable */
    public bool isOrderable(Ingredient ingredient)
    {
        IngredientDescription desc = GetIngredientDescription(ingredient);

        if (desc != null)
        {
            return(!string.Equals(desc.mode, "none"));
        }
        return(false);
    }
    /* Determines whether the given ingredient is cookable */
    public bool isCookable(Ingredient ingredient)
    {
        if (ingredient == null)
        {
            return(false);
        }
        IngredientDescription desc = GetIngredientDescription(ingredient);

        return(desc != null && desc.cookable);
    }
    /* Determines whether the given ingredient is cooked */
    public bool isCooked(Ingredient ingredient)
    {
        if (ingredient == null)
        {
            return(false);
        }
        IngredientDescription desc = GetIngredientDescription(ingredient);

        return(desc == null ? false : desc.cookable && (ingredient.numberOfPanFlips >= desc.correctFlips));
    }
    /* Determines whether the given ingredient is chopped */
    public bool isChopped(Ingredient ingredient)
    {
        if (ingredient == null)
        {
            return(false);
        }
        IngredientDescription desc = GetIngredientDescription(ingredient);

        return(desc == null ? false : desc.choppable && (ingredient.numberOfChops >= desc.correctChops));
    }
        public ActionResult Create(IngredientDescription ingredientdescription)
        {
            if (ModelState.IsValid)
            {
                db.IngredientDescriptions.AddObject(ingredientdescription);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ingredientdescription));
        }
 public ActionResult Edit(IngredientDescription ingredientdescription)
 {
     if (ModelState.IsValid)
     {
         db.IngredientDescriptions.Attach(ingredientdescription);
         db.ObjectStateManager.ChangeObjectState(ingredientdescription, EntityState.Modified);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ingredientdescription));
 }
    /* Gets a random recipe name */
    public string getRandomRecipeName()
    {
        int numIngredients           = allIngredients.ingredients.Length;
        IngredientDescription recipe = allIngredients.ingredients[Random.Range(0, numIngredients - 1)];

        while (!string.Equals(recipe.mode, mode))
        {
            recipe = allIngredients.ingredients[Random.Range(0, numIngredients - 1)];
        }

        return(recipe.name);
    }
Exemple #10
0
        /// <summary>
        /// Returns true if BrandedFoodObjectDietFlags instances are equal
        /// </summary>
        /// <param name="other">Instance of BrandedFoodObjectDietFlags to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(BrandedFoodObjectDietFlags other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Ingredient == other.Ingredient ||
                     Ingredient != null &&
                     Ingredient.Equals(other.Ingredient)
                     ) &&
                 (
                     IngredientDescription == other.IngredientDescription ||
                     IngredientDescription != null &&
                     IngredientDescription.Equals(other.IngredientDescription)
                 ) &&
                 (
                     DietLabel == other.DietLabel ||
                     DietLabel != null &&
                     DietLabel.Equals(other.DietLabel)
                 ) &&
                 (
                     IsCompatible == other.IsCompatible ||
                     IsCompatible != null &&
                     IsCompatible.Equals(other.IsCompatible)
                 ) &&
                 (
                     CompatibilityLevel == other.CompatibilityLevel ||
                     CompatibilityLevel != null &&
                     CompatibilityLevel.Equals(other.CompatibilityLevel)
                 ) &&
                 (
                     CompatibilityDescription == other.CompatibilityDescription ||
                     CompatibilityDescription != null &&
                     CompatibilityDescription.Equals(other.CompatibilityDescription)
                 ) &&
                 (
                     IsAllergen == other.IsAllergen ||
                     IsAllergen != null &&
                     IsAllergen.Equals(other.IsAllergen)
                 ));
        }
 /* Returns the description corresponding to an ingredient, if possible */
 public IngredientDescription GetIngredientDescription(Ingredient ingredient)
 {
     if (ingredient != null)
     {
         /* Iterate through all ingredient descriptions, finding and returning one with a matchign name */
         for (int i = 0; i < allIngredients.ingredients.Length; i++)
         {
             IngredientDescription testIngredient = allIngredients.ingredients[i];
             if (string.Equals(ingredient.Name, testIngredient.name))
             {
                 return(testIngredient);
             }
         }
     }
     return(null);
 }
        public ICollection <IngredientDescription> GetAllIngredients()
        {
            SqlDataReader reader = this.ExecuteReader(
                @"SELECT Id, Name
                     FROM Ingredients");

            ICollection <IngredientDescription> ingredients = new List <IngredientDescription>();

            using (reader)
            {
                while (reader.Read())
                {
                    int    ingredientId              = reader.GetInt32(0);
                    string ingredientName            = reader.GetString(1);
                    IngredientDescription ingredient = new IngredientDescription(ingredientId, ingredientName);

                    ingredients.Add(ingredient);
                }
            }

            return(ingredients);
        }
    /* Determines whether the input ingredient matches the provided criteria */
    public bool MatchesCriteria(Ingredient ingredient, IngredientCriteria criteria)
    {
        /* Grab corresponding ingredient description (if available) */
        IngredientDescription desc = GetIngredientDescription(ingredient);
        bool cooked = false, chopped = false;

        if (desc != null)
        {
            /* Determine ingredient status based on ingredient description */
            chopped = desc.choppable && (ingredient.numberOfChops >= desc.correctChops);
            cooked  = desc.cookable && (ingredient.numberOfPanFlips >= desc.correctFlips);

            bool nameMatches = string.Equals(desc.name, criteria.name);

            /* Check ingredient status against criteria */
            if (nameMatches && criteria.cooked == cooked && criteria.chopped == chopped)
            {
                return(true);
            }
        }

        return(false);
    }
Exemple #14
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Ingredient != null)
         {
             hashCode = hashCode * 59 + Ingredient.GetHashCode();
         }
         if (IngredientDescription != null)
         {
             hashCode = hashCode * 59 + IngredientDescription.GetHashCode();
         }
         if (DietLabel != null)
         {
             hashCode = hashCode * 59 + DietLabel.GetHashCode();
         }
         if (IsCompatible != null)
         {
             hashCode = hashCode * 59 + IsCompatible.GetHashCode();
         }
         if (CompatibilityLevel != null)
         {
             hashCode = hashCode * 59 + CompatibilityLevel.GetHashCode();
         }
         if (CompatibilityDescription != null)
         {
             hashCode = hashCode * 59 + CompatibilityDescription.GetHashCode();
         }
         if (IsAllergen != null)
         {
             hashCode = hashCode * 59 + IsAllergen.GetHashCode();
         }
         return(hashCode);
     }
 }
    /* Determines whether the input ingredient matches the current cuisine */
    public bool MatchesMode(Ingredient ingredient)
    {
        IngredientDescription desc = GetIngredientDescription(ingredient);

        return(desc != null && desc.mode.Equals(mode));
    }
        //
        // GET: /IngredientDescription/Delete/5

        public ActionResult Delete(int id)
        {
            IngredientDescription ingredientdescription = db.IngredientDescriptions.Single(i => i.IngredientDescriptionID == id);

            return(View(ingredientdescription));
        }
    /* Gets the score corresponding to an ingredient */
    public int getScoreForIngredient(Ingredient ingredient)
    {
        IngredientDescription desc = GetIngredientDescription(ingredient);

        return(desc != null ? desc.score : 0);
    }
        //
        // GET: /IngredientDescription/Details/5

        public ViewResult Details(int id)
        {
            IngredientDescription ingredientdescription = db.IngredientDescriptions.Single(i => i.IngredientDescriptionID == id);

            return(View(ingredientdescription));
        }