public SubscribesViewModel(ServerClient client, MainViewModel mainViewModel) { this.PhonePayNumber = "700"; this.Login = this._settigs.UserSettings.Login; this.UpdateDataCommand = new ReallyCommand(new Action(this.UpdateData)); this.FreezeSubscribeCommand = new ReallyCommand(new Action(this.FreezeSubscribe)); this.CopyQiwiNumberCommand = new ReallyCommand((Action)(() => { Clipboard.SetText(this.PhonePayNumber); this.IsCopyNumber = true; })); this.CopyLoginCommand = new ReallyCommand((Action)(() => { Clipboard.SetText(this.Login); this.IsCopyLogin = true; })); this.PositiveBuyCommand = new ReallyCommand((Action)(async() => { SubscribesViewModel subscribesViewModel = this; if (!subscribesViewModel._client.IsWork) { await subscribesViewModel.ShowErrorDialogAsync((BaseViewModel)subscribesViewModel._mainViewModel, "Вы были отключены. Авторизуйтесь еще раз, что бы выполнить автовход на сайт PositiveBet."); } else { subscribesViewModel.SetPositiveCookie(); if (subscribesViewModel._mainViewModel.IsRowsBrowserTemplate) { subscribesViewModel._mainViewModel.LoadUrlBrowser1(PositibetServerClient.GetPayUrl()); } else if (subscribesViewModel._mainViewModel.ActiveTab == 0) { subscribesViewModel._mainViewModel.LoadUrlBrowser1(PositibetServerClient.GetPayUrl()); } else { subscribesViewModel._mainViewModel.LoadUrlBrowser2(PositibetServerClient.GetPayUrl()); } } })); this._client = client; this._mainViewModel = mainViewModel; this.ExtractInfo(this._settigs.UserSettings.UserAuthData.SubscribeInfo); Task.Factory.StartNew(new Action(this.UpdateTime)); }
private async void FreezeSubscribe() { SubscribesViewModel subscribesViewModel = this; try { if (subscribesViewModel.State == ESubscribeState.Active) { if (await subscribesViewModel.ShowYesOrNoDialogAsync((BaseViewModel)subscribesViewModel._mainViewModel, "Запрос", "Вы точно хотите приостановить подписку?") == MessageDialogResult.Negative) { return; } subscribesViewModel.Loading = true; int num = await subscribesViewModel._client.FreezeSubscreAsync() ? 1 : 0; subscribesViewModel.AddLog(string.Format("{0}frez/{1}", (object)Environment.NewLine, (object)DateTime.Now)); } else { if (await subscribesViewModel.ShowYesOrNoDialogAsync((BaseViewModel)subscribesViewModel._mainViewModel, "Запрос", "Вы точно хотите разморозить подписку?") == MessageDialogResult.Negative) { return; } subscribesViewModel.Loading = true; int num = await subscribesViewModel._client.UnfreezeSubscreAsync() ? 1 : 0; subscribesViewModel.AddLog(string.Format("{0}unfrez/{1}", (object)Environment.NewLine, (object)DateTime.Now)); } Task.Factory.StartNew(new Action(subscribesViewModel.UpdateData)); } catch (Exception ex) { await subscribesViewModel.ShowErrorDialogAsync((BaseViewModel)subscribesViewModel._mainViewModel, "Не смогли " + subscribesViewModel.FreezeString + " подписку" + ex.Message); subscribesViewModel.Loading = false; } }
public async void UpdateData() { SubscribesViewModel subscribesViewModel = this; subscribesViewModel.Loading = true; try { subscribesViewModel.ReloadEnabled = false; subscribesViewModel.Counter = 60; await Task.Factory.StartNew((Action)(() => Thread.Sleep(2000))); PositiveSubscribeInfo subscribesAsync = await subscribesViewModel._client.GetSubscribesAsync(); ESubscribeState state = subscribesViewModel.State; subscribesViewModel.ExtractInfo(subscribesAsync); if (state != subscribesViewModel.State) { if (subscribesViewModel.State == ESubscribeState.Active) { subscribesViewModel._settigs.UserSettings.UserAuthData.SubscribeInfo.IsActive = true; subscribesViewModel._settigs.UserSettings.UserAuthData.SubscribeInfo.IsFreeze = false; } if (subscribesViewModel.State == ESubscribeState.Freeze) { subscribesViewModel._settigs.UserSettings.UserAuthData.SubscribeInfo.IsActive = false; subscribesViewModel._settigs.UserSettings.UserAuthData.SubscribeInfo.IsFreeze = true; } subscribesViewModel._client.UpdateSettings(SettingsHelper.SettingConverter(subscribesViewModel._settigs)); Settings.Save(subscribesViewModel._settigs); } } catch (Exception ex) { await subscribesViewModel.ShowErrorDialogAsync((BaseViewModel)subscribesViewModel._mainViewModel, "Информация о подписках не получена! " + ex.Message); } subscribesViewModel.Loading = false; }