Exemple #1
0
        public static ICarSortStrategy <TCar> GetStrategy <TCar>(
            BaseCarSortStrategyType sortType,
            SortStrategyDirection sortDirection) where TCar : BaseCar
        {
            switch (sortType)
            {
            case BaseCarSortStrategyType.Price when sortDirection == SortStrategyDirection.Ascending:
                return(new SortCarsByPredicateStrategy <TCar, decimal>(c => c.Price));

            case BaseCarSortStrategyType.Price when sortDirection == SortStrategyDirection.Descending:
                return(new SortCarsByPredicateDescStrategy <TCar, decimal>(c => c.Price));

            case BaseCarSortStrategyType.Year when sortDirection == SortStrategyDirection.Ascending:
                return(new SortCarsByPredicateStrategy <TCar, string>(c => c.Year));

            case BaseCarSortStrategyType.Year when sortDirection == SortStrategyDirection.Descending:
                return(new SortCarsByPredicateDescStrategy <TCar, string>(c => c.Year));

            case BaseCarSortStrategyType.Warranty when sortDirection == SortStrategyDirection.Ascending:
                return(new SortCarsByPredicateStrategy <TCar, int>(c => c.WarrantyMonthsLeft));

            case BaseCarSortStrategyType.Warranty when sortDirection == SortStrategyDirection.Descending:
                return(new SortCarsByPredicateDescStrategy <TCar, int>(c => c.WarrantyMonthsLeft));

            default:
                throw new InvalidEnumArgumentException();
            }
        }
Exemple #2
0
        public IActionResult ChangeSortType(BaseCarSortStrategyType sortStrategyType, string returnUrl)
        {
            var sortTypeKey = WebConstants.CookieUserSearchCarsSortTypeKey;

            this.cookiesService.SetCookieValue(this.HttpContext.Response.Cookies, sortTypeKey, sortStrategyType.ToString());

            return(Redirect(returnUrl));
        }