示例#1
0
        public IActionResult Index(int pageNo = 1, string category = "Все")
        {
            List <Food> foods;

            if (category == "Все")
            {
                foods = dbContext.Foods.ToList();
            }
            else
            {
                Category cat = dbContext.Categories.FirstOrDefault(c => c.Name == category);
                foods = dbContext.Foods.Where(f => f.CategoryId == cat.Id).ToList();
            }
            ListModelView <Food> page = ListModelView <Food> .CreatePage(foods, itemsPerPage, pageNo);

            foreach (Food food in page)
            {
                food.Category = dbContext.Categories.FirstOrDefault(c => c.Id == food.CategoryId);
            }

            ViewData["Category"]   = category;
            ViewData["Categories"] = GetCategories();

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ListPartial", page));
            }
            else
            {
                return(View(page));
            }
        }
示例#2
0
        public IActionResult Index(int pageNo = 1, string category = "Все")
        {
            List <Food> foods;

            if (category == "Все")
            {
                foods = dbContext.Foods.Include(f => f.Category).ToList();
            }
            else
            {
                Category cat = dbContext.Categories.FirstOrDefault(c => c.Name == category);
                foods = dbContext.Foods.Where(f => f.CategoryId == cat.Id).Include(f => f.Category).ToList();
            }
            foods.Sort((f1, f2) => f1.Category.Name.CompareTo(f2.Category.Name));

            ListModelView <Food> page = ListModelView <Food> .CreatePage(foods, itemsPerPage, pageNo);


            ViewData["Category"]   = category;
            ViewData["Categories"] = GetCategories();

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ListPartial", page));
            }
            else
            {
                return(View(page));
            }
        }
示例#3
0
 public void setListFilesView(ListModelView listModelView)
 {
     cList = listModelView;
 }