Example #1
0
        public List <Meal> GetList()
        {
            ProductDAL productDAL = new ProductDAL(configuration);
            var        listMeal   = new List <Meal>();
            string     mealQuery  = "SELECT * FROM [dbo].[Posilki]";

            try
            {
                using (SqlConnection con = new SqlConnection(_connectionString))
                {
                    SqlCommand cmd = new SqlCommand(mealQuery, con);
                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        listMeal.Add(new Meal
                        {
                            Id          = Convert.ToInt32(rdr[0]),
                            ProductList = productDAL.GetMealProducts(Convert.ToInt32(rdr[0])),
                            Recipe      = rdr[1].ToString(),
                            Category    = rdr[2].ToString()
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(listMeal);
        }
Example #2
0
        public List <ShoppingList> GetList()
        {
            ProductDAL productDAL        = new ProductDAL(configuration);
            var        ShoppingLists     = new List <ShoppingList>();
            string     ShoppingListQuery = "SELECT * FROM [dbo].[ListaZakupow]";

            try
            {
                using (SqlConnection con = new SqlConnection(_connectionString))
                {
                    SqlCommand cmd = new SqlCommand(ShoppingListQuery, con);
                    //cmd.CommandType = CommandType.StoredProcedure;
                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        ShoppingLists.Add(new ShoppingList
                        {
                            Id   = Convert.ToInt32(rdr[0]),
                            Name = rdr[1].ToString(),
                            //Weight = Convert.ToInt32(rdr[2]),
                            IdUser = Convert.ToInt32(rdr[2]),
                            ShoppingListProducts = productDAL.GetShoppingProducts(Convert.ToInt32(rdr[0]))
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ShoppingLists);
        }