Esempio n. 1
0
        private async void UploadPhoto(Plugin.Media.Abstractions.MediaFile mediaFile)
        {
            if (mediaFile != null)
            {
                await Task.Run(() => { _model.SetActivityResource(false, true); });

                if (await _media.UploadPhotoAsync(mediaFile))
                {
                    if (!string.IsNullOrEmpty(_media.FileName))
                    {
                        var profileImage = _metaPivotService.AddMeta(_media.FileName,
                                                                     MetaConstants.PROFILE_PHOTO.ToCapital(),
                                                                     MetaConstants.PROFILE_PHOTO,
                                                                     MetaConstants.PROFILE_PHOTO);
                        var response = await _metaPivotService.SaveMetaAsync(profileImage);

                        if (response != null && response.Contains(HttpConstants.SUCCESS))
                        {
                            _model.User.ProfileImage = _media.FileName;
                            App.CurrentUser.UserInfo = _model.User;
                            _model.ProfileImagePath  = _model.User.ProfileImage;
                            _model.SetActivityResource(showMessage: true,
                                                       message: TextResources.ChangeProfilePhoto + " " + TextResources.Change + " " +
                                                       TextResources.Success);
                            return;
                        }
                    }
                }
            }
            _model.SetActivityResource(showError: true, errorMessage: _media.Message);
        }
Esempio n. 2
0
        private async void ChangeProfilePhoto(object sender, EventArgs args)
        {
            var result = await DisplayActionSheet(TextResources.ChooseOption, TextResources.Cancel, null,
                                                  new string[] { TextResources.PickFromGallery, TextResources.TakeFromCamera });

            if (result != null)
            {
                if (result == "Cancel")
                {
                    return;
                }
                if (result == TextResources.PickFromGallery)
                {
                    _media.Refresh();
                    var mediaFile = await _media.PickPhotoAsync();

                    if (mediaFile == null)
                    {
                        _model.SetActivityResource(showError: true, errorMessage: _media.Message);
                        return;
                    }

                    await Task.Run(() => { _model.SetActivityResource(false, true); });

                    var response = await _media.UploadPhotoAsync(mediaFile);

                    if (!response)
                    {
                        _model.SetActivityResource(true, false, showError: true, errorMessage: _media.Message);
                        return;
                    }
                }
                else if (result == TextResources.TakeFromCamera)
                {
                    _media.Refresh();
                    var mediaFile = await _media.TakePhotoAsync();

                    if (mediaFile == null)
                    {
                        _model.SetActivityResource(showError: true, errorMessage: _media.Message);
                        return;
                    }

                    await Task.Run(() => { _model.SetActivityResource(false, true); });

                    var response = await _media.UploadPhotoAsync(mediaFile);

                    if (!response)
                    {
                        _model.SetActivityResource(true, false, showError: true, errorMessage: _media.Message);
                        return;
                    }
                }

                _model.SetActivityResource();

                if (!string.IsNullOrEmpty(_media.FileName))
                {
                    var profileImage = _metaPivotService.AddMeta(_media.FileName,
                                                                 MetaConstants.PROFILE_PHOTO.ToCapital(), MetaConstants.PROFILE_PHOTO,
                                                                 MetaConstants.PROFILE_PHOTO);
                    var response = await _metaPivotService.SaveMetaAsync(profileImage);

                    if (response != null && response.Contains(HttpConstants.SUCCESS))
                    {
                        _model.User.ProfileImage = _media.FileName;
                        App.CurrentUser.UserInfo = _model.User;
                        _model.ProfileImagePath  = _model.User.ProfileImage;
                        _model.SetActivityResource(showMessage: true,
                                                   message: TextResources.ChangeProfilePhoto + " " + TextResources.Change + " " +
                                                   TextResources.Success);
                    }
                }
                else
                {
                    _model.SetActivityResource(showError: true, errorMessage: _media.Message);
                }
            }
        }