// GET: /DevelopmentTool/GroupByCompany
        public ActionResult GroupByCompany(DevToolSearchCriteria searchCriteria)
        {
            var collection = _db.DevelopmentTools;
            IQueryable <DevelopmentTool> query = collection;

            if (searchCriteria == null)
            {
                return(View(new DevelopmentToolsModel()));
            }
            query = GetByFiltersDevelopmentTools(searchCriteria, query);

            DevelopmentToolsModel developmentToolsModel = new DevelopmentToolsModel()
            {
                ShowGroupedBy = true,
                AvailableSourceCodeLicenses = Enum.GetNames(typeof(SourceCodeLicense)),
                AvailableCompanyNames       = _db.DevelopmentTools.Select(x => x.Company.Name).Distinct().ToList(),
                CompanyNameFilter           = searchCriteria.CompanyName,
                SourceCodeLicenseFilter     = searchCriteria.SourceCodeLicenses,
                PriceFilter = searchCriteria.PriceRange,
                DevTools    = query.ToList(),
                DevToolsGroupedByCompany = GetDevToolsGroupedByCompany(query)
            };

            return(View(developmentToolsModel));
        }
        private static IQueryable <DevelopmentTool> FilterDevToolsByPriceRange(DevToolSearchCriteria searchCriteria, IQueryable <DevelopmentTool> collection)
        {
            switch (searchCriteria.PriceRange)
            {
            case PriceRange.ZeroToHundred:
                return(collection.Where(x => x.Price >= 0 && x.Price < 100));

            case PriceRange.HundredToThousand:
                return(collection.Where(x => x.Price >= 100 && x.Price < 1000));

            case PriceRange.ThousandToTenThousand:
                return(collection.Where(x => x.Price >= 1000 && x.Price < 10000));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 private static IQueryable <DevelopmentTool> GetByFiltersDevelopmentTools(DevToolSearchCriteria searchCriteria, IQueryable <DevelopmentTool> query)
 {
     if (!string.IsNullOrWhiteSpace(searchCriteria.SourceCodeLicenses))
     {
         var sourceCodeLicenses =
             (SourceCodeLicense)Enum.Parse(typeof(SourceCodeLicense), searchCriteria.SourceCodeLicenses);
         query = query.Where(x => x.SourceCodeLicense == sourceCodeLicenses);
     }
     if (!string.IsNullOrWhiteSpace(searchCriteria.CompanyName))
     {
         query = query.Where(x => x.Company.Name == searchCriteria.CompanyName);
     }
     if (searchCriteria.PriceRange != PriceRange.None)
     {
         query = FilterDevToolsByPriceRange(searchCriteria, query);
     }
     return(query);
 }