Esempio n. 1
0
        public async Task <ActionResult> Info(ManagerSortCriteria criteria = ManagerSortCriteria.Default, int pageNumber = 1)
        {
            var sortedManagers = await(Task.Run(() => ManagerService.SortManagers(ManagerService.Managers, criteria)));

            var pageSize = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PageSize"));

            var managerViewModel = new ManagerViewModel
            {
                PageInfo = new PageInfo(currentPageNumber: pageNumber, pageSize: pageSize, totalItems: sortedManagers.Count()),

                ManagersPerPage = PageInfo.GetItemsPerPage(sortedManagers, pageNumber, pageSize),

                Filters = new SelectList(Enum.GetValues(typeof(ManagerSortCriteria)), criteria)
            };

            return(PartialView(managerViewModel));
        }
        public async Task <ActionResult> Info(int?manager, int?customer, SaleSortCriteria criteria = SaleSortCriteria.Default, int pageNumber = 1)
        {
            IEnumerable <Sale> sales = await Task.Run(() => SaleService.Sales.ToList());


            var managerId = manager ?? 0;

            if (managerId != 0)
            {
                sales = SaleService.FilterByManager(sales, managerId);
            }

            var customerId = customer ?? 0;

            if (customerId != 0)
            {
                sales = SaleService.FilterByCustomer(sales, customerId);
            }

            sales = await Task.Run(() => SaleService.SortSales(sales, criteria));


            int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PageSize"));

            var saleViewModel = new SaleViewModel
            {
                PageInfo = new PageInfo(currentPageNumber: pageNumber, pageSize: pageSize, totalItems: sales.Count()),

                SalesPerPage = PageInfo.GetItemsPerPage(sales, pageNumber, pageSize),

                SortingFilters = new SelectList(Enum.GetValues(typeof(SaleSortCriteria)), criteria),

                Managers = await CreateManagerSelectList(managerId),

                Customers = await CreateCustomerSelectList(customerId)
            };

            return(PartialView(saleViewModel));
        }