Ejemplo n.º 1
0
        public async Task AddToRoleAsync(Employee user, string roleName, CancellationToken cancellationToken)
        {
            var role = (await roles.FetchEmployeeRoleByName(roleName).ConfigureAwait(false))
                       .Ensure(e => e.HasValue, "Role is available")
                       .OnSuccess(e => e.Value);

            if (role.IsFailure)
            {
                throw new InvalidOperationException("Failed to fetch role");
            }

            user.RoleId = role.Value.RoleId;
        }
Ejemplo n.º 2
0
 public async Task <EmployeeRole> FindByNameAsync(string roleName, CancellationToken cancellationToken)
 {
     return((await roles.FetchEmployeeRoleByName(roleName).ConfigureAwait(false))
            .Ensure(e => e.HasValue, "Role is available")
            .OnBoth(e => e.IsFailure
             ? null
             : e.Value.Value));
 }