Esempio n. 1
0
        /// <summary>
        /// 修改头像
        /// </summary>
        /// <param name="item">用户实例</param>
        /// <param name="file">文件流</param>
        /// <returns></returns>
        public int UpdateAvatar(User item, IFormFile file)
        {
            return(ProcessUpdate(() =>
            {
                IUploadFileManager uploadFileManager = serviceProvider.GetRequiredService <IUploadFileManager>();
                UploadFile uploadFile = uploadFileManager.CreateUploadFile(item.Id, item.Id, 1, file.FileName);
                string physicalPath = uploadFileManager.GetPhysicalPath(uploadFile.RelativePath);
                uploadFileManager.SaveFile(physicalPath, file);

                string existAvatar = item.Avatar;
                item.Avatar = uploadFile.RelativePath;

                int affectRows = ProcessWithTransaction((transaction) =>
                {
                    int rows = dal.ModifyAvatar(item, transaction.Connection, transaction);
                    rows += operateHistoryManager.Insert(item.Id, item, DataOperationType.Update, description: "用户修改头像", transaction: transaction);
                    rows += uploadFileManager.Insert(uploadFile, transaction);
                    return rows;
                });
                if (affectRows > 0)
                {
                    RemoveCache();
                }
                return affectRows;
            }, (log) =>
            {
                log.Properties[nameof(item)] = item;
            }));
        }
Esempio n. 2
0
        //public ObservableCollection<TLUserBase> Items { get; set; }

        public EditChatViewModel(IUploadFileManager uploadManager, ICacheService cacheService,
                                 ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService,
                                 IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            _uploadManager = uploadManager;

            CurrentItem = StateService.CurrentChat;
            StateService.CurrentChat = null;
            var chat = CurrentItem as TLChat;

            if (chat != null)
            {
                Title = chat.Title.ToString();
            }
            var broadcastChat = CurrentItem as TLBroadcastChat;

            if (broadcastChat != null)
            {
                Title = broadcastChat.Title.ToString();
            }
            var channel = CurrentItem as TLChannel;

            if (channel != null)
            {
                Title = channel.Title.ToString();
                About = channel.About != null?channel.About.ToString() : string.Empty;
            }

            //Items = new ObservableCollection<TLUserBase>();
        }
        public ChatCreateStep1ViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUploadFileManager uploadFileManager)
            : base(protoService, cacheService, aggregator)
        {
            _uploadFileManager = uploadFileManager;

            SendCommand      = new RelayCommand(SendExecute, () => !string.IsNullOrWhiteSpace(Title));
            EditPhotoCommand = new RelayCommand <StorageFile>(EditPhotoExecute);
        }
Esempio n. 4
0
        public ChatEditViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUploadFileManager uploadFileManager)
            : base(protoService, cacheService, aggregator)
        {
            _uploadFileManager = uploadFileManager;

            SendCommand      = new RelayCommand(SendExecute);
            EditPhotoCommand = new RelayCommand <StorageFile>(EditPhotoExecute);
            DeleteCommand    = new RelayCommand(DeleteExecute);
        }
Esempio n. 5
0
 public SettingsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUpdatesService updatesService, IPushService pushService, IContactsService contactsService, IUploadFileManager uploadFileManager, IStickersService stickersService)
     : base(protoService, cacheService, aggregator)
 {
     _updatesService    = updatesService;
     _pushService       = pushService;
     _contactsService   = contactsService;
     _uploadFileManager = uploadFileManager;
     _stickersService   = stickersService;
 }
        public EditCurrentUserViewModel(IUploadFileManager uploadManager, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) :
            base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            _uploadManager = uploadManager;

            CurrentItem = CacheService.GetUser(new TLInt(StateService.CurrentUserId));

            FirstName = ((TLUserBase)CurrentItem).FirstName.Value;
            LastName  = ((TLUserBase)CurrentItem).LastName.Value;
        }
Esempio n. 7
0
        public ChannelEditViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUploadFileManager uploadFileManager)
            : base(protoService, cacheService, aggregator)
        {
            _uploadFileManager = uploadFileManager;

            AdminedPublicChannels = new MvxObservableCollection <TLChannel>();

            SendCommand           = new RelayCommand(SendExecute);
            EditPhotoCommand      = new RelayCommand <StorageFile>(EditPhotoExecute);
            EditStickerSetCommand = new RelayCommand(EditStickerSetExecute);
            RevokeLinkCommand     = new RelayCommand <TLChannel>(RevokeLinkExecute);
            DeleteCommand         = new RelayCommand(DeleteExecute);
        }
Esempio n. 8
0
        public SettingsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUpdatesService updatesService, IPushService pushService, IContactsService contactsService, IUploadFileManager uploadFileManager, IStickersService stickersService)
            : base(protoService, cacheService, aggregator)
        {
            _updatesService    = updatesService;
            _pushService       = pushService;
            _contactsService   = contactsService;
            _uploadFileManager = uploadFileManager;
            _stickersService   = stickersService;

            AskCommand       = new RelayCommand(AskExecute);
            LogoutCommand    = new RelayCommand(LogoutExecute);
            EditPhotoCommand = new RelayCommand <StorageFile>(EditPhotoExecute);
        }
        public CreateChannelStep1ViewModel(IUploadFileManager uploadManager, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            _uploadManager = uploadManager;

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => Title))
                {
                    NotifyOfPropertyChange(() => PlaceholderText);
                    NotifyOfPropertyChange(() => CanCreateChannel);
                }
            };
        }
