Ejemplo n.º 1
0
        public async Task <IActionResult> Index(
            string name,
            AdminOptionFilterStrategy filter = AdminOptionFilterStrategy.All,
            int pageNumber = 1)
        {
            var cookies = this.HttpContext.Request.Cookies;

            var sortStrategyKey = WebConstants.CookieAdminOptionsSortTypeKey;
            var sortType        = this.cookiesService.GetValueOrDefault <OptionSortStrategyType>(cookies, sortStrategyKey);

            var sortDirectionKey = WebConstants.CookieAdminOptionsSortDirectionKey;
            var sortDirection    = this.cookiesService.GetValueOrDefault <SortStrategyDirection>(cookies, sortDirectionKey);

            var sortStrategy    = OptionSortStrategyFactory.GetStrategy(sortType, sortDirection);
            var filterStrategy  = OptionFilterStrategyFactory.GetStrategy(filter, name);
            var allOptions      = this.optionRepository.GetAll();
            var filteredOptions = filterStrategy.Filter(allOptions);

            // TODO: Make use of projectTo
            var optionServiceModels = await this.adminOptionsService
                                      .GetAllSorted(filteredOptions, sortStrategy, pageNumber)
                                      .ToArrayAsync();

            var optionViewModels = Mapper.Map <IEnumerable <OptionViewModel> >(optionServiceModels);

            var model = new AdminOptionsViewModel()
            {
                CurrentPage           = pageNumber,
                Options               = optionViewModels,
                TotalPagesCount       = await PaginationHelper.CountTotalPagesCountAsync(filteredOptions),
                SortStrategyDirection = sortDirection,
                SortStrategyType      = sortType
            };

            return(View(model));
        }
 public AdminOptionsWindow(string user)
 {
     InitializeComponent();
     _viewmodel       = new AdminOptionsViewModel(user);
     this.DataContext = _viewmodel;
 }