Beispiel #1
0
        public string PurchaseTicket(LuisResponse luisResults)
        {
            var  home            = luisResults.Entities.ContainsKey("Home") ? luisResults.Entities["Home"] : null;
            var  away            = luisResults.Entities.ContainsKey("Away") ? luisResults.Entities["Away"] : null;
            var  team            = luisResults.Entities.ContainsKey("Team") ? luisResults.Entities["Team"] : null;
            bool areTeamsPresent = (home ?? away ?? team) == null; // Check if teams are present, if yes get new game from FindMatch, if not get last game saved in context

            FindMatchResponse findMatchResponse = FindMatch(luisResults, areTeamsPresent);
            var finalResponse = string.Empty;

            home = findMatchResponse.Home;
            away = findMatchResponse.Away;
            var number       = luisResults.Entities.ContainsKey("number") ? luisResults.Entities["number"] : null;
            var ticketNumber = 1;

            if (number != null)
            {
                ticketNumber = int.Parse(number);
            }
            var ticketString = ticketNumber > 1 ? "tickets" : "ticket";


            if (home != null && away != null)
            {
                finalResponse = lgEngine.EvaluateTemplate("PurchaseTicketTemplate", new { home = home, away = away, ticketNumber = ticketNumber, ticketString = ticketString, stadium = stadiums[home], date = findMatchResponse.MatchDate, price = ticketNumber * TicketPrice });
            }
            else
            {
                finalResponse = "Sorry we could not find the game you were trying to purchase tickets for.";
            }

            return(finalResponse);
        }
Beispiel #2
0
        public FindMatchResponse FindMatch(LuisResponse luisResults, bool fromContext = false)
        {
            // If requested to get last discussed game, return it
            if (fromContext)
            {
                return(LastGameInMemory);
            }

            var home     = luisResults.Entities.ContainsKey("Home") ? luisResults.Entities["Home"] : null;
            var away     = luisResults.Entities.ContainsKey("Away") ? luisResults.Entities["Away"] : null;
            var team     = luisResults.Entities.ContainsKey("Team") ? luisResults.Entities["Team"] : null;
            var relative = luisResults.Entities.ContainsKey("Relative") ? luisResults.Entities["Relative"] : null;

            if (home != null && away == null && team != null && home != team)
            {
                away = team;
            }
            else if (home == null && away != null && team != null && away != team)
            {
                home = team;
            }

            MatchJSON matchInfo = GetMatchInfo(home, away, team, relative);

            var findMatchResult = new FindMatchResponse()
            {
                Home         = matchInfo.HomeTeam,
                Away         = matchInfo.AwayTeam,
                MatchDate    = matchInfo.Date,
                ResponseText = matchInfo.MatchDescription,
                Team         = team,
                PictureType  = IsChampionsLeague ? PictureType.ChampionsLeague : PictureType.LaLiga,
            };

            CoreferenceTeam   = team ?? home ?? away; // Save last team in context
            LastGameInMemory  = findMatchResult;      // Save last game found
            IsChampionsLeague = false;                // Reset Champions League flag
            return(findMatchResult);
        }