/// <summary> /// Default contructor /// </summary> /// <param name="dialogService"></param> /// <param name="hotspotClinet"></param> public HotspotUserProfilesViewModel(IDialogService dialogService, IHotspotClient hotspotClinet, IEventAggregator eventAggregator) { _dialogService = dialogService; _hotspotClient = hotspotClinet; _eventAggregator = eventAggregator; Profiles = new ObservableCollection <HotspotUserProfileViewModel>(); // Call Helper methods InitCommands(); SubscribeEvents(); // Refresh the profiles list RefreshCommand.Execute(null); }
/// <summary> /// Default constructor /// </summary> /// <param name="eventAggregator"></param> /// <param name="hotspotClient"></param> public AddMultipleHotspotUsersViewModel(IEventAggregator eventAggregator, IHotspotClient hotspotClient) { UsernameAndPasswordViewModel = new AddMultipleUsersUsernameAndPasswordViewModel(); ProfileAndLimitsViewModel = new AddMultipleHotspotUsersProfileAndLimitsViewModel(); ((DelegateCommand)UsernameAndPasswordViewModel.NextCommand).RaiseCanExecuteChanged(); ProfileAndLimitsViewModel.FinishCommand = new DelegateCommand(() => { eventAggregator.GetEvent <AddMultipleHotspotUsersEvent>().Publish(this); DialogHost.CloseDialogCommand.Execute(null, null); }); ProfileAndLimitsViewModel.RefreshProfilesCommand = new DelegateCommand(async() => ProfileAndLimitsViewModel.Profiles = (await hotspotClient.LoadAllProfilesAsync()).Select(p => p.Name)); ProfileAndLimitsViewModel.RefreshProfilesCommand.Execute(null); }
/// <summary> /// Default constructor /// </summary> /// <param name="dialogService"></param> /// <param name="eventAggregator"></param> /// <param name="hotspotClient"></param> public HotspotUsersViewModel(IDialogService dialogService, IEventAggregator eventAggregator, IHotspotClient hotspotClient) { // Init Private members _dialogService = dialogService; _eventAggregator = eventAggregator; _hotspotClient = hotspotClient; // Init public properties Users = new ObservableCollection <HotspotUserViewModel>(); // Init Commands InitCommands(); // Subscribe events SubcribeEvents(); // Refresh the users list RefreshCommand.Execute(null); }
public AddHotspotUserViewModel(IEventAggregator eventAggregator, IHotspotClient hotspotClient, HotspotUserViewModel userToEdit) : this(eventAggregator, hotspotClient) { if (userToEdit?.Username != null) { IsUpdate = true; } else { return; } OriginalName = userToEdit.Username; _userToEdit = userToEdit; // Set Basic info BasicViewModel.Username = userToEdit.Username; BasicViewModel.Password = userToEdit.Password; // Set the bandwidth limit if there is if (userToEdit.LimitBytesOut.Bytes > 0 || userToEdit.LimitBytesIn.Bytes > 0) { LimitsViewModel.HasBandwidthLimits = true; // Setting LimitBytesOut if (Math.Floor(userToEdit.LimitBytesOut.GigaBytes) > 0) { LimitsViewModel.DownloadType = 2; LimitsViewModel.DownloadAmount = userToEdit.LimitBytesOut.GigaBytes.ToString(CultureInfo.InvariantCulture); } else if (Math.Floor(userToEdit.LimitBytesOut.MegaBytes) > 0) { LimitsViewModel.DownloadType = 1; LimitsViewModel.DownloadAmount = userToEdit.LimitBytesOut.MegaBytes.ToString(CultureInfo.InvariantCulture); } else { LimitsViewModel.DownloadType = 0; LimitsViewModel.DownloadAmount = userToEdit.LimitBytesOut.KiloBytes.ToString(CultureInfo.InvariantCulture); } // Setting LimitBytesIn if (Math.Floor(userToEdit.LimitBytesIn.GigaBytes) > 0) { LimitsViewModel.UploadType = 2; LimitsViewModel.UploadAmount = userToEdit.LimitBytesIn.GigaBytes.ToString(CultureInfo.InvariantCulture); } else if (Math.Floor(userToEdit.LimitBytesIn.MegaBytes) > 0) { LimitsViewModel.UploadType = 1; LimitsViewModel.UploadAmount = userToEdit.LimitBytesIn.MegaBytes.ToString(CultureInfo.InvariantCulture); } else { LimitsViewModel.UploadType = 0; LimitsViewModel.UploadAmount = userToEdit.LimitBytesIn.KiloBytes.ToString(CultureInfo.InvariantCulture); } } // Set time limits LimitsViewModel.HasTimeLimits = !string.IsNullOrEmpty(userToEdit.LimitUptime); var time = Parsers.MikrotikTime.Parse(userToEdit.LimitUptime); if (time != null) { LimitsViewModel.HasTimeLimits = true; LimitsViewModel.TimeLimitDays = time.Days.ToString(); LimitsViewModel.TimeLimitHours = time.Hours.ToString(); LimitsViewModel.TimeLimitMinutes = time.Mintues.ToString(); } LimitsViewModel.Price = userToEdit.Price != null && userToEdit.Price != "free" && Regex.IsMatch(userToEdit.Price, @"^\d+$") ? userToEdit.Price : string.Empty; if (userToEdit.Validity > -1) { LimitsViewModel.Validity = userToEdit.Validity.ToString(); } }
public AddHotspotUserViewModel(IEventAggregator eventAggregator, IHotspotClient hotspotClient) { IsUpdate = false; #region Init Commands // A Command to refresh the list of the user profiles and select the first one if the list count is greater than 0 BasicViewModel.RefreshProfilesCommand = new DelegateCommand(async() => { // Load profiles BasicViewModel.Profiles = (await hotspotClient.LoadAllProfilesAsync()).Select(p => p.Name).ToList(); // Select the first one if (BasicViewModel.Profiles.Count > 0) { BasicViewModel.SelectedProfileIndex = _userToEdit != null ? BasicViewModel.Profiles.IndexOf(_userToEdit.Profile) : 0; } }); // A Command to add the built user LimitsViewModel.FinishCommand = new DelegateCommand(() => { // Init a new user var user = _userToEdit?.UserModel ?? new HotspotUser(); user.Name = BasicViewModel.Username; user.Password = BasicViewModel.Password; // Calculate the profile value user.Profile = BasicViewModel.SelectedProfileIndex >= 0 ? (BasicViewModel.Profiles.Count - 1 >= BasicViewModel.SelectedProfileIndex ? BasicViewModel.Profiles[BasicViewModel.SelectedProfileIndex] : "default") : "default"; // TODO: // Do a record add for the user notes // Set bandwidth limit if (LimitsViewModel.HasBandwidthLimits) { // Array of the common sizes var mul = new long[] { 1024, 1024 * 1024, 1024 * 1024 * 1024 }; // Set the bandwidth limits user.LimitBytesOut = (!string.IsNullOrEmpty(LimitsViewModel.DownloadAmount) ? int.Parse(LimitsViewModel.DownloadAmount) : 0) * mul[LimitsViewModel.DownloadType]; user.LimitBytesIn = (!string.IsNullOrEmpty(LimitsViewModel.UploadAmount) ? int.Parse(LimitsViewModel.UploadAmount) : 0) * mul[LimitsViewModel.UploadType]; } // Set timelimit if the user has set one if (LimitsViewModel.HasTimeLimits) { // Calculate the timelimt using timespan and replace the time span dot with mikrotik "d " symbole var timeLimit = new TimeSpan(!string.IsNullOrEmpty(LimitsViewModel.TimeLimitDays) ? int.Parse(LimitsViewModel.TimeLimitDays) : 0, !string.IsNullOrEmpty(LimitsViewModel.TimeLimitDays) ? int.Parse(LimitsViewModel.TimeLimitDays) : 0, !string.IsNullOrEmpty(LimitsViewModel.TimeLimitDays) ? int.Parse(LimitsViewModel.TimeLimitDays) : 0 ); user.LimitUptime = timeLimit.ToString().Replace(".", "d "); } // Raise the add event User = user; eventAggregator.GetEvent <AddHotspotUserEvent>().Publish(this); // Close the dialog DialogHost.CloseDialogCommand.Execute(null, null); }); #endregion BasicViewModel.RefreshProfilesCommand.Execute(null); }