コード例 #1
0
        public Task <ProfileDTO> NixTeamAppointmentAsync(long targetTeamId, CancellationTokenSource cancellationTokenSource) =>
        Task <ProfileDTO> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            ProfileDTO resultProfile = null;

            NixTeamAppointmentRequest nixTeamAppointmentRequest = new NixTeamAppointmentRequest()
            {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = string.Format(GlobalSettings.Instance.Endpoints.TeamEndPoints.NixTeamAppointmentRequest, targetTeamId)
            };

            NixTeamAppointmentResponse nixTeamAppointmentResponse = null;

            try {
                nixTeamAppointmentResponse = await _requestProvider.DeleteAsync <NixTeamAppointmentRequest, NixTeamAppointmentResponse>(nixTeamAppointmentRequest);

                if (nixTeamAppointmentResponse != null)
                {
                    resultProfile = _profileFactory.BuildProfileDTO(nixTeamAppointmentResponse);
                }
                else
                {
                    throw new InvalidOperationException(TeamService.NIX_APPOINTMENT_TO_THE_TEAM_COMMON_ERROR_MESSAGE);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (HttpRequestExceptionEx exc) {
                nixTeamAppointmentResponse = JsonConvert.DeserializeObject <NixTeamAppointmentResponse>(exc.Message);

                string output = string.Format("{0}",
                                              nixTeamAppointmentResponse.Relation?.FirstOrDefault());

                output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? TeamService.NIX_APPOINTMENT_TO_THE_TEAM_COMMON_ERROR_MESSAGE : output;

                throw new InvalidOperationException(output.Trim());
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);
                throw;
            }

            return(resultProfile);
        }, cancellationTokenSource.Token);
コード例 #2
0
        public ChildItemViewModel MakeChild(RegistrationResponse registrationResponse)
        {
            ChildItemViewModel childItemViewModel = new ChildItemViewModel(_profileService)
            {
                Id   = registrationResponse.Id,
                Name = registrationResponse.FirstName,
                Age  = (DateTime.Now.Year - registrationResponse.DateOfBirth.Year).ToString(),
                //Impersonate = (DateTime.Now.Year - registrationResponse.DateOfBirth.Year) < AGE_RESTRICTION ? IMPERSONATE_IMAGE_PATH : string.Empty,
                IsImpersonateLoginEnabled = (DateTime.Now.Year - registrationResponse.DateOfBirth.Year) < UserProfile.YOUNG_PLAYERS_AGE_LIMIT,
                Profile = _profileFactory.BuildProfileDTO(registrationResponse)
            };

            childItemViewModel.IsAddEmailCommandEnabled = (!childItemViewModel.IsImpersonateLoginEnabled && !registrationResponse.IsEmailConfirmed);

            return(childItemViewModel);
        }
コード例 #3
0
        public async Task <ProfileDTO> GetProfileByIdAsync(long id, CancellationToken cancellationToken) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            ProfileDTO profile = null;

            GetProfileRequest getProfileRequest = new GetProfileRequest {
                Url         = string.Format(GlobalSettings.Instance.Endpoints.ProfileEndpoints.GetProfileByIdEndPoints, id),
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken
            };

            GetProfileResponse getProfileResponse = null;

            try {
                getProfileResponse =
                    await _requestProvider.GetAsync <GetProfileRequest, GetProfileResponse>(getProfileRequest);

                if (getProfileResponse != null)
                {
                    profile = _profileFactory.BuildProfileDTO(getProfileResponse);
                }
                else
                {
                    throw new InvalidOperationException(CANT_RESOLVE_PROFILE_COMMON_ERROR_MESSAGE);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

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

                Debug.WriteLine($"ERROR:{ex.Message}");
                Debugger.Break();
                throw new Exception(ex.Message);
            }

            return(profile);
        }, cancellationToken);