示例#1
0
        public async Task <IActionResult> Search([Bind("q,PageNumber,SelectedOrder")] CollectionViewModel model)
        {
            model.PageSize = 50;
            var items = _context.Items
                        .AsNoTracking()
                        .Include(i => i.ItemCategories)
                        .ThenInclude(i => i.Category)
                        .AsQueryable();

            if (!string.IsNullOrEmpty(model.q))
            {
                string[] keywords = model.q.Trim().ToLower().Split(" ");
                foreach (string keyword in keywords)
                {
                    items = items.Where(i => i.Name.ToLower().Contains(keyword) ||
                                        i.ItemCategories.Any(ic => ic.Category.Name.ToLower().Contains(keyword)) ||
                                        i.Description.ToLower().Contains(keyword));
                }
            }

            items = items.OrderItemsBy(model.SelectedOrder);

            await model.PaginateItems(items);

            return(View("Category", model));
        }
示例#2
0
        public async Task <IActionResult> Category(string grade, string series, [Bind("PageNumber,SelectedOrder")] CollectionViewModel model)
        {
            var allCategories = await _context.Categories
                                .AsNoTracking()
                                .ToListAsync();

            var gradeCategory = allCategories.Where(c => c.Name.NameEncode() == grade).FirstOrDefault();

            if (gradeCategory == null)
            {
                return(NotFound());
            }
            model.GradeName = gradeCategory.Name;
            var items = _context.Items
                        .AsNoTracking()
                        .Include(i => i.ItemCategories)
                        .Where(i => i.ItemCategories.Any(ic => ic.CategoryId == gradeCategory.Id));

            if (!string.IsNullOrEmpty(series))
            {
                var seriesCategory   = allCategories.Where(c => c.Name.NameEncode() == series).FirstOrDefault();
                int seriesCategoryId = -1;
                if (seriesCategory != null)
                {
                    model.SeriesName = seriesCategory.Name;
                    seriesCategoryId = seriesCategory.Id;
                }
                items = items.Where(b => b.ItemCategories.Any(ic => ic.CategoryId == seriesCategoryId));
            }

            items = items.OrderItemsBy(model.SelectedOrder);

            await model.PaginateItems(items);

            model.SeriesCategories = await _context.Categories
                                     .AsNoTracking()
                                     .Where(b => b.ParentCategory.Id == gradeCategory.Id)
                                     .ToListAsync();

            return(View(model));
        }
        public async Task <IActionResult> Index([Bind("PageNumber,SelectedOrder")] CollectionViewModel model)
        {
            String coverPath   = Path.Combine(_webHostEnvironment.WebRootPath, "images\\cover");
            String galleryPath = Path.Combine(_webHostEnvironment.WebRootPath, "images\\gallery");

            if (!Directory.Exists(coverPath))
            {
                Directory.CreateDirectory(coverPath);
            }
            if (!Directory.Exists(galleryPath))
            {
                Directory.CreateDirectory(galleryPath);
            }

            model.PageSize = 20;
            var allItems = _context.Items
                           .Include(i => i.Photos)
                           .AsNoTracking();

            var items = allItems.OrderItemsBy(model.SelectedOrder);
            await model.PaginateItems(items);

            return(View(model));
        }