public static IOptionSortStrategy GetStrategy(
            OptionSortStrategyType sortStrategyType,
            SortStrategyDirection sortDirection)
        {
            switch (sortStrategyType)
            {
            case OptionSortStrategyType.Cars when sortDirection == SortStrategyDirection.Ascending:
                return(new SortOptionsByPredicateStrategy <int>(o => o.CarsOptions.Count));

            case OptionSortStrategyType.Cars when sortDirection == SortStrategyDirection.Descending:
                return(new SortOptionsByPredicateDescStrategy <int>(o => o.CarsOptions.Count));

            case OptionSortStrategyType.Name when sortDirection == SortStrategyDirection.Ascending:
                return(new SortOptionsByPredicateStrategy <string>(o => o.Name));

            case OptionSortStrategyType.Name when sortDirection == SortStrategyDirection.Descending:
                return(new SortOptionsByPredicateDescStrategy <string>(o => o.Name));

            case OptionSortStrategyType.OptionType when sortDirection == SortStrategyDirection.Ascending:
                return(new SortOptionsByPredicateStrategy <string>(o => o.OptionType.Name));

            case OptionSortStrategyType.OptionType when sortDirection == SortStrategyDirection.Descending:
                return(new SortOptionsByPredicateDescStrategy <string>(o => o.OptionType.Name));

            case OptionSortStrategyType.Price when sortDirection == SortStrategyDirection.Ascending:
                return(new SortOptionsByPredicateStrategy <decimal>(o => o.Price));

            case OptionSortStrategyType.Price when sortDirection == SortStrategyDirection.Descending:
                return(new SortOptionsByPredicateDescStrategy <decimal>(o => o.Price));

            default:
                throw new InvalidEnumArgumentException();
            }
        }
示例#2
0
        public static IEngineSortStrategy GetStrategy(
            EngineSortStrategy sortStrategyType,
            SortStrategyDirection sortDirection)
        {
            switch (sortStrategyType)
            {
            case EngineSortStrategy.Name when sortDirection == SortStrategyDirection.Ascending:
                return(new SortEnginesStrategy <string>(e => e.Name));

            case EngineSortStrategy.Name when sortDirection == SortStrategyDirection.Descending:
                return(new SortEnginesDescStrategy <string>(e => e.Name));

            case EngineSortStrategy.Price when sortDirection == SortStrategyDirection.Ascending:
                return(new SortEnginesStrategy <decimal>(e => e.Price));

            case EngineSortStrategy.Price when sortDirection == SortStrategyDirection.Descending:
                return(new SortEnginesDescStrategy <decimal>(e => e.Price));

            case EngineSortStrategy.Weight when sortDirection == SortStrategyDirection.Ascending:
                return(new SortEnginesStrategy <int>(e => e.Weight_Kg));

            case EngineSortStrategy.Weight when sortDirection == SortStrategyDirection.Descending:
                return(new SortEnginesDescStrategy <int>(e => e.Weight_Kg));

            case EngineSortStrategy.Cars when sortDirection == SortStrategyDirection.Ascending:
                return(new SortEnginesStrategy <int>(e => e.Cars.Count));

            case EngineSortStrategy.Cars when sortDirection == SortStrategyDirection.Descending:
                return(new SortEnginesDescStrategy <int>(e => e.Cars.Count));

            default:
                throw new InvalidEnumArgumentException();
            }
        }
        public static ICarSortStrategy<TCar> GetStrategy<TCar>(
            UsedCarSortStrategyType sortType, 
            SortStrategyDirection sortDirection) where TCar : UsedCar
        {
            switch (sortType)
            {
                case UsedCarSortStrategyType.Price when sortDirection == SortStrategyDirection.Ascending:
                    return new SortCarsByPredicateStrategy<TCar, decimal>(c => c.Price);
                case UsedCarSortStrategyType.Price when sortDirection == SortStrategyDirection.Descending:
                    return new SortCarsByPredicateDescStrategy<TCar, decimal>(c => c.Price);

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

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

                case UsedCarSortStrategyType.Mileage when sortDirection == SortStrategyDirection.Ascending:
                    return new SortCarsByPredicateStrategy<TCar, double>(c => c.Mileage);
                case UsedCarSortStrategyType.Mileage when sortDirection == SortStrategyDirection.Descending:
                    return new SortCarsByPredicateDescStrategy<TCar, double>(c => c.Mileage);

                default:
                    throw new InvalidEnumArgumentException();
            }
        }
示例#4
0
        public IActionResult ChangeSortDirection(SortStrategyDirection sortDirection)
        {
            var sortDirectionKey = WebConstants.CookieAdminOptionsSortDirectionKey;

            this.cookiesService.SetCookieValue(this.HttpContext.Response.Cookies, sortDirectionKey, sortDirection.ToString());

            return(RedirectToAction("Index"));
        }
        public IActionResult ChangeSortDirection(SortStrategyDirection sortDirection, string returnUrl)
        {
            var sortDirectionKey = WebConstants.CookieUserUsedCarsSortDirectionKey;

            this.cookiesService.SetCookieValue(this.HttpContext.Response.Cookies, sortDirectionKey, sortDirection.ToString());

            return(Redirect(returnUrl));
        }
