Esempio n. 1
0
        public async Task <IActionResult> GetAsync(string name)
        {
            var category = await _categoryServices.GetAsync(name);

            if (category == null)
            {
                return(NotFound());
            }

            return(Json(category));
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(string sortOrder, string currentFilter,
                                                string searchString, int?pageIndex = 1, int pageSize = 10)
        {
            ViewData["CurrentPageSize"] = pageSize;
            ViewData["CurrentSort"]     = sortOrder;
            ViewData["NameSortParm"]    = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["TotalSortParm"]   = sortOrder == "Total" ? "total_desc" : "Total";

            if (searchString != null)
            {
                pageIndex = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            Expression <Func <Category, bool> > filter = null;

            if (!string.IsNullOrEmpty(searchString))
            {
                filter = c => c.Name.Contains(searchString);
            }

            Func <IQueryable <Category>, IOrderedQueryable <Category> > orderBy = null;

            switch (sortOrder)
            {
            case "name_desc":
                orderBy = q => q.OrderByDescending(c => c.Name);
                break;

            case "Total":
                orderBy = q => q.OrderBy(c => c.Todos.Count);
                break;

            case "total_desc":
                orderBy = q => q.OrderByDescending(c => c.Todos.Count);
                break;

            default:
                orderBy = q => q.OrderBy(c => c.Name);
                break;
            }

            var categories = await _categoryServices.GetAsync(filter : filter, orderBy : orderBy, pageIndex : pageIndex ?? 1, pageSize : pageSize, includeProperties : "Todos");

            return(View(categories));
        }
        public async Task <IActionResult> Index(string sortOrder, string currentFilter, string searchString, int?pageIndex = 1, int pageSize = 10)
        {
            ViewData["CurrentPageSize"]      = pageSize;
            ViewData["CurrentSort"]          = sortOrder;
            ViewData["NameSortParm"]         = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["SlugSortParm"]         = sortOrder == "Slug" ? "slug_desc" : "Slug";
            ViewData["CreatedDateSortParm"]  = sortOrder == "CreatedDate" ? "createdDate_desc" : "CreatedDate";
            ViewData["ModifiedDateSortParm"] = sortOrder == "ModifiedDate" ? "modifiedDate_desc" : "ModifiedDate";

            if (searchString != null)
            {
                pageIndex = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            Expression <Func <Category, bool> > filter = null;

            if (!string.IsNullOrEmpty(searchString))
            {
                filter = c => c.Name.Contains(searchString) || c.Slug.Contains(searchString);
            }

            Func <IQueryable <Category>, IOrderedQueryable <Category> > orderBy = null;

            switch (sortOrder)
            {
            case "name_desc":
                orderBy = q => q.OrderByDescending(c => c.Name);
                break;

            case "Slug":
                orderBy = q => q.OrderBy(c => c.Slug);
                break;

            case "slug_desc":
                orderBy = q => q.OrderByDescending(c => c.Slug);
                break;

            case "CreatedDate":
                orderBy = q => q.OrderBy(c => c.CreatedDate);
                break;

            case "createdDate_desc":
                orderBy = q => q.OrderByDescending(c => c.CreatedDate);
                break;

            case "ModifiedDate":
                orderBy = q => q.OrderBy(c => c.ModifiedDate);
                break;

            case "modifiedDate_desc":
                orderBy = q => q.OrderByDescending(c => c.ModifiedDate);
                break;

            default:
                orderBy = q => q.OrderBy(c => c.Name);
                break;
            }

            var categories = await _categoryServices.GetAsync(filter : filter, orderBy : orderBy, pageIndex : pageIndex ?? 1, pageSize : pageSize);

            return(View(categories));
        }