public static PermissionResult CanAddHeader(MainContext context, AgendaHeader header, IEnumerable <AgendaHeader> headers) { if (header == null) { throw new ArgumentNullException(nameof(header)); } if (headers == null) { throw new ArgumentNullException(nameof(headers)); } var result = Validator.ValidateNotEmpty(header.Name, @"HeaderNameIsRequired"); if (result != PermissionResult.Allow) { return(result); } var name = (header.Name ?? string.Empty).Trim(); foreach (var h in headers) { if (h.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) { return(PermissionResult.Deny(@"HeaderWithTheSameNameAlreadyExists")); } } var values = GetData(context); //context.Log(nameof(IsAgendaHeaderExists), LogLevel.Info); if (IsAgendaHeaderExists(values, name)) { return(PermissionResult.Deny(@"HeaderWithTheSameNameAlreadyExists")); } var date = header.DateTime.Date; //context.Log(nameof(IsDateExists), LogLevel.Info); if (IsDateExists(values, date)) { return(PermissionResult.Deny(@"HeaderWithTheSameDateAlreadyExists")); } // TODO : Parameter ??? if (date < DateTime.Today.AddDays(-30)) { return(PermissionResult.Confirm(@"HeaderDateConfirmTooOld")); } return(PermissionResult.Allow); }
public PermissionResult CanChangeStartTime(Activity activity, DateTime dateTime) { if (activity == null) { throw new ArgumentNullException(nameof(activity)); } if (activity.Details == string.Empty) { return(PermissionResult.Deny(@"CannotChangeDateOfServerActivity")); } if (activity.Details == @"???") { return(PermissionResult.Confirm(@"OutsideOfWorkingHours")); } return(PermissionResult.Allow); }
public PermissionResult CanAdd(Login login) { if (login == null) { throw new ArgumentNullException("login"); } // Trim the username var username = (login.Username ?? string.Empty).Trim(); if (this.IsSystem(login)) { return(PermissionResult.Deny(this.Settings.UsernameIsReservedForInternalUseMsg)); } // Check for duplicate username // Check in the database ?!?? Do we need the field ?! foreach (var current in _logins) { if (current.Username.Equals(username, StringComparison.OrdinalIgnoreCase)) { return(PermissionResult.Deny(this.Settings.UsernameAlreadyTakenMsg)); } } // Check password strength var strength = GetPasswordStrength(login.Password); switch (strength) { case PasswordStrength.Weak: return(PermissionResult.Deny(this.Settings.PasswordTooWeakMsg)); case PasswordStrength.Medium: return(PermissionResult.Confirm(this.Settings.ConfirmPasswordMediumStrengthMsg)); case PasswordStrength.Good: case PasswordStrength.Strong: return(PermissionResult.Allow); default: throw new ArgumentOutOfRangeException(); } }