示例#6
0
        public static ITestDriveSortStrategy GetStrategy(
            AdminTestDrivesSortStrategyType sortStrategyType,
            SortStrategyDirection sortDirection)
        {
            switch (sortStrategyType)
            {
            case AdminTestDrivesSortStrategyType.Status when sortDirection == SortStrategyDirection.Ascending:
                return(new SortTestDrivesByStatusStrategy());

            case AdminTestDrivesSortStrategyType.Status when sortDirection == SortStrategyDirection.Descending:
                return(new SortTestDrivesByStatusDescStrategy());

            case AdminTestDrivesSortStrategyType.Price when sortDirection == SortStrategyDirection.Ascending:
                return(new SortTestDrivesByPredicateStrategy <DateTime>(td => td.ScheduleDate));

            case AdminTestDrivesSortStrategyType.Price when sortDirection == SortStrategyDirection.Descending:
                return(new SortTestDrivesByPredicateDescStrategy <DateTime>(td => td.ScheduleDate));

            case AdminTestDrivesSortStrategyType.Email when sortDirection == SortStrategyDirection.Ascending:
                return(new SortTestDrivesByPredicateStrategy <string>(td => td.User.Email));

            case AdminTestDrivesSortStrategyType.Email when sortDirection == SortStrategyDirection.Descending:
                return(new SortTestDrivesByPredicateDescStrategy <string>(td => td.User.Email));

            case AdminTestDrivesSortStrategyType.PassedCount when sortDirection == SortStrategyDirection.Ascending:
                return(new SortTestDrivesByPassedCountStrategy());

            case AdminTestDrivesSortStrategyType.PassedCount when sortDirection == SortStrategyDirection.Descending:
                return(new SortTestDrivesByPassedCountDescStrategy());

            case AdminTestDrivesSortStrategyType.Date when sortDirection == SortStrategyDirection.Ascending:
                return(new SortTestDrivesByPredicateStrategy <decimal>(td => td.Car.Price));

            case AdminTestDrivesSortStrategyType.Date when sortDirection == SortStrategyDirection.Descending:
                return(new SortTestDrivesByPredicateDescStrategy <decimal>(td => td.Car.Price));

            default:
                throw new InvalidEnumArgumentException();
            }
        }
示例#7
0
        public static ICarSortStrategy <TCar> GetStrategy <TCar>(
            AdminBaseCarSortStrategyType sortType,
            SortStrategyDirection sortDirection) where TCar : BaseCar
        {
            switch (sortType)
            {
            case AdminBaseCarSortStrategyType.Condition when sortDirection == SortStrategyDirection.Ascending:
                return(new SortCarsByPredicateStrategy <TCar, int>(c => c is NewCar ? 0 : 1));

            case AdminBaseCarSortStrategyType.Condition when sortDirection == SortStrategyDirection.Descending:
                return(new SortCarsByPredicateDescStrategy <TCar, int>(c => c is NewCar ? 0 : 1));

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

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

            case AdminBaseCarSortStrategyType.Price when sortDirection == SortStrategyDirection.Ascending:
                return(new SortCarsByPredicateStrategy <TCar, decimal>(c => c.Price));

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

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

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

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

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

            default:
                throw new InvalidEnumArgumentException();
            }
        }
        public static IUserSortStrategy GetStrategy(UserSortStrategyType sortStrategy, SortStrategyDirection sortDirection)
        {
            switch (sortStrategy)
            {
            case UserSortStrategyType.Name when sortDirection == SortStrategyDirection.Ascending:
                return(new SortUsersByNamesStrategy());

            case UserSortStrategyType.Name when sortDirection == SortStrategyDirection.Descending:
                return(new SortUsersByNamesDescStrategy());

            case UserSortStrategyType.Orders when sortDirection == SortStrategyDirection.Ascending:
                return(new SortUsersByTestDrivesCountStrategy());

            case UserSortStrategyType.Orders when sortDirection == SortStrategyDirection.Descending:
                return(new SortUsersByTestDrivesCountDescStrategy());

            case UserSortStrategyType.LockoutStatus when sortDirection == SortStrategyDirection.Ascending:
                return(new SortUsersByLockoutStatusStrategy());

            case UserSortStrategyType.LockoutStatus when sortDirection == SortStrategyDirection.Descending:
                return(new SortUsersByLockoutStatusDescStrategy());

            case UserSortStrategyType.Email when sortDirection == SortStrategyDirection.Ascending:
                return(new SortUsersByEmailStrategy());

            case UserSortStrategyType.Email when sortDirection == SortStrategyDirection.Descending:
                return(new SortUsersByEmailDescStrategy());

            default:
                throw new InvalidEnumArgumentException();
            }
        }