Beispiel #1
0
        public IActionResult GetTeam(TeamType?teamType, [FromQuery(Name = "t")] long?time = null)
        {
            if (teamType == null)
            {
                return(BadRequest(new ErrorResponse("No such team")));
            }

            // Get the current allocation if no time specified
            if (time == null)
            {
                // Look up the team name against all the teams in an allocation
                switch (teamType)
                {
                case TeamType.A:
                    return(Json(new TeamSummaryResponse(_allocation.PodA)));

                case TeamType.B:
                    return(Json(new TeamSummaryResponse(_allocation.PodB)));

                case TeamType.C:
                    return(Json(new TeamSummaryResponse(_allocation.PodC)));

                case TeamType.D:
                    return(Json(new TeamSummaryResponse(_allocation.PodD)));

                case TeamType.Senior:
                    return(Json(new TeamSummaryResponse(_allocation.SeniorTeam)));

                default:
                    return(BadRequest(new ErrorResponse("Someone naughty has created a new TeamType instance")));
                }
            }
            // Otherwise try to find the allocation that was in place at the time specified
            else
            {
                Team allocation;
                switch (teamType)
                {
                case TeamType.Senior:
                    allocation = _allocation.GetPastSeniorTeam(time.Value);
                    break;

                case TeamType.A:
                case TeamType.B:
                case TeamType.C:
                case TeamType.D:
                    allocation = _allocation.GetPastPod(time.Value, teamType.Value);
                    break;

                default:
                    return(BadRequest(new ErrorResponse("Someone naughty has created a new TeamType instance")));
                }

                // No allocation at the time or lookup unsupported
                if (allocation == null)
                {
                    if (teamType == TeamType.Senior)
                    {
                        return(Json(new TeamSummaryResponse(SeniorTeam.Empty)));
                    }
                    else
                    {
                        return(Json(new TeamSummaryResponse(Pod.CreateEmpty(teamType.Value))));
                    }
                }
                else
                {
                    return(Json(new TeamSummaryResponse(allocation)));
                }
            }
        }