Beispiel #1
0
        public async Task <IActionResult> ViewTeam(string teamName)
        {
            var teams = await Team.GetByTeamNameAsync(teamName, _azureSQL);

            var team = teams.FirstOrDefault();

            var entries = await Step.GetByTeamAsync(team?.TeamName, _azureSQL);

            var uniqueNames = entries.Select(x => x.Nickname).Distinct();

            var nicknames = new List <Nickname>();

            foreach (var name in uniqueNames)
            {
                var results = await Nickname.GetByNicknameAsync(name, _azureSQL);

                if (!(results is null))
                {
                    nicknames.Add(results.FirstOrDefault());
                }
            }

            return(View("Team", new TeamResult
            {
                Team = team,
                Nicknames = nicknames,
                Steps = entries
            }));
        }
        public async Task <IActionResult> MapAsync(string journeyName, string teamName, string name)
        {
            var response = new Map();

            if (!string.IsNullOrWhiteSpace(journeyName) &&
                (journeyName.Length < 100))
            {
                journeyName = journeyName.Trim();

                var journeys = await Journey.GetByJourneyNameAsync(journeyName, _azureSQL);

                response.Journey = journeys.FirstOrDefault();

                var entries = await Step.GetByJourneyAsync(response.Journey?.JourneyName, _azureSQL);

                foreach (var entry in entries)
                {
                    response.StepsTaken += entry.Steps;
                }
            }

            if (!(string.IsNullOrWhiteSpace(teamName)) &&
                (teamName.Length < 100))
            {
                teamName = teamName.Trim();

                var teams = await Team.GetByTeamNameAsync(teamName, _azureSQL);

                response.Team = teams.FirstOrDefault();
            }
            else
            {
                var teams = await Team.GetAllAsync(_azureSQL);

                response.Teams = teams.OrderBy(x => x.TeamName);
            }

            if (!(string.IsNullOrWhiteSpace(name)) &&
                (name.Length < 100))
            {
                name = name.Trim();

                var nicknames = await Nickname.GetByNicknameAsync(name, _azureSQL);

                response.Nickname = nicknames.FirstOrDefault();
            }
            else
            {
                var nicknames = await Nickname.GetAllAsync(_azureSQL);

                response.Nicknames = nicknames.OrderBy(x => x.Name);
            }

            if (response?.Journey is null || string.IsNullOrWhiteSpace(response?.Journey?.JourneyName))
            {
                return(Redirect("/"));
            }

            return(View("Map", response));
        }
        public async Task <IActionResult> ViewJourney(string journeyName)
        {
            var journeys = await Journey.GetByJourneyNameAsync(journeyName, _azureSQL);

            var journey = journeys.FirstOrDefault();
            var entries = await Step.GetByJourneyAsync(journey?.JourneyName, _azureSQL);

            var uniqueTeamNames = entries.Select(x => x.TeamName).Distinct();

            var teams = new List <Team>();

            foreach (var team in uniqueTeamNames)
            {
                var results = await Team.GetByTeamNameAsync(team, _azureSQL);

                if (!(results is null))
                {
                    teams.Add(results.FirstOrDefault());
                }
            }

            var uniqueNames = entries.Select(x => x.Nickname).Distinct();

            var nicknames = new List <Nickname>();

            foreach (var name in uniqueNames)
            {
                var results = await Nickname.GetByNicknameAsync(name, _azureSQL);

                if (!(results is null))
                {
                    nicknames.Add(results.FirstOrDefault());
                }
            }

            // Maybe look up all the entries that reference this team?
            return(View("Journey", new JourneyResult
            {
                Journey = journey,
                Teams = teams,
                Nicknames = nicknames,
                Steps = entries
            }));
        }
        public async Task <IActionResult> ViewName(string name)
        {
            var nicknames = await Nickname.GetByNicknameAsync(name, _azureSQL);

            var nickname = nicknames.FirstOrDefault();

            var entries = await Step.GetByExactNicknameAsync(nickname?.Name, _azureSQL);

            var uniqueJourneyNames = entries.Select(x => x.JourneyName).Distinct();

            var journeys = new List <Journey>();

            foreach (var journey in uniqueJourneyNames)
            {
                var results = await Journey.GetByJourneyNameAsync(journey, _azureSQL);

                if (!(results is null))
                {
                    journeys.Add(results.FirstOrDefault());
                }
            }

            var uniqueTeamNames = entries.Select(x => x.TeamName).Distinct();

            var teams = new List <Team>();

            foreach (var team in uniqueTeamNames)
            {
                var results = await Team.GetByTeamNameAsync(team, _azureSQL);

                if (!(results is null))
                {
                    teams.Add(results.FirstOrDefault());
                }
            }

            return(View("Nickname", new NicknameResult
            {
                Nickname = nickname,
                Journeys = journeys,
                Teams = teams,
                Steps = entries
            }));
        }
        public async Task <IActionResult> IndexAsync(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                var results = await Nickname.GetAllAsync(_azureSQL);

                return(View("Nicknames", new NicknameSearchResult
                {
                    Query = name,
                    Nicknames = results
                }));
            }
            else
            {
                var results = await Nickname.GetByNicknameAsync(name, _azureSQL);

                if (!results.Any())
                {
                    results = await Nickname.SearchByNicknameAsync(name, _azureSQL);
                }

                if (results.Count() > 1)
                {
                    return(View("Nicknames", new NicknameSearchResult
                    {
                        Query = name,
                        Nicknames = results
                    }));
                }
                else
                {
                    return(View("Nicknames", new NicknameSearchResult
                    {
                        Query = name,
                        Nicknames = results
                    }));
                }
            }
        }
        public async Task CreateAndDeleteNickname()
        {
            var nickname = new Nickname
            {
                Name    = "TestNickname",
                Bio     = "This is a team created to test the process of team creation and deletion.",
                Active  = true,
                Created = DateTime.Now
            };

            var checkSubmit = await nickname.PostAsync(_azureSql);

            Assert.True(checkSubmit);

            var fromDb = await Nickname.GetByNicknameAsync(nickname.Name, _azureSql);

            var thisTeam = fromDb.FirstOrDefault();

            Assert.Equal(nickname.Name, thisTeam.Name);

            var checkDelete = await thisTeam.DeleteAsync(_azureSql);

            Assert.True(checkDelete);
        }