Exemplo n.º 1
0
        public ActionResult Index(string category, PageSizeFilter pageSizeFilter, SortFilter sortFilter,
                                  ProducersFilter producerFilter, PageFilter pageFilter,
                                  [ModelBinder(typeof(GroupFilterBinder))] GroupFilter groupFilter)
        {
            try
            {
                var url = ProducerRedirect.GetUrl(Request.Url, category, producerFilter);
                if (url != string.Empty)
                {
                    return(RedirectPermanent(url));
                }

                ViewModel = new FilterViewModelBase(category, pageSizeFilter, sortFilter, producerFilter, pageFilter,
                                                    groupFilter);

                var categoryObj = categoryRepository.Find(category);
                if (categoryObj == null)
                {
                    throw new Exception("Invalid category name.");
                }

                ViewModel.CategoryObj = categoryObj;
                IQueryable <Product> entities = productRepository.GetProductsWithProducerByProductName(category);
                entities = StartInitialize(entities);
                EndInitialize(entities);

                return(View(ViewModel));
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(RedirectToAction("index", "error", new { statusCode = 404 }));
            }
        }
Exemplo n.º 2
0
 public FilterViewModelBase(string category, PageSizeFilter pageSizeFilter, SortFilter sortFilter, ProducersFilter producersFilter, PageFilter pageFilter, GroupFilter groupFilter)
     : this(pageSizeFilter, sortFilter, pageFilter)
 {
     this.ProducersFilter = producersFilter;
     this.GroupsFilter    = groupFilter;
     this.Filters.Add(producersFilter);
     this.Filters.Add(groupFilter);
     this.Category = category;
 }
Exemplo n.º 3
0
        private SortFilter GetSortFilter(SortFilter def, SortFilter inp)
        {
            SortFilter sf = new SortFilter();

            sf.Sort   = (inp.Sort == null) ? def.Sort   : inp.Sort;
            sf.Filter = (inp.Filter == null) ? def.Filter : inp.Filter;
            sf.Page   = (!inp.Page.HasValue) ? def.Page   : inp.Page;

            return(sf);
        }
Exemplo n.º 4
0
        public IEnumerable <GameOutput> GetFiltered(GameFilterInput filters, int takeCount, int skipCount)
        {
            var gameFilterChain = new GameFilterChain();

            RegisterFilters(gameFilterChain, filters);
            var sortFilter    = new SortFilter(filters.SortType);
            var sortPredicate = sortFilter.Execute(x => x);
            var predicate     = gameFilterChain.Execute(x => !x.IsDeleted);

            return(Mapper.Map <List <GameOutput> >(_unitOfWork.GetGamesFromAllDbs().GetSorted(sortPredicate, predicate).Skip(skipCount).Take(takeCount)));
        }
