Пример #1
0
        public Dictionary <DateTime, Recipe> userHistory(int idUser)
        {
            Dictionary <DateTime, Recipe> result        = new Dictionary <DateTime, Recipe>();
            Dictionary <DateTime, int>    dic_id_recipe = new Dictionary <DateTime, int>();
            Connection con = new Connection();

            using (SqlCommand command = con.Fetch().CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = "select * from[History] where Id_User=@user";
                command.Parameters.Add("@user", SqlDbType.Int).Value = idUser;

                using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                {
                    DataTable result_query = new DataTable();
                    adapter.Fill(result_query);

                    foreach (DataRow row in result_query.Rows)
                    {
                        DateTime value    = (DateTime)row["Date"];
                        int      idrecipe = int.Parse(row["Id_Recipe"].ToString());

                        dic_id_recipe.Add(value, idrecipe);
                    }
                }
            }
            RecipeDAO dao = new RecipeDAO();

            foreach (KeyValuePair <DateTime, int> pair in dic_id_recipe)
            {
                result.Add(pair.Key, dao.FindById(pair.Value));
            }
            con.Close();

            return(result);
        }
Пример #2
0
        public Menu getLastestMenu(int idUser)
        {
            Connection con    = new Connection();
            Menu       result = new Menu();

            using (SqlCommand command = con.Fetch().CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = "SELECT Id_Menu AS Menu,Date FROM Menu WHERE Id_User=@user ORDER BY Date DESC";
                command.Parameters.Add("@user", SqlDbType.Int).Value = idUser;

                using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                {
                    DataTable result_query = new DataTable();
                    adapter.Fill(result_query);

                    if (result_query.Rows.Count == 0)
                    {
                        return(null);
                    }


                    DataRow  row = result_query.Rows[0];
                    int      idMenu;
                    bool     flag = int.TryParse(row["Menu"].ToString(), out idMenu);
                    DateTime date = (DateTime)row["Date"];

                    if (!flag)
                    {
                        return(null);
                    }

                    result.Id_Menu      = idMenu;
                    result.StartingDate = date;
                }
            }

            List <int> aux = new List <int>();

            using (SqlCommand command = con.Fetch().CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = "SELECT * FROM Menu_Recipe WHERE Id_Menu = @menu ORDER BY Position DESC";
                command.Parameters.Add("@menu", SqlDbType.Int).Value = result.Id_Menu;

                using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                {
                    DataTable result_query = new DataTable();
                    adapter.Fill(result_query);

                    foreach (DataRow row in result_query.Rows)
                    {
                        aux.Add((int)row["Id_Recipe"]);
                    }
                }
            }
            result.Recipes = new List <Recipe>();
            RecipeDAO dao = new RecipeDAO();

            foreach (int i in aux)
            {
                result.Recipes.Add(dao.FindById(i));
            }
            con.Close();

            return(result);
        }