/// <summary> /// Gets the current user bookings from the database /// </summary> /// <returns>An <c>await</c>able <see cref="Task"/> that will complete when the /// first set of results are ready</returns> public Task FetchBookings() { var tcs = new TaskCompletionSource <bool>(); _bookingQuery = Query .Select(FlightsResult) .From(DataSource.Database(UserSession.Database)) .Where(UsernameProperty.EqualTo(UserSession.Username)); var retVal = tcs.Task; _cancelToken = _bookingQuery.AddChangeListener(null, (sender, args) => { foreach (var row in args.Rows) { var bookings = row.GetArray("flights"); var eventArgs = new BookingsUpdateEventArgs(EnumerateBookings(bookings)); BookingsChanged?.Invoke(this, eventArgs); } var oldTcs = Interlocked.Exchange(ref tcs, null); oldTcs?.SetResult(true); }); return(retVal); }
protected override void beforeWriteNodeLogic(bool Creating, bool OverrideUniqueValidation) { if (_unableToWriteNodeInvalidUserName()) { throw new CswDniException(CswEnumErrorType.Warning, "Usernames may only contains letters, numbers, underscores, periods and dashes.", "Username contains invalid characters: " + this.Username); } if (UsernameProperty.Text != string.Empty) // case 25616 { UsernameProperty.setReadOnly(value: true, SaveToDb: true); // BZ 5906 } // case 22512 if (Username == ChemSWAdminUsername && _CswNbtResources.CurrentNbtUser != null && _CswNbtResources.CurrentNbtUser.Username != ChemSWAdminUsername && false == (_CswNbtResources.CurrentNbtUser is CswNbtSystemUser)) { throw new CswDniException(CswEnumErrorType.Warning, "The '" + ChemSWAdminUsername + "' user cannot be edited", "Current user (" + _CswNbtResources.CurrentUser.Username + ") attempted to edit the '" + ChemSWAdminUsername + "' user account."); } if (AvailableWorkUnits.Value.Count == 0 && null != CurrentWorkUnitProperty.RelatedNodeId) { AvailableWorkUnits.AddValue(CurrentWorkUnitProperty.RelatedNodeId.ToString()); } }
private string GetUserDocID() { using (var userQuery = QueryBuilder .Select(DocIdResult) .From(DataSource.Database(Database)) .Where(UsernameProperty.EqualTo(Expression.String(Username)))) { var results = userQuery.Execute().ToList(); return(results.FirstOrDefault()?.GetString("id")); } }
private string GetUserDocID() { using (var userQuery = Query .Select(DocIdResult) .From(DataSource.Database(Database)) .Where(UsernameProperty.EqualTo(Username))) { using (var results = userQuery.Run()) { return(results.FirstOrDefault()?.GetString("id")); } } }
set => SetProperty(UsernameProperty, value);
SetValue(UsernameProperty, value);
protected override void afterPopulateProps() { UsernameProperty.SetOnPropChange(OnUserNamePropChange); AvailableWorkUnits.SetOnPropChange(OnAvailableWorkUnitsChange); CurrentWorkUnitProperty.SetOnPropChange(OnCurrentWorkUnitPropertyChange); AccountLocked.SetOnPropChange(onAccountLockedPropChange); AvailableWorkUnits.InitOptions = InitAvailableWorkUnitsOptions; _updateAvailableWorkUnits(); // BZ 6941, 8288 // Set the Default View to use the selected User, rather than the logged in User //DefaultView.User = this; FavoriteViews.User = this; // BZ 8288 // Favorite Actions options should derive from Role's Action Permissions if (_RoleNode != null) { CswCommaDelimitedString NewYValues = new CswCommaDelimitedString(); foreach (CswNbtAction Action in _CswNbtResources.Actions) { if (_CswNbtResources.Permit.can(Action, this) && Action.ShowInList) { NewYValues.Add(Action.DisplayName.ToString()); } } this.FavoriteActions.YValues = NewYValues; } //BZ 9933 if (_CswNbtResources.CurrentNbtUser == null || !_CswNbtResources.CurrentNbtUser.IsAdministrator()) { this.FailedLoginCount.setHidden(value: true, SaveToDb: false); this.AccountLocked.setHidden(value: true, SaveToDb: false); } //case 27793: these are the properties that a user cannot edit -- not even his own if ((null == _CswNbtResources.CurrentNbtUser) || (false == _CswNbtResources.CurrentNbtUser.IsAdministrator())) { this.Role.setReadOnly(true, false); } //case 27793: Prevent non-adminsitrators from editing paswords, except their own if (IsPasswordReadOnly) { this.PasswordProperty.setReadOnly(true, false); } else { this.PasswordProperty.setReadOnly(false, false); } Role.SetOnPropChange(onRolePropChange); DateFormatProperty.SetOnPropChange(onDateFormatPropChange); TimeFormatProperty.SetOnPropChange(onTimeFormatPropChange); //Case 31084: only an administrator can edit other users' profiles if ((null == _CswNbtResources.CurrentNbtUser) || (false == _CswNbtResources.CurrentNbtUser.IsAdministrator() && UserId != _CswNbtResources.CurrentNbtUser.UserId)) { this.Node.setReadOnly(true, false); } }