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 async Task <IActionResult> Edit(string foodId) { Food food = await _foodServices.GetFood(foodId); if (food == null) { return(NotFound()); } EditFoodViewModel foodEdit = new EditFoodViewModel() { FoodName = food.Name, Images = food.FoodImages.ToList(), IsActive = food.IsActive, Price = food.Price, FoodId = food.FoodId }; return(View(foodEdit)); }
public async Task <IActionResult> Create(string foodId) { AppIdentityUser user = await _userManager.GetUserAsync(User); Food food = await _foodServices.GetFood(foodId); if (user != null && food != null) { OrderDetail order = await _orderServices.GetOrderToday(user.Id); if (order == null) { if (await _orderServices.CreateOrder(food: food, user: user)) { ViewBag.foodName = food.Name; return(View("~/Views/Order/OrderSuccess.cshtml")); } } } return(RedirectToAction(actionName: "Index", controllerName: "Home")); }
public List <Receptmodels> Slumplist(int user_id, DateTime date) { date = datefixer(date); List <Receptmodels> food_list = new List <Receptmodels>(); Receptmodels re = new Receptmodels(); food_list = _foodServices.GetFood("SELECT * FROM recept WHERE id_recept IN (SELECT recept_id FROM users_has_recept WHERE user_id =@id_user)", user_id); int maxdays = 5; int maxnumber = food_list.Count; Random rnd = new Random(); List <Receptmodels> random_list = new List <Receptmodels>(); int i = 0; bool check = true; if (maxnumber > 7) { while (i < maxdays) { check = true; int number = rnd.Next(1, maxnumber); foreach (var item in random_list) { if (item.Id == food_list[number].Id) { check = false; } } if (check) { food_list[number].Date = date; food_list[number].DateName = NameOfDay(date); random_list.Add(food_list[number]); i++; date = date.AddDays(1); } } } if (maxnumber <= 7) { re.Id = -10; re.Name = "Inte tillräckligt med maträtter för att slumpa fram en vecka!!!"; random_list.Add(re); } return(random_list); }
public ActionResult Index(int?page, int?size) { int SizeofPage = 20; if (size != null) { SizeofPage = size.Value; } var food_list = new List <Receptmodels>(); food_list = _foodServices.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)); var pager = new Pager(food_list.Count, page, SizeofPage); ViewBag.Count = food_list.Count; var viewModel = new IndexViewModel { Items = food_list.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize), Pager = pager, Size = SizeofPage }; return(View(viewModel)); }