예제 #1
0
        public IActionResult Random()
        {
            var       claim  = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid);
            int       idUser = int.Parse(claim.Value);
            RecipeDAO dao    = new RecipeDAO();

            List <Recipe> recipe = dao.LoadRecipes();

            int RandomNumber(int min, int max)
            {
                Random random = new Random();

                return(random.Next(min, max));
            }

            int           numero   = RandomNumber(0, recipe.Count);
            List <Recipe> receitas = dao.getFavorites(idUser);

            ViewBag.Boolean = false;
            foreach (Recipe recp in receitas)
            {
                if (recp.Id_Recipe == numero)
                {
                    ViewBag.Boolean = true;
                    break;
                }
            }

            Recipe r = dao.FindById(recipe.ElementAt(numero).Id_Recipe);

            ViewBag.image = r.GetImage();

            return(View(r));
        }
예제 #2
0
        public IActionResult Search(string words)
        {
            RecipeDAO     dao = new RecipeDAO();
            List <Recipe> result;

            if (words == null || words.Equals(""))
            {
                result = dao.LoadRecipes();
            }
            else
            {
                List <string> l_words = words.Split(' ').ToList();
                result = dao.searchByWords(l_words);
            }
            var claim  = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid);
            int idUser = int.Parse(claim.Value);

            Dictionary <int, float> rating = dao.allRatings();

            ViewBag.Ratings = rating;


            List <Recipe> receitas  = dao.getFavorites(idUser);
            List <int>    favoritos = new List <int>();

            foreach (Recipe recp in receitas)
            {
                favoritos.Add(recp.Id_Recipe);
            }
            ViewBag.Favorites = favoritos;

            return(View(result));
        }
예제 #3
0
        public IActionResult Index()
        {
            RecipeDAO dao = new RecipeDAO();

            List <Recipe> Recipes = dao.LoadRecipes();

            return(View(Recipes));
        }
예제 #4
0
        public IActionResult Index()
        {
            var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid);

            int idUser = int.Parse(claim.Value);

            RecipeDAO dao = new RecipeDAO();

            UserDAO    daou = new UserDAO();
            Utilizador u    = daou.FindById(idUser);

            List <Recipe> recipes = dao.LoadRecipeByType(u.Preferencia);

            Dictionary <int, float>           rating     = dao.allRatings();
            List <KeyValuePair <int, float> > sortingDic = rating.ToList();

            sortingDic.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value));

            List <Recipe> cardRecipes = new List <Recipe>();

            foreach (KeyValuePair <int, float> pairs in sortingDic.Take(2))
            {
                cardRecipes.Add(dao.FindById(pairs.Key));
            }

            List <Recipe> aux = dao.LoadRecipes();

            foreach (Recipe t in cardRecipes)
            {
                bool flag = aux.Remove(t);
                Console.WriteLine(flag);
            }

            Random rnd = new Random();

            for (int i = 0; i < 2; i++)
            {
                if (aux.Count > 0)
                {
                    int    rand = rnd.Next(aux.Count);
                    Recipe t    = aux[rand];
                    cardRecipes.Add(t);
                    aux.Remove(t);
                }
            }
            List <Recipe> receitas  = dao.getFavorites(idUser);
            List <int>    favoritos = new List <int>();

            foreach (Recipe recp in receitas)
            {
                favoritos.Add(recp.Id_Recipe);
            }
            ViewBag.Favorites  = favoritos;
            ViewBag.Ratings    = rating;
            ViewBag.CardRecipe = cardRecipes;

            return(View(recipes));
        }