Esempio n. 1
0
        // GET: Search
        public async Task <IActionResult> Search(
            int?noOfSearchValues, int gameSelection, int groupSelection,
            int referenceValue, int referenceLocation, int?referencePos,
            int?value2, int val2WeekSelect, int val2Location, int value2Week, int?value2Pos,
            int?value3, int val3WeekSelect, int val3Location, int value3Week, int?value3Pos,
            int?pageNumber, int noOfWeeksToDisplay = 2)
        {
            // Games Name List
            List <Game> gamesList = new List <Game>();

            gamesList = (from games in _context.Games select games).ToList(); //collect data from game context into list
            gamesList.Insert(0, new Game {
                ID = 0, Name = "Select Groups"
            });                                                               // add select option to list

            List <GamesClass> gamesGroups = new List <GamesClass>();

            gamesGroups = (from gamesClass in _context.GamesClass select gamesClass).ToList();
            gamesGroups.Insert(0, new GamesClass {
                ID = 0, Name = "Select All"
            });

            ViewBag.ListOfGames  = gamesList;
            ViewBag.ListOfGroups = gamesGroups;

            // Search Results Data
            ViewBag.SearchParmAmt       = noOfSearchValues;
            ViewBag.DisplayWeeksParmAmt = noOfWeeksToDisplay;
            ViewBag.GameSelection       = gameSelection;
            ViewBag.GroupSelection      = groupSelection;
            ViewBag.DisplaySpaceParm    = (noOfWeeksToDisplay * 2) + 1;
            int sizePerPage = ((noOfWeeksToDisplay * 2) + 1) * 10;

            // Reference Value
            ViewBag.ReferenceValue    = referenceValue;
            ViewBag.ReferenceLocation = referenceLocation; //
            ViewBag.ReferencePos      = referencePos;

            // 2nd Search Value
            ViewBag.Value2         = value2;
            ViewBag.Val2WeekSelect = val2WeekSelect; //
            ViewBag.Val2Location   = val2Location;   //
            ViewBag.Value2Week     = value2Week;
            ViewBag.Value2Pos      = value2Pos;
            ViewBag.Value2WeekAbs  = value2Week >= 0 ? value2Week : ((noOfWeeksToDisplay * 3) + 1 + value2Week);

            // 3rd Search Value
            ViewBag.Value3         = value3;
            ViewBag.Val3WeekSelect = val3WeekSelect;
            ViewBag.Val3Location   = val3Location;
            ViewBag.Value3Week     = value3Week;
            ViewBag.Value3Pos      = value3Pos;
            ViewBag.Value3WeekAbs  = value3Week >= 0 ? value3Week : ((noOfWeeksToDisplay * 3) + 1 + value3Week);

            if (noOfSearchValues == null)
            {
                return(View());
            }


            referencePos = referencePos == 0 ? null : referencePos;
            value2Pos    = value2Pos == 0 ? null : value2Pos;
            value3Pos    = value3Pos == 0 ? null : value3Pos;

            //var events = from s in _context.Events select s;
            int[] groupGamesToSearchFrom = (gameSelection == 0) ? (from games in _context.Games.Where(s => s.GamesClassID == groupSelection) select games.ID).ToArray() : null;

            var events = (gameSelection > 0 && gameSelection < gamesList.Count) ? from s in _context.Events.Where(s => s.GameID == gameSelection) select s : ((groupGamesToSearchFrom == null) ? from s in _context.Events select s : from s in _context.Events.Where(s => groupGamesToSearchFrom.Contains(s.GameID)) select s);

            List <Event> selectedEvents = new List <Event>();

            List <AdvancedSearchResult> results = new List <AdvancedSearchResult>();

            switch (noOfSearchValues)
            {
            case 1:
                results = await Task.Run(() => AdvSearch.FindResults(_context, noOfWeeksToDisplay, referenceValue, referenceLocation, referencePos, gameSelection, groupGamesToSearchFrom).ToList());

                selectedEvents = AdvancedSearch.FindAsync(events, noOfWeeksToDisplay, referenceValue, referenceLocation, referencePos).ToList();
                break;

            case 2:
                results = await Task.Run(() => AdvSearch.FindResults(_context, noOfWeeksToDisplay, referenceValue, referenceLocation, referencePos, gameSelection, groupGamesToSearchFrom, (int)value2, val2WeekSelect, value2Week, val2Location, value2Pos).ToList());

                if (val2WeekSelect == 2)
                {
                    for (int i = -2; i <= 2; i++)
                    {
                        if (i != 0)
                        {
                            selectedEvents.AddRange(AdvancedSearch.FindAsync(events, noOfWeeksToDisplay, referenceValue, referenceLocation, referencePos, (int)value2, i, val2Location, value2Pos).ToList());
                        }
                    }
                }
                else
                {
                    selectedEvents = AdvancedSearch.FindAsync(events, noOfWeeksToDisplay, referenceValue, referenceLocation, referencePos, (int)value2, value2Week, val2Location, value2Pos).ToList();
                }
                break;

            case 3:
                results = await Task.Run(() => AdvSearch.FindResults(_context, noOfWeeksToDisplay, referenceValue, referenceLocation, referencePos, gameSelection, groupGamesToSearchFrom, (int)value2, val2WeekSelect, value2Week, val2Location, value2Pos, (int)value3, val3WeekSelect, value3Week, val3Location, value3Pos).ToList());

                selectedEvents = AdvancedSearch.FindAsync(events, noOfWeeksToDisplay, referenceValue, referenceLocation, referencePos, (int)value2, value2Week, val2Location, value2Pos, (int)value3, value3Week, val3Location, value3Pos).ToList();
                break;

            default:
                return(View());
            }
            return(View(await Task.Run(() => PaginatedList <Event> .Create(selectedEvents.AsQueryable(), pageNumber ?? 1, sizePerPage, gamesList, gamesGroups, gameSelection, groupSelection))));
        }
Esempio n. 2
0
        // GET: Advanced Search
        public async Task <IActionResult> Search(SearchParameters searchParameters)
        {
            searchParameters.GamesList = (from games in _context.Games select games).ToList();
            searchParameters.GamesList.Insert(0, new Game {
                ID = 0, Name = "Select Groups"
            });
            searchParameters.GamesGroups = (from groups in _context.GamesClass select groups).ToList();
            searchParameters.GamesGroups.Insert(0, new GamesClass {
                ID = 0, Name = "Select All"
            });

            SearchResultViewModel searchResults = new SearchResultViewModel()
            {
                SearchParameters = searchParameters
            };

            if (searchParameters.NoOfSearchValues == null)
            {
                return(await Task.Run(() => View(searchResults)));
            }

            List <AdvancedSearchResult> results = new List <AdvancedSearchResult>();

            int[] groupGamesToSearchFrom = (searchParameters.GameSelection == 0) ? (from games in _context.Games.Where(s => s.GamesClassID == searchParameters.GroupSelection) select games.ID).ToArray() : null;

            switch (searchParameters.NoOfSearchValues)
            {
            case 1:
                results = await Task.Run(() => AdvSearch.FindResults(_context,
                                                                     searchParameters.NoOfWeeksToDisplay,
                                                                     (int)searchParameters.ReferenceValue,
                                                                     searchParameters.ReferenceLocation,
                                                                     searchParameters.ReferencePosition,
                                                                     searchParameters.GameSelection,
                                                                     groupGamesToSearchFrom).ToList());

                break;

            case 2:
                results = await Task.Run(() => AdvSearch.FindResults(_context,
                                                                     searchParameters.NoOfWeeksToDisplay,
                                                                     (int)searchParameters.ReferenceValue,
                                                                     searchParameters.ReferenceLocation,
                                                                     searchParameters.ReferencePosition,
                                                                     searchParameters.GameSelection,
                                                                     groupGamesToSearchFrom,
                                                                     (int)searchParameters.Value2,
                                                                     searchParameters.Value2WeekSelect,
                                                                     searchParameters.Value2Week,
                                                                     searchParameters.Value2Location,
                                                                     searchParameters.Value2Position).ToList());

                break;

            case 3:
                results = await Task.Run(() => AdvSearch.FindResults(_context,
                                                                     searchParameters.NoOfWeeksToDisplay,
                                                                     (int)searchParameters.ReferenceValue,
                                                                     searchParameters.ReferenceLocation,
                                                                     searchParameters.ReferencePosition,
                                                                     searchParameters.GameSelection,
                                                                     groupGamesToSearchFrom,
                                                                     (int)searchParameters.Value2,
                                                                     searchParameters.Value2WeekSelect,
                                                                     searchParameters.Value2Week,
                                                                     searchParameters.Value2Location,
                                                                     searchParameters.Value2Position,
                                                                     (int)searchParameters.Value3,
                                                                     searchParameters.Value3WeekSelect,
                                                                     searchParameters.Value3Week,
                                                                     searchParameters.Value3Location,
                                                                     searchParameters.Value3Position).ToList());

                break;

            default:
                results = null;
                break;
            }

            searchResults.SearchResults = results;

            return(await Task.Run(() => View(searchResults)));
        }