Example #1
0
        public TeamDTO BuildTeam(TeamEndsPartnershipWithOrganizationResponse data)
        {
            TeamDTO teamDTO = null;

            if (data != null)
            {
                teamDTO = new TeamDTO()
                {
                    Coach          = data.Coach,
                    CoachId        = data.CoachId,
                    CreatedBy      = data.CreatedBy,
                    Events         = data.Events,
                    Games          = data.Games,
                    Id             = data.Id,
                    Locations      = data.Locations,
                    Members        = data.Members,
                    Name           = data.Name,
                    Opponents      = data.Opponents,
                    Organization   = data.Organization,
                    OrganizationId = data.OrganizationId,
                    Owner          = data.Owner,
                    Sport          = data.Sport
                };
            }

            return(teamDTO);
        }
Example #2
0
        public Task <TeamDTO> EndPartnershipWithOrganization(long teamId, CancellationTokenSource cancellationTokenSource) =>
        Task <TeamDTO> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            TeamDTO resultTeam = null;

            TeamEndsPartnershipWithOrganizationRequest teamEndsPartnershipWithOrganizationRequest = new TeamEndsPartnershipWithOrganizationRequest()
            {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = string.Format(GlobalSettings.Instance.Endpoints.TeamEndPoints.TeamEndPartnershipWithOrganizationApiKey, teamId)
            };

            try {
                TeamEndsPartnershipWithOrganizationResponse teamEndsPartnershipWithOrganizationResponse =
                    await _requestProvider.PostAsync <TeamEndsPartnershipWithOrganizationRequest, TeamEndsPartnershipWithOrganizationResponse>(teamEndsPartnershipWithOrganizationRequest);

                if (teamEndsPartnershipWithOrganizationResponse == null)
                {
                    throw new InvalidOperationException(TEAM_END_PARTNERSHIP_WITH_ORGANIZATION_COMMON_ERROR_MESSAGE);
                }

                if (teamEndsPartnershipWithOrganizationResponse.Errors != null || teamEndsPartnershipWithOrganizationResponse.OrgError != null ||
                    teamEndsPartnershipWithOrganizationResponse.ProfileError != null || teamEndsPartnershipWithOrganizationResponse.TeamError != null)
                {
                    throw new InvalidOperationException(string.Format("{0} {1} {2} {3}",
                                                                      teamEndsPartnershipWithOrganizationResponse.Errors?.FirstOrDefault(), teamEndsPartnershipWithOrganizationResponse.OrgError?.FirstOrDefault(),
                                                                      teamEndsPartnershipWithOrganizationResponse.ProfileError?.FirstOrDefault(), teamEndsPartnershipWithOrganizationResponse.TeamError?.FirstOrDefault()).Trim());
                }
                else
                {
                    resultTeam = _teamFactory.BuildTeam(teamEndsPartnershipWithOrganizationResponse);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);
                throw;
            }

            return(resultTeam);
        }, cancellationTokenSource.Token);