private void ThrowIfFound(string contributorId, AppContributorPermission permission, Func <string> message) { if (contributors.TryGetValue(contributorId, out var currentPermission) && currentPermission == permission) { var error = new ValidationError("Contributor is already part of the app with same permissions.", "ContributorId"); throw new ValidationException(message(), error); } }
public void Assign(string contributorId, AppContributorPermission permission) { string Message() => "Cannot assign contributor"; ThrowIfFound(contributorId, permission, Message); ThrowIfNoOwner(c => c[contributorId] = permission, Message); contributors[contributorId] = permission; }
public static AppPermission ToAppPermission(this AppContributorPermission contributorPermission) { Guard.Enum(contributorPermission, nameof(contributorPermission)); return((AppPermission)Enum.Parse(typeof(AppPermission), contributorPermission.ToString())); }