コード例 #1
0
 public ActionResult DeleteFromRecipe(int idRecipe, int idIngredient)
 {
     if (IngredientsDAO.DeleteFromRecipe(idRecipe, idIngredient))
     {
         return(Ok());
     }
     return(BadRequest());
 }
コード例 #2
0
 public ActionResult Delete(int id)
 {
     if (IngredientsDAO.Delete(id))
     {
         return(Ok());
     }
     return(BadRequest());
 }
コード例 #3
0
        public ActionResult PutInRecipe([FromBody] UsedIngredientsDTO ingredientDto)
        {
            if (IngredientsDAO.UpdateInRecipe(ingredientDto))
            {
                return(Ok());
            }

            return(BadRequest());
        }
コード例 #4
0
        public List <CocktailModel> GetNewGeneratedCocktail(int numberOfIngridients, double finalPercentageOfAlcohol, string drinkName)
        {
            List <CocktailModel>   cocktailReturnColl = new List <CocktailModel>();
            CocktailModel          cocktailReturn     = null;
            List <IngredientModel> ingredientColl     = null;

            cocktailDAO    = new CocktailDAO();
            ingredientsDAO = new IngredientsDAO();

            if (numberOfIngridients == 0)
            {
                numberOfIngridients = 2;
            }

            if (finalPercentageOfAlcohol == 0)
            {
                finalPercentageOfAlcohol = 0.15;
            }

            ingredientColl = ingredientsDAO.ListAll();

            cocktailReturn      = new CocktailModel();
            cocktailReturn.Name = "".Equals(drinkName) ? "New Drink" : drinkName;

            Random r = new Random();

            for (int i = 0; i < numberOfIngridients; i++)
            {
                int x          = r.Next(ingredientColl.Count);
                var ingridient = ingredientColl[x];
                if (cocktailReturn.OrderIngredient == null)
                {
                    cocktailReturn.OrderIngredient = new List <IngredientModel>();
                    cocktailReturn.OrderIngredient.Add(ingridient);
                }
                else
                {
                    if (cocktailReturn.OrderIngredient.Exists(item => item.Name == "Champagne"))
                    {
                        if (ingridient.Name.Equals("Campari"))
                        {
                            cocktailReturn.OrderIngredient.Add(ingredientColl.Single(item => item.Name != "Campari"));
                        }
                    }
                    else if (cocktailReturn.OrderIngredient.Exists(item => item.Name == "Campari"))
                    {
                        {
                            if (ingridient.Name.Equals("Champagne"))
                            {
                                cocktailReturn.OrderIngredient.Add(ingredientColl.Single(item => item.Name != "Champagne"));
                            }
                        }
                    }
                    else
                    {
                        cocktailReturn.OrderIngredient.Add(ingridient);
                    }
                }
            }

            if (Util.Utils.SumAlcohol(cocktailReturn.OrderIngredient) <= finalPercentageOfAlcohol)
            {
                cocktailReturn.HexadecimalColor    = Util.Utils.GetHexaDrink(cocktailReturn.OrderIngredient);
                cocktailReturn.PercentageOfAlcohol = Util.Utils.SumAlcohol(cocktailReturn.OrderIngredient);
                cocktailReturnColl.Add(cocktailReturn);
            }

            return(cocktailReturnColl);
        }
コード例 #5
0
 public UsedIngredientsDTO PostToRecipe([FromBody] UsedIngredientsDTO ingredientDto)
 {
     return(IngredientsDAO.PostToRecipe(ingredientDto));
 }
コード例 #6
0
 public IngredientsDTO Post([FromBody] IngredientsDTO ingredientDto)
 {
     return(IngredientsDAO.Post(ingredientDto));
 }
コード例 #7
0
 public IEnumerable <UsedIngredientsDTO> GetFromRecipe(int recipeId)
 {
     return(IngredientsDAO.QueryFromRecipe(recipeId));
 }
コード例 #8
0
 public IEnumerable <IngredientsDTO> Get()
 {
     return(IngredientsDAO.Query());
 }