Esempio n. 1
0
 private OpponentDTO BuildOpponent(CreateOpponentResponse data)
 {
     try {
         return(new OpponentDTO()
         {
             ContactName = data.ContactName,
             Email = data.Email,
             Id = data.Id,
             Name = data.Name,
             Notes = data.Notes,
             Phone = data.Phone,
             TeamId = data.TeamId
         });
     }
     catch (Exception exc) {
         throw new InvalidOperationException("SchedulingService BuildOpponent()", exc);
     }
 }
Esempio n. 2
0
        public Task <OpponentDTO> CreateOpponentAsync(CreateOpponentDataModel createOpponentDataModel, CancellationTokenSource cancellationTokenSource) =>
        Task <OpponentDTO> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            OpponentDTO createdOpponent = null;

            CreateOpponentRequest createOpponentRequest = new CreateOpponentRequest()
            {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.ScheduleEndpoints.CreateNewOpponent,
                Data        = createOpponentDataModel
            };

            try {
                CreateOpponentResponse createOpponentResponse = await _requestProvider.PostAsync <CreateOpponentRequest, CreateOpponentResponse>(createOpponentRequest);

                if (createOpponentResponse != null)
                {
                    createdOpponent = BuildOpponent(createOpponentResponse);
                }
                else
                {
                    throw new InvalidOperationException(CREATE_OPPONENT_COMMON_ERROR_MESSAGE);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

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

                throw;
            }

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