//public Task<MediaDTO> SetAppBackgroundImage(BackgroundImageDataModel backgroundImageDataModel, CancellationTokenSource cancellationTokenSource) =>
        //    Task<MediaDTO>.Run(async () => {
        //        if (!CrossConnectivity.Current.IsConnected) {
        //            throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
        //        }

        //        SetAppBackgroundImageResponse setAppBackgroundImageResponse = null;
        //        MediaDTO profileMediaDTO = null;

        //        SetAppBackgroundImageRequest setAppBackgroundImageRequest = new SetAppBackgroundImageRequest() {
        //            AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
        //            Data = new SetAppBackgroundImageDataModel() {
        //                BackgroundImage = backgroundImageDataModel
        //            },
        //            Url = GlobalSettings.Instance.Endpoints.ProfileEndpoints.SetAppBackgroundImageEndPoint
        //        };

        //        try {
        //            setAppBackgroundImageResponse = await _requestProvider.PostAsync<SetAppBackgroundImageRequest, SetAppBackgroundImageResponse>(setAppBackgroundImageRequest);

        //            if (setAppBackgroundImageResponse != null) {
        //                profileMediaDTO = _mediaFactory.BuildMediaDTO(setAppBackgroundImageResponse);
        //            }
        //            else {
        //                throw new InvalidOperationException(ProfileService._SET_APP_BACKGROUND_IMAGE_COMMON_ERROR_MESSAGE);
        //            }
        //        }
        //        catch (ServiceAuthenticationException exc) {
        //            _identityUtilService.RefreshToken();

        //            throw exc;
        //        }
        //        catch (HttpRequestExceptionEx exc) {
        //            setAppBackgroundImageResponse = JsonConvert.DeserializeObject<SetAppBackgroundImageResponse>(exc.Message);

        //            string output = setAppBackgroundImageResponse?.Errors?.FirstOrDefault();

        //            output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? _SET_APP_BACKGROUND_IMAGE_COMMON_ERROR_MESSAGE : output;

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

        //            throw exc;
        //        }

        //        return profileMediaDTO;
        //    });

        public Task <bool> SetAppBackgroundImage(long mediaId, CancellationTokenSource cancellationTokenSource) =>
        Task <bool> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            SetAppBackgroundImageResponse setAppBackgroundImageResponse = null;
            bool completion = false;

            SetAppBackgroundImageRequest setAppBackgroundImageRequest = new SetAppBackgroundImageRequest()
            {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Data        = new SetAppBackgroundImageDataModel()
                {
                    MediaId = mediaId
                },
                Url = GlobalSettings.Instance.Endpoints.ProfileEndpoints.SetAppBackgroundImageEndPoint
            };

            try {
                setAppBackgroundImageResponse = await _requestProvider.PostAsync <SetAppBackgroundImageRequest, SetAppBackgroundImageResponse>(setAppBackgroundImageRequest);

                if (setAppBackgroundImageResponse != null)
                {
                    completion = true;
                }
                else
                {
                    completion = false;
                    throw new InvalidOperationException(ProfileService._SET_APP_BACKGROUND_IMAGE_COMMON_ERROR_MESSAGE);
                }
            }
            catch (ServiceAuthenticationException exc) {
                completion = false;
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (HttpRequestExceptionEx exc) {
                completion = false;
                setAppBackgroundImageResponse = JsonConvert.DeserializeObject <SetAppBackgroundImageResponse>(exc.Message);

                string output = setAppBackgroundImageResponse?.Errors?.FirstOrDefault();

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

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

                throw exc;
            }

            return(completion);
        });
Exemple #2
0
        public MediaDTO BuildMediaDTO(SetAppBackgroundImageResponse setAppBackgroundImageResponse)
        {
            MediaDTO profileMediaDTO = null;

            if (setAppBackgroundImageResponse != null)
            {
                profileMediaDTO = new MediaDTO()
                {
                    Url          = setAppBackgroundImageResponse.Url,
                    ThumbnailUrl = setAppBackgroundImageResponse.ThumbnailUrl,
                    Name         = setAppBackgroundImageResponse.Name,
                    Id           = setAppBackgroundImageResponse.Id
                };
            }

            return(profileMediaDTO);
        }