public ActionResult All(int?page, int?size, string search, bool chicken, bool beef, bool fish, bool meat, bool pork, bool sausage, bool vego, string cookingtime) { int SizeofPage = 20; if (size != null) { SizeofPage = size.Value; } if (string.IsNullOrEmpty(cookingtime)) { cookingtime = "Över 60 minuter"; } var recept = new List <Receptmodels>(); var sql = _foodservice.CreateSearchString(chicken, vego, fish, beef, pork, sausage, meat, false, search, cookingtime); recept = _foodservice.GetFoodListForReceptView("SELECT * FROM public.recept_search_view" + sql, Convert.ToInt32(User.Identity.Name), search); ViewBag.Myfood = _foodservice.GetFood("SELECT * FROM recept WHERE id_recept IN (SELECT recept_id FROM users_has_recept WHERE user_id =@id_user)", Convert.ToInt32(User.Identity.Name)); ViewBag.food = recept; var pager = new Pager(recept.Count, page, SizeofPage); var viewModel = new IndexViewModel { Items = recept.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize), Pager = pager, Sökord = search, Size = SizeofPage, BeefFilter = beef, ChickenFilter = chicken, FishFilter = fish, MeatFilter = meat, PorkFilter = pork, SausageFilter = sausage, VegoFilter = vego, Cookingtime = cookingtime }; var cooking = new List <string> { "Under 15 minuter", "Under 30 minuter", "Under 45 minuter", "Under 60 minuter", "Över 60 minuter" }; ViewBag.Cookingtimes = cooking; return(View(viewModel)); }
public List <Receptmodels> CreateRandomListOfRecept() { var List = _foodServices.GetFoodListForReceptView("SELECT * FROM public.recept_search_view", 1, null); Random rnd = new Random(); int maxnumber = List.Count; var ListOfrandom = new List <Receptmodels>(); for (int i = 0; i < 3; i++) { int number = rnd.Next(1, maxnumber); ListOfrandom.Add(List[number]); } return(ListOfrandom); }