public DrinkViewModels PostDrinkId([FromBody]int id)
 {
     using (var db = new DrinkAppContext())
     {
         var dri = new DrinkRecipeViewModels();
         var drink = db.Drinks.Select(a => a).Where(b => b.DrinkID == id).FirstOrDefault();
         var drinkVM = new List<DrinkViewModels>();
         var x = (from dr in db.DrinkRecipes
                  join i in db.Ingredients
                  on dr.IngredientID equals i.IngredientID
                  where dr.DrinkID == id
                  select new DrinkRecipeViewModels
                  {
                      DrinkRecipeID = dr.DrinkRecipeID,
                      Amount = dr.Amount,
                      Order = dr.Order,
                      IngredientID = dr.IngredientID,
                      DrinkID = dr.DrinkID,
                      Name = i.Name
                  }).ToList();
         var drinkVMs = new DrinkViewModels();
         drinkVMs.DrinkID = drink.DrinkID;
         drinkVMs.Name = drink.Name;
         drinkVMs.DrinkTaste = drink.DrinkTaste;
         drinkVMs.DrinkType = drink.DrinkType;
         drinkVMs.Complexity = drink.Complexity;
         drinkVMs.DRI = x;
         return drinkVMs;
     }
 }
Ejemplo n.º 2
0
        public IEnumerable<DrinkViewModels> Get()
        {
            using (var db = new DrinkAppContext())
            {

                var dri = new DrinkRecipeViewModels();
                var drinkVM = new List<DrinkViewModels>();
                var drinklist = db.Drinks.ToList();
                foreach (var item in drinklist)
                {

                    var x = (from dr in db.DrinkRecipes
                             join i in db.Ingredients
                             on dr.IngredientID equals i.IngredientID
                             where dr.DrinkID == item.DrinkID
                             select new DrinkRecipeViewModels
                             {

                                 DrinkRecipeID = dr.DrinkRecipeID,
                                 Amount = dr.Amount,
                                 Order = dr.Order,
                                 IngredientID = dr.IngredientID,
                                 DrinkID = dr.DrinkID,
                                 Name = i.Name
                             }).ToList();

                    var drinkVMs = new DrinkViewModels();
                    drinkVMs.DrinkID = item.DrinkID;
                    drinkVMs.Name = item.Name;
                    drinkVMs.DrinkTaste = item.DrinkTaste;
                    drinkVMs.DrinkType = item.DrinkType;
                    drinkVMs.Complexity = item.Complexity;
                    drinkVMs.DRI = x;
                    drinkVM.Add(drinkVMs);
                }
                return drinkVM;
            }
        }