Esempio n. 10
0
        public SignUpViewModel(IUploadFileManager fileManager, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            SuppressUpdateStatus = true;

            FileManager = fileManager;
            EventAggregator.Subscribe(this);
            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => FirstName) ||
                    Property.NameEquals(args.PropertyName, () => LastName))
                {
                    NotifyOfPropertyChange(() => CanSignUp);
                }
            };
        }
Esempio n. 11
0
        public ChatDetailsViewModel(IUploadFileManager uploadManager, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            Spans = new List <TimerSpan>
            {
                new TimerSpan(AppResources.Enabled, string.Empty, 0, AppResources.Enabled),
                new TimerSpan(AppResources.HourNominativeSingular, "1", (int)TimeSpan.FromHours(1.0).TotalSeconds, string.Format(AppResources.MuteFor, string.Format("{0} {1}", "1", AppResources.HourNominativeSingular).ToLowerInvariant())),
                new TimerSpan(AppResources.HourGenitivePlural, "8", (int)TimeSpan.FromHours(8.0).TotalSeconds, string.Format(AppResources.MuteFor, string.Format("{0} {1}", "8", AppResources.HourGenitivePlural).ToLowerInvariant())),
                new TimerSpan(AppResources.DayNominativePlural, "2", (int)TimeSpan.FromDays(2.0).TotalSeconds, string.Format(AppResources.MuteFor, string.Format("{0} {1}", "2", AppResources.DayNominativePlural).ToLowerInvariant())),
                new TimerSpan(AppResources.Disabled, string.Empty, int.MaxValue, AppResources.Disabled),
            };
            _selectedSpan = Spans[0];

            _notificationTimer          = new DispatcherTimer();
            _notificationTimer.Interval = TimeSpan.FromSeconds(Constants.NotificationTimerInterval);
            _notificationTimer.Tick    += OnNotificationTimerTick;

            _uploadManager = uploadManager;
            eventAggregator.Subscribe(this);

            DisplayName = LowercaseConverter.Convert(AppResources.Profile);

            Items = new ObservableCollection <TLUserBase>();

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => MuteUntil) &&
                    !_suppressUpdating)
                {
                    UpdateNotifySettingsAsync();
                }

                if (Property.NameEquals(args.PropertyName, () => SelectedSound) &&
                    !_suppressUpdating)
                {
                    NotificationsViewModel.PlaySound(SelectedSound);

                    UpdateNotifySettingsAsync();
                }
            };
        }
Esempio n. 12
0
 public ChannelEditViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUploadFileManager uploadFileManager)
     : base(protoService, cacheService, aggregator, uploadFileManager)
 {
 }
Esempio n. 13
0
 public ChatDetailsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUploadFileManager uploadFileManager)
     : base(protoService, cacheService, aggregator)
 {
     _uploadFileManager = uploadFileManager;
 }
Esempio n. 14
0
        //public ObservableCollection<TLUserBase> Items { get; set; }

        public EditChatViewModel(IUploadFileManager uploadManager, ICacheService cacheService,
                                 ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService,
                                 IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            _uploadManager = uploadManager;

            CurrentItem = StateService.CurrentChat;
            StateService.CurrentChat = null;
            var chat = CurrentItem as TLChat;

            if (chat != null)
            {
                Title = chat.Title.ToString();
            }
            var broadcastChat = CurrentItem as TLBroadcastChat;

            if (broadcastChat != null)
            {
                Title = broadcastChat.Title.ToString();
            }
            var channel = CurrentItem as TLChannel;

            if (channel != null)
            {
                Title = channel.Title.ToString();
                About = channel.About != null?channel.About.ToString() : string.Empty;
            }

            var channel44 = CurrentItem as TLChannel44;

            if (channel44 != null)
            {
                _signMessages = channel44.Signatures;
            }

            var channel68 = CurrentItem as TLChannel68;

            if (channel68 != null)
            {
                _hiddenPrehistory = channel68.HiddenPrehistory;
            }

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => SignMessages))
                {
                    if (channel44 == null)
                    {
                        return;
                    }

                    MTProtoService.ToggleSignaturesAsync(channel44.ToInputChannel(), new TLBool(SignMessages),
                                                         result => Execute.BeginOnUIThread(() =>
                    {
                    }),
                                                         error => Execute.BeginOnUIThread(() =>
                    {
                        Execute.ShowDebugMessage("channels.toggleComments error " + error);
                    }));
                }
                else if (Property.NameEquals(args.PropertyName, () => HiddenPrehistory))
                {
                    if (channel44 == null)
                    {
                        return;
                    }

                    MTProtoService.TogglePreHistoryHiddenAsync(channel44.ToInputChannel(), new TLBool(HiddenPrehistory),
                                                               result => Execute.BeginOnUIThread(() =>
                    {
                        MTProtoService.GetFullChannelAsync(channel44.ToInputChannel(), result2 =>
                        {
                        });
                    }),
                                                               error => Execute.BeginOnUIThread(() =>
                    {
                        Execute.ShowDebugMessage("channels.toggleComments error " + error);
                    }));
                }
            };
        }