Exemplo n.º 5
0
        public ActionResult Index(PageFilter pageFilter, SortFilter sortFilter, PageSizeFilter pageSizeFilter,
                                  SearchFilter searchFilter)
        {
            var seperators = new[] { " ", "-" };

            string[] tokens = searchFilter.Keyword.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
            ViewModel  = new FilterViewModelBase(pageSizeFilter, sortFilter, pageFilter, searchFilter);
            expression = obj => tokens.All(t => obj.DisplayName.Contains(t));
            IEnumerable <Product> products = productRepository.GetProductWithProducersByExpression(expression);

            StartInitializeCommon(products.Count());
            EndInitializeCommon(products);
            return(View(ViewModel));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Получить отсортированный список
        /// </summary>
        /// <param name="sortFilter"></param>
        /// <returns></returns>
        public IEnumerable <Book> SortByFilter(SortFilter sortFilter)
        {
            IEnumerable <Book> result = _dbSet.Books;

            if (sortFilter.SortByHead)
            {
                result = _dbSet.Books.OrderBy(b => b.Head);
            }
            else if (sortFilter.SortByYear)
            {
                result = _dbSet.Books.OrderBy(b => b.PublishYear);
            }
            return(result);
        }
Exemplo n.º 7
0
        public void It_Should_Sort_Dictionaries_By_Field()
        {
            // Arrange
            SortFilter sizeFilter = new SortFilter(LiquidString.Create("field1"));

            // Act
            var result = sizeFilter.Apply(new TemplateContext(), CreateObjList());

            // Assert
            Assert.That(IdAt(result.SuccessValue <LiquidCollection>(), 0, "field1").Value, Is.EqualTo("Aa"));
            Assert.That(IdAt(result.SuccessValue <LiquidCollection>(), 1, "field1").Value, Is.EqualTo("ab"));
            Assert.That(IdAt(result.SuccessValue <LiquidCollection>(), 2, "field1").Value, Is.EqualTo("b"));
            Assert.That(IdAt(result.SuccessValue <LiquidCollection>(), 3, "field1").Value, Is.EqualTo("Z"));
        }
 public CustomerRepository()
 {
     //this is the unique id for the model to which this repository belongs to. used to find the correct connection string
     ModelId = RepoLookup.ModelId.MainDb;
     //this is the unique id for the entity. used to retrieve EntityInfo object from the RepoLookup.EntityId
     EntityId = RepoLookup.EntityId.MainDb_People_Customer;
     //tables with triggers have limitations that need to be accounted for
     HasTriggers = false;
     #region Default Sorting
     //this is the PK (PK__Customer__A4AE64D8164452B1) sorting. used as default for method overloads that DO NOT take a SortFilters parameter
     DefaultSort = new SortFilters <CustomerProperty>(1)
     {
         SortFilter.New(CustomerProperty.CustomerId),
     };
     #endregion
 }
Exemplo n.º 9
0
 public TrackRepository()
 {
     //this is the unique id for the model to which this repository belongs to. used to find the correct connection string
     ModelId = RepoLookup.ModelId.MainDb;
     //this is the unique id for the entity. used to retrieve EntityInfo object from the RepoLookup.EntityId
     EntityId = RepoLookup.EntityId.MainDb_Media_Track;
     //tables with triggers have limitations that need to be accounted for
     HasTriggers = false;
     #region Default Sorting
     //this is the PK (PK__Track__7A74F8E00EA330E9) sorting. used as default for method overloads that DO NOT take a SortFilters parameter
     DefaultSort = new SortFilters <TrackProperty>(1)
     {
         SortFilter.New(TrackProperty.TrackId),
     };
     #endregion
 }
Exemplo n.º 10
0
 public ColorRepository()
 {
     //this is the unique id for the model to which this repository belongs to. used to find the correct connection string
     ModelId = RepoLookup.ModelId.WorldWideImporters;
     //this is the unique id for the entity. used to retrieve EntityInfo object from the RepoLookup.EntityId
     EntityId = RepoLookup.EntityId.WorldWideImporters_Warehouse_Color;
     //tables with triggers have limitations that need to be accounted for
     HasTriggers = false;
     #region Default Sorting
     //this is the PK (PK_Warehouse_Colors) sorting. used as default for method overloads that DO NOT take a SortFilters parameter
     DefaultSort = new SortFilters <ColorProperty>(1)
     {
         SortFilter.New(ColorProperty.ColorID),
     };
     #endregion
 }
Exemplo n.º 11
0
 public InvoiceRepository()
 {
     //this is the unique id for the model to which this repository belongs to. used to find the correct connection string
     ModelId = RepoLookup.ModelId.MainDb;
     //this is the unique id for the entity. used to retrieve EntityInfo object from the RepoLookup.EntityId
     EntityId = RepoLookup.EntityId.MainDb_Accounting_Invoice;
     //tables with triggers have limitations that need to be accounted for
     HasTriggers = false;
     #region Default Sorting
     //this is the PK (PK__Invoice__D796AAB51A14E395) sorting. used as default for method overloads that DO NOT take a SortFilters parameter
     DefaultSort = new SortFilters <InvoiceProperty>(1)
     {
         SortFilter.New(InvoiceProperty.InvoiceId),
     };
     #endregion
 }
 public EmployeeRepository()
 {
     //this is the unique id for the model to which this repository belongs to. used to find the correct connection string
     ModelId = RepoLookup.ModelId.MainDb;
     //this is the unique id for the entity. used to retrieve EntityInfo object from the RepoLookup.EntityId
     EntityId = RepoLookup.EntityId.MainDb_People_Employee;
     //tables with triggers have limitations that need to be accounted for
     HasTriggers = false;
     #region Default Sorting
     //this is the PK (PK__Employee__7AD04F111273C1CD) sorting. used as default for method overloads that DO NOT take a SortFilters parameter
     DefaultSort = new SortFilters <EmployeeProperty>(1)
     {
         SortFilter.New(EmployeeProperty.EmployeeId),
     };
     #endregion
 }
Exemplo n.º 13
0
        /// <summary>
        ///     Returns localized name of the filter
        /// </summary>
        /// <param name="filter">Filter for which localized name should be returned</param>
        /// <returns>Localized name of the filter</returns>
        public static string LocalizedName(this SortFilter filter)
        {
            switch (filter)
            {
            case SortFilter.Name:
                return("Název");

            case SortFilter.Date:
                return("Datum");

            case SortFilter.Distance:
                return("Vzdálenost");

            default:
                return("Neznámé");
            }
        }
Exemplo n.º 14
0
        internal static SortFilter FromRequest <T>(GridRequest request, string defaultSortFieldName)
        {
            if (!(defaultSortFieldName.ToLower().EndsWith(" asc") || defaultSortFieldName.ToLower().EndsWith(" desc")))
            {
                defaultSortFieldName += " asc";
            }

            SortFilter sortFilter = new SortFilter
            {
                Sort = (request.Sort != null && request.Sort.Any())
                    ? DataSortFromGrid.GetOrderClause(request.Sort)
                    : $"{defaultSortFieldName}",
                Filter = DataFilterFromGrid.GetWhereClause <T>(request.Filter)
            };

            return(sortFilter);
        }
Exemplo n.º 15
0
        public IActionResult OnPostFilter(int option)
        {
            switch (option)
            {
            //case 1:
            //    break;
            case 2:
                Predicate <SpeedMeasurement> predicateOver = (SpeedMeasurement s) => { return(s.Speed > s.Location.SpeedLimit); };
                FilterList = SortFilter.Comparer(FilterList, predicateOver);
                break;

            case 3:
                Predicate <SpeedMeasurement> predicateCut = s => { return(s.Speed > s.Location.SpeedLimit * 1.3); };
                FilterList = SortFilter.Comparer(FilterList, predicateCut);
                break;

            case 4:
                Predicate <SpeedMeasurement> predicateConditional = s =>
                {
                    if (s.Location.Zone == Zone.Motorvej)
                    {
                        return(s.Speed > s.Location.SpeedLimit * 1.3);
                    }
                    else
                    {
                        return(s.Speed > s.Location.SpeedLimit * 1.6);
                    }
                };
                FilterList = SortFilter.Comparer(FilterList, predicateConditional);
                break;

            case 5:
                Predicate <SpeedMeasurement> predicateUnconditional = s =>
                {
                    return(s.Speed > s.Location.SpeedLimit * 2 && s.Speed >= 100);
                };
                FilterList = SortFilter.Comparer(FilterList, predicateUnconditional);
                break;

            default:
                break;
            }
            return(Page());
        }
Exemplo n.º 16
0
        private FilterViewModelBase(PageSizeFilter pageSizeFilter, SortFilter sortFilter, PageFilter pageFilter)
        {
            this.PageSizeFilter = pageSizeFilter;
            this.SortFilter     = sortFilter;
            this.PageFilter     = pageFilter;

            this.Filters = new FilterList {
                pageSizeFilter, sortFilter, pageFilter
            };

            this.PageSize = new List <GenericFilterModelBase <int> >
            {
                new GenericFilterModelBase <int> {
                    Value = Constants.PageSizeDefault
                },
                new GenericFilterModelBase <int> {
                    Value = Constants.PageSizeSmall
                },
                new GenericFilterModelBase <int> {
                    Value = Constants.PageSizeBig
                }
            };

            this.Sort = new List <GenericFilterModelBase <int> >
            {
                new GenericFilterModelBase <int>
                {
                    Value = (int)(Core.Sort.PriceAsc),
                    Name  = Constants.PriceAsc
                },
                new GenericFilterModelBase <int>
                {
                    Value = (int)(Core.Sort.PriceDesc),
                    Name  = Constants.PriceDesc
                },
                new GenericFilterModelBase <int>
                {
                    Value = (int)(Core.Sort.RateDesc),
                    Name  = Constants.RateDesc
                }
            };
            this.Pagging = new PagingViewModel(this.Category);
        }
Exemplo n.º 17
0
        public IActionResult Index(string sortOrder, string currentFilter, int?pageNumber)
        {
            User user = CheckIdentity();

            if (user == null)
            {
                return(RedirectToAction("Error", "Home"));
            }
            Log.Me.Debug("Home/Index - User: "******", SortOrder: '" + sortOrder + "', CurrentFilter: '" + currentFilter + "', PageNumber: " + pageNumber.ToString());
            ApplicationVersion();

            // current is what's cached, or the defaults
            SortFilter def     = new SortFilter("creationdate desc", "uncommitted-" + user.UserId, 1);
            string     key     = "HomeIndex-" + user.UserId;
            SortFilter current = Cache <SortFilter> .GetCache().Get(key, () => def);

            // Inputs override previous or default values
            if (sortOrder != null)
            {
                current.Sort = sortOrder;
            }
            if (pageNumber.HasValue)
            {
                current.Page = pageNumber;
            }
            if (currentFilter != null && current.Filter != currentFilter)
            {
                current.Filter = currentFilter;
                current.Page   = 1;  // filter just got updated, so reset the page number
            }

            // Cache the current settings, so that we come back to the same page from Report/Edit
            Cache <SortFilter> .GetCache().Set(key, () => current);

            ViewData["CurrentSort"]   = current.Sort;
            ViewData["CurrentFilter"] = current.Filter;

            int pageSize = 25;

            return(View(PaginatedList <PendingReport> .Create(
                            _context.PendingReportRepo.List(current.Sort, current.Filter), current.Page ?? 1, pageSize)));
        }
Exemplo n.º 18
0
        public void It_Should_Sort_An_Array_By_StringValues()
        {
            // Arrange
            LiquidCollection liquidCollection = new LiquidCollection {
                LiquidString.Create("a string"),
                LiquidNumeric.Create(123),
                LiquidNumeric.Create(456m),
                new LiquidBoolean(false)
            };
            var filter = new SortFilter(LiquidString.Create(""));

            // Act
            var result        = filter.Apply(new TemplateContext(), liquidCollection);
            var resultStrings = result.SuccessValue <LiquidCollection>().Select(ValueCaster.RenderAsString);

            // Assert
            Assert.That(resultStrings, Is.EqualTo(new List <String> {
                "123", "456.0", "a string", "false"
            }));
        }
Exemplo n.º 19
0
        public void It_Should_Sort_An_Array_By_StringValues()
        {
            // Arrange
            IList<IExpressionConstant> objlist = new List<IExpressionConstant>
            {
                new StringValue("a string"), 
                NumericValue.Create(123), 
                NumericValue.Create(456m),
                new BooleanValue(false)
            };
            ArrayValue arrayValue = new ArrayValue(objlist);
            var filter = new SortFilter(new StringValue(""));

            // Act            
            var result = filter.Apply(new TemplateContext(), arrayValue);
            var resultStrings = result.SuccessValue<ArrayValue>().Select(ValueCaster.RenderAsString);
            
            // Assert
            Assert.That(resultStrings, Is.EqualTo(new List<String>{"123", "456.0", "a string", "false"}));

        }
Exemplo n.º 20
0
        public IActionResult OnPostSort(int option, string option2)
        {
            if (option2?.Length > 0)
            {
                Predicate <Location> predicateLocation = (Location loc) => { return(loc.Address.Contains(option2)); };
                SortableLocationList = SortFilter.Comparer(SortableLocationList, predicateLocation);
            }

            if (option == 1)
            {
                SortableLocationList.Sort();
            }
            else if (option == 2)
            {
                SortableLocationList.Sort(new LocationSortByZone());
            }
            else if (option == 3)
            {
                SortableLocationList.Sort(new LocationSortBySpeed());
            }

            return(Page());
        }
Exemplo n.º 21
0
        public void It_Should_Sort_Dictionaries_By_Field()
        {
            // Arrange
            IList<IExpressionConstant> objlist = new List<IExpressionConstant>
            {
                DataFixtures.CreateDictionary(1, "Aa", "Value 1 B"), 
                DataFixtures.CreateDictionary(2, "Z", "Value 2 B"), 
                DataFixtures.CreateDictionary(3, "ab", "Value 3 B"), 
                DataFixtures.CreateDictionary(4, "b", "Value 4 B"),
            };
            ArrayValue arrayValue = new ArrayValue(objlist);
            SortFilter sizeFilter = new SortFilter(new StringValue("field1"));

            // Act
            var result = sizeFilter.Apply(new TemplateContext(), arrayValue);

            // Assert
            Assert.That(IdAt(result.SuccessValue<ArrayValue>(), 0, "field1").Value, Is.EqualTo("Aa"));
            Assert.That(IdAt(result.SuccessValue<ArrayValue>(), 1, "field1").Value, Is.EqualTo("ab"));
            Assert.That(IdAt(result.SuccessValue<ArrayValue>(), 2, "field1").Value, Is.EqualTo("b"));
            Assert.That(IdAt(result.SuccessValue<ArrayValue>(), 3, "field1").Value, Is.EqualTo("Z"));

        }
Exemplo n.º 22
0
 private void OnSortFilterChanged(SortFilter filter)
 {
     SharedModel.ResetAgentProducts();
     SharedModel.ResetItemSubTypeProducts();
 }
 public SortFilterCellInfo(SortFilter filter, string text, string subtext = null, Sprite icon = null) : base(text, subtext, icon)
 {
     SortFilter = filter;
 }
Exemplo n.º 24
0
 public IEnumerable <Book> SortBookByFilter(SortFilter sortFilter)
 {
     return(_bookRepository.SortByFilter(sortFilter));
 }
Exemplo n.º 25
0
 public IActionResult GetBooks([FromQuery] SortFilter sortFilter)
 {
     return(new JsonResult(_bookService.SortBookByFilter(sortFilter)));
 }
Exemplo n.º 26
0
 public FilterViewModelBase(PageSizeFilter pageSizeFilter, SortFilter sortFilter, PageFilter pageFilter, SearchFilter searchFilter)
     : this(pageSizeFilter, sortFilter, pageFilter)
 {
     this.SearchFilter = searchFilter;
     this.Filters.Add(searchFilter);
 }