/// <summary>
        /// Gets the tournament list.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="golfClubId">The golf club identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <GetTournamentListResponse> GetTournamentList(String accessToken,
                                                                        Guid golfClubId,
                                                                        CancellationToken cancellationToken)
        {
            GetTournamentListResponse response = null;

            String requestUri = $"{this.BaseAddress}/api/GolfClub/{golfClubId}/Tournament/List";

            try
            {
                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful so now deserialise the body to the response object
                response = JsonConvert.DeserializeObject <GetTournamentListResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception("Error getting the tournament list.", ex);

                throw exception;
            }

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the tournament list.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="claimsIdentity">The claims identity.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <List <GetTournamentListViewModel> > GetTournamentList(String accessToken,
                                                                                 ClaimsIdentity claimsIdentity,
                                                                                 CancellationToken cancellationToken)
        {
            List <GetTournamentListViewModel> result = new List <GetTournamentListViewModel>();

            try
            {
                Guid golfClubId = ApiClient.GetClaimValue <Guid>(claimsIdentity, "GolfClubId");
                GetTournamentListResponse tournamentListResponse = await this.TournamentClient.GetTournamentList(accessToken, golfClubId, cancellationToken);

                result = this.ModelFactory.ConvertFrom(tournamentListResponse);
            }
            catch (Exception ex)
            {
                // Look at the inner exception
                if (ex.InnerException is KeyNotFoundException)
                {
                    // Swallow this exception and set the result to false
                    result = new List <GetTournamentListViewModel>();
                }
                else
                {
                    throw;
                }
            }

            return(result);
        }
        public async Task <IActionResult> GetGolfClub([FromRoute] Guid golfClubId,
                                                      [FromQuery] Boolean includeMembers,
                                                      [FromQuery] Boolean includeMeasuredCourses,
                                                      [FromQuery] Boolean includeUsers,
                                                      [FromQuery] Boolean includeTournaments,
                                                      CancellationToken cancellationToken)
        {
            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(golfClubId, golfClubIdClaim);

            if (validationResult == false)
            {
                return(this.Forbid());
            }

            GetGolfClubResponsev1 getGolfClubResponsev1 = await this.Manager.GetGolfClub(Guid.Parse(golfClubIdClaim.Value), cancellationToken);

            List <GetGolfClubMembershipDetailsResponse> membersList = null;

            if (includeMembers)
            {
                membersList = await this.Manager.GetGolfClubMembersList(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetMeasuredCourseListResponse measuredCourseList = null;

            if (includeMeasuredCourses)
            {
                measuredCourseList = await this.Manager.GetMeasuredCourseList(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetGolfClubUserListResponse users = null;

            if (includeUsers)
            {
                users = await this.Manager.GetGolfClubUsers(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetTournamentListResponse tournamentList = null;

            if (includeTournaments)
            {
                tournamentList = await this.Manager.GetTournamentList(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetGolfClubResponsev2 getGolfClubResponsev2 = this.ConvertGetGolfClubResponse(getGolfClubResponsev1, membersList, measuredCourseList, users, tournamentList);

            return(this.Ok(getGolfClubResponsev2));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetTournamentList([FromRoute] Guid golfClubId, CancellationToken cancellationToken)
        {
            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(golfClubId, golfClubIdClaim);

            if (validationResult == false)
            {
                return(this.Forbid());
            }

            // Get the data
            GetTournamentListResponse tournamentList = await this.Manager.GetTournamentList(Guid.Parse(golfClubIdClaim.Value), cancellationToken);

            return(this.Ok(tournamentList));
        }
        public void ModelFactory_ConvertFrom_GetTournamentListResponse_ConvertedSuccessfully()
        {
            ModelFactory factory = new ModelFactory();

            GetTournamentListResponse apiResponse = ModelFactoryTestData.GetTournamentListResponse();

            List <GetTournamentListViewModel> viewModel = factory.ConvertFrom(apiResponse);

            viewModel.First().PlayerCategory.ShouldBe(apiResponse.Tournaments.First().PlayerCategory.ToString());
            viewModel.First().Date.ShouldBe(apiResponse.Tournaments.First().TournamentDate);
            viewModel.First().Format.ShouldBe(apiResponse.Tournaments.First().TournamentFormat.ToString());
            viewModel.First().MeasuredCourseName.ShouldBe(apiResponse.Tournaments.First().MeasuredCourseName);
            viewModel.First().MeasuredCourseTeeColour.ShouldBe(apiResponse.Tournaments.First().MeasuredCourseTeeColour);
            viewModel.First().Name.ShouldBe(apiResponse.Tournaments.First().TournamentName);
            viewModel.First().Status.ShouldBe("Resulted");
            viewModel.First().TournamentId.ShouldBe(apiResponse.Tournaments.First().TournamentId);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="apiResponse">The API response.</param>
        /// <returns></returns>
        public List <GetTournamentListViewModel> ConvertFrom(GetTournamentListResponse apiResponse)
        {
            List <GetTournamentListViewModel> viewModels = new List <GetTournamentListViewModel>();

            foreach (GetTournamentResponse apiResponseTournament in apiResponse.Tournaments)
            {
                viewModels.Add(new GetTournamentListViewModel
                {
                    Date                    = apiResponseTournament.TournamentDate,
                    Format                  = apiResponseTournament.TournamentFormat.ToString(),
                    MeasuredCourseName      = apiResponseTournament.MeasuredCourseName,
                    MeasuredCourseTeeColour = apiResponseTournament.MeasuredCourseTeeColour,
                    Name                    = apiResponseTournament.TournamentName,
                    PlayerCategory          = apiResponseTournament.PlayerCategory.ToString(),
                    TournamentId            = apiResponseTournament.TournamentId,
                    Status                  = this.TranslateTournamentStatus(apiResponseTournament)
                });
            }

            return(viewModels);
        }
        /// <summary>
        /// Gets the next available tournaments for sign in.
        /// </summary>
        /// <param name="passwordToken">The password token.</param>
        /// <param name="playerId">The player identifier.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task GetNextAvailableTournamentsForSignIn(String passwordToken,
                                                               Guid playerId,
                                                               MyTournamentsSignInViewModel viewModel,
                                                               CancellationToken cancellationToken)
        {
            // Get memberships
            List <ClubMembershipResponse> memberships = await this.PlayerClient.GetPlayerMemberships(passwordToken, playerId, cancellationToken);

            List <GetTournamentResponse> tournaments = new List <GetTournamentResponse>();

            // Get Tournaments
            foreach (ClubMembershipResponse clubMembershipResponse in memberships)
            {
                GetTournamentListResponse tournamentsForClub =
                    await this.TournamentClient.GetTournamentList(passwordToken, clubMembershipResponse.GolfClubId, cancellationToken);

                tournaments.AddRange(tournamentsForClub.Tournaments);
            }

            // Get First one (Need to decide how to actually sort these....)
            IEnumerable <GetTournamentResponse> availableTournaments = tournaments.Where(t => t.HasBeenCompleted == false && t.TournamentDate.Date == DateTime.Today);

            foreach (GetTournamentResponse getTournamentResponse in availableTournaments)
            {
                if (viewModel.Tournaments == null)
                {
                    viewModel.Tournaments = new ObservableCollection <TournamentSignInViewModel>();
                }

                viewModel.Tournaments.Add(new TournamentSignInViewModel
                {
                    TournamentId   = getTournamentResponse.TournamentId,
                    CourseName     = getTournamentResponse.MeasuredCourseName,
                    TournamentName = getTournamentResponse.TournamentName,
                    TournamentDate = getTournamentResponse.TournamentDate,
                    Format         = getTournamentResponse.TournamentFormat.ToString()
                });
            }
        }
Exemplo n.º 8
0
 public IEnumerator GetTournamentList(GetTournamentListRequest request,
                                      Action <GetTournamentListResponse> onTournamentListResponse,
                                      Action <string> onError)
 {
     yield return(SyncGet(
                      request,
                      responseText =>
     {
         if (!string.IsNullOrEmpty(responseText))
         {
             onTournamentListResponse(GetTournamentListResponse.FromJSON(responseText));
         }
         else
         {
             onTournamentListResponse(new GetTournamentListResponse()
             {
                 tournaments = new List <Tournament>()
             });
         }
     },
                      onError
                      ));
 }
        private GetGolfClubResponsev2 ConvertGetGolfClubResponse(GetGolfClubResponsev1 getGolfClubResponsev1,
                                                                 List <GetGolfClubMembershipDetailsResponse> membersList = null,
                                                                 GetMeasuredCourseListResponse measuredCourseList        = null,
                                                                 GetGolfClubUserListResponse users        = null,
                                                                 GetTournamentListResponse tournamentList = null)
        {
            GetGolfClubResponsev2 response = new GetGolfClubResponsev2
            {
                TelephoneNumber = getGolfClubResponsev1.TelephoneNumber,
                EmailAddress    = getGolfClubResponsev1.EmailAddress,
                Name            = getGolfClubResponsev1.Name,
                AddressLine1    = getGolfClubResponsev1.AddressLine1,
                AddressLine2    = getGolfClubResponsev1.AddressLine2,
                Id         = getGolfClubResponsev1.Id,
                PostalCode = getGolfClubResponsev1.PostalCode,
                Region     = getGolfClubResponsev1.Region,
                Town       = getGolfClubResponsev1.Town,
                Website    = getGolfClubResponsev1.Website,
            };

            if (membersList != null)
            {
                response.GolfClubMembershipDetailsResponseList = new List <GolfClubMembershipDetailsResponse>();

                foreach (GetGolfClubMembershipDetailsResponse getGolfClubMembershipDetailsResponse in membersList)
                {
                    response.GolfClubMembershipDetailsResponseList.Add(new GolfClubMembershipDetailsResponse
                    {
                        MembershipStatus  = (MembershipStatusv2)getGolfClubMembershipDetailsResponse.MembershipStatus,
                        PlayerId          = getGolfClubMembershipDetailsResponse.PlayerId,
                        Name              = getGolfClubMembershipDetailsResponse.Name,
                        MembershipNumber  = getGolfClubMembershipDetailsResponse.MembershipNumber,
                        PlayerDateOfBirth = getGolfClubMembershipDetailsResponse.PlayerDateOfBirth,
                        PlayerFullName    = getGolfClubMembershipDetailsResponse.PlayerFullName,
                        PlayerGender      = getGolfClubMembershipDetailsResponse.PlayerGender
                    });
                }
            }

            if (measuredCourseList != null)
            {
                response.MeasuredCourses = new List <MeasuredCourseListResponse>();

                foreach (DataTransferObjects.Responses.MeasuredCourseListResponse measuredCourseListResponse in measuredCourseList.MeasuredCourses)
                {
                    response.MeasuredCourses.Add(new MeasuredCourseListResponse
                    {
                        MeasuredCourseId     = measuredCourseListResponse.MeasuredCourseId,
                        Name                 = measuredCourseListResponse.Name,
                        TeeColour            = measuredCourseListResponse.TeeColour,
                        StandardScratchScore = measuredCourseListResponse.StandardScratchScore
                    });
                }
            }

            if (users != null)
            {
                response.Users = new List <GolfClubUserResponse>();

                foreach (DataTransferObjects.Responses.GolfClubUserResponse user in users.Users)
                {
                    response.Users.Add(new GolfClubUserResponse
                    {
                        UserId      = user.UserId,
                        FamilyName  = user.FamilyName,
                        GivenName   = user.GivenName,
                        MiddleName  = user.MiddleName,
                        Email       = user.Email,
                        PhoneNumber = user.PhoneNumber,
                        UserName    = user.UserName,
                        UserType    = user.UserType
                    });
                }
            }

            if (tournamentList != null)
            {
                response.Tournaments = new List <TournamentResponse>();

                foreach (DataTransferObjects.Responses.GetTournamentResponse tournamentListTournament in tournamentList.Tournaments)
                {
                    response.Tournaments.Add(new TournamentResponse
                    {
                        MeasuredCourseId           = tournamentListTournament.MeasuredCourseId,
                        TournamentFormat           = (TournamentFormat)tournamentListTournament.TournamentFormat,
                        TournamentDate             = tournamentListTournament.TournamentDate,
                        MeasuredCourseName         = tournamentListTournament.MeasuredCourseName,
                        TournamentId               = tournamentListTournament.TournamentId,
                        MeasuredCourseTeeColour    = tournamentListTournament.MeasuredCourseTeeColour,
                        TournamentName             = tournamentListTournament.TournamentName,
                        HasBeenCancelled           = tournamentListTournament.HasBeenCancelled,
                        HasBeenCompleted           = tournamentListTournament.HasBeenCompleted,
                        HasResultBeenProduced      = tournamentListTournament.HasResultBeenProduced,
                        MeasuredCourseSSS          = tournamentListTournament.MeasuredCourseSSS,
                        PlayerCategory             = (PlayerCategory)tournamentListTournament.PlayerCategory,
                        PlayersScoresRecordedCount = tournamentListTournament.PlayersScoresRecordedCount,
                        PlayersSignedUpCount       = tournamentListTournament.PlayersSignedUpCount
                    });
                }
            }

            return(response);
        }