Beispiel #1
0
        public async Task <IActionResult> SearchResults(string query)
        {
            // Redirect to Jump Routes if the query syntax matches
            if (!String.IsNullOrWhiteSpace(query))
            {
                Regex        rgx        = new Regex(@"(.*) > (.*)");
                List <Match> rgxMatches = rgx.Matches(query).ToList();
                if (rgxMatches != null && rgxMatches.Count > 0 && rgxMatches[0].Groups.Count == 3)
                {
                    string fromQuery = rgxMatches[0].Groups[1].Value;
                    string toQuery   = rgxMatches[0].Groups[2].Value;
                    return(RedirectToAction("JumpRoutes", "Universe", new { fromQuery = fromQuery, toQuery = toQuery }));
                }
            }

            int count = -1; // -1 at the end implies that the query was not provided
            List <Region_V_Row>        regions        = new List <Region_V_Row>();
            List <Constellation_V_Row> constellations = new List <Constellation_V_Row>();
            List <SolarSystem_V_Row>   solarSystems   = new List <SolarSystem_V_Row>();
            List <Station_V_Row>       stations       = new List <Station_V_Row>();
            List <ItemType_V_Row>      itemTypes      = new List <ItemType_V_Row>();
            List <CharacterDataModel>  characters     = new List <CharacterDataModel>();

            if (!String.IsNullOrWhiteSpace(query))
            {
                // Attempt to parse as int to check for specific id searches that are not broad
                int id = 0;
                Int32.TryParse(query, out id);
                if (id > 0)
                {
                    try
                    {
                        Character_Row character = _DBService.GetCharacterPublicInfo(id); //var characterApi = await _ESIClient.Character.GetCharacterPublicInfoV4Async(id);
                        characters.Add(new CharacterDataModel()
                        {
                            Id        = id,
                            Character = character
                        });
                    }
                    catch (Exception e)
                    {
                        // Do nothing. Character isn't valid
                    }

                    regions = new List <Region_V_Row>()
                    {
                        _DBService.GetRegion(id)
                    };
                    constellations = new List <Constellation_V_Row>()
                    {
                        _DBService.GetConstellation(id)
                    };
                    solarSystems = new List <SolarSystem_V_Row>()
                    {
                        _DBService.GetSolarSystem(id)
                    };
                    stations = new List <Station_V_Row>()
                    {
                        _DBService.GetStation(id)
                    };
                }
                else // For services that do not support id search
                {
                    // Search Universe
                    regions        = _DBService.SearchRegions(query);
                    constellations = _DBService.SearchConstellations(query);
                    solarSystems   = _DBService.SearchSolarSystems(query);
                    stations       = _DBService.SearchStations(query);
                    // Search Item Types
                    itemTypes = _DBService.SearchItemTypes(query);
                    // Search API
                    try
                    {
                        AuthDTO auth = GetAuth(_ESIClient);
                        _Log.LogDebug(String.Format("Logged in to retrieve Character Info for Character Id: {0}", auth.CharacterId));

                        // TODO: Support all available search categories (agent, alliance, character, constellation, corporation, faction, inventory_type, region, solar_system, station, structure)
                        //https://esi.evetech.net/ui#/Search/get_characters_character_id_search

                        var searchApi = await _ESIClient.Search.SearchCharacterV3Async(auth, new List <string>() { "character" }, query);

                        var searchApiModel = searchApi.Model;

                        // Process Characters
                        List <int> characterIds = searchApiModel.Character;
                        for (int x = 0; x < characterIds.Count; x++)
                        {
                            if (x == 5)
                            {
                                break;         // Only do the first 5
                            }
                            int           characterId         = characterIds[x];
                            Character_Row characterFromSearch = _DBService.GetCharacterPublicInfo(characterId); //var characterIdSearch = await _ESIClient.Character.GetCharacterPublicInfoV4Async(characterId);
                            characters.Add(new CharacterDataModel()
                            {
                                Id        = characterId,
                                Character = characterFromSearch
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        // Not logged in, won't bother searching
                    }
                }

                count = regions.Count() +
                        constellations.Count() +
                        solarSystems.Count() +
                        stations.Count() +
                        itemTypes.Count() +
                        characters.Count();
            }


            var model = new SearchResultsPageViewModel
            {
                Query          = query,
                ResultCount    = count,
                Regions        = regions,
                Constellations = constellations,
                SolarSystems   = solarSystems,
                Stations       = stations,
                ItemTypes      = itemTypes,
                Characters     = characters
            };

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> Index(int id)
        {
            AuthDTO auth = GetAuth(_ESIClient);

            _Log.LogDebug(String.Format("Logged in to retrieve Character Info for Character Id: {0}", auth.CharacterId));

            Fatigue jumpFatigue = null;

            EVEStandard.Models.System locationSystem = null;
            CharacterAttributes       attributes     = null;

            if (id <= 0)          // Use own Character info
            {
                id = CharacterId; // Set id and use that

                var characterJumpFatigue = await _ESIClient.Character.GetJumpFatigueV1Async(auth);

                jumpFatigue = characterJumpFatigue.Model;

                var characterLocationApi = await _ESIClient.Location.GetCharacterLocationV1Async(auth);

                CharacterLocation characterLocation = characterLocationApi.Model;
                var locationSystemApi = await _ESIClient.Universe.GetSolarSystemInfoV4Async(characterLocation.SolarSystemId);

                locationSystem = locationSystemApi.Model;

                var attributesApi = await _ESIClient.Skills.GetCharacterAttributesV1Async(auth);

                attributes = attributesApi.Model;
            }

            Character_Row character = _DBService.GetCharacterPublicInfo(id);
            var           portrait  = await _ESIClient.Character.GetCharacterPortraitsV2Async(id);

            var corporation = await _ESIClient.Corporation.GetCorporationInfoV4Async((int)character.CorporationId);

            List <SkillQueueDataModel> skillsQueue = await GetSkillQueue(auth, id);

            List <CharacterBookmarkDataModel> bookmarksViewModel = await GetBookmarks(auth);

            bookmarksViewModel = bookmarksViewModel.OrderBy(x => x.Folder.Name).ToList();

            var walletApi = await _ESIClient.Wallet.GetCharacterWalletBalanceV1Async(auth);

            double walletBalance = walletApi.Model;

            var model = new CharacterPageViewModel
            {
                Id                   = id,
                Character            = character,
                Attributes           = attributes,
                Portrait             = portrait.Model,
                Corporation          = corporation.Model,
                LocationSystem       = locationSystem,
                CharacterJumpFatigue = jumpFatigue,
                SkillsQueue          = skillsQueue,
                Bookmarks            = bookmarksViewModel,
                WalletBalance        = walletBalance
            };

            return(View(model));
        }