Ejemplo n.º 1
0
		public override async Task<string> GetRoleNameAsync(MangoUserRole role, CancellationToken cancellationToken)
		{
			if (role == null)
			{
				throw new ArgumentNullException(nameof(role));
			}

			return await Task.FromResult(role.RoleName);
		}
Ejemplo n.º 2
0
		public override async Task SetRoleNameAsync(MangoUserRole role, string roleName, CancellationToken cancellationToken)
		{
			if (role == null)
			{
				throw new ArgumentNullException(nameof(role));
			}
			await Task.Run(() =>
			{
				role.RoleName = roleName;
			});
		}
Ejemplo n.º 3
0
 public static UserRoleEntity UserRoleM2E(MangoUserRole mangoUserRole)
 {
     if (mangoUserRole == null)
     {
         throw new ArgumentNullException(nameof(mangoUserRole));
     }
     return(new UserRoleEntity
     {
         Id = mangoUserRole.Id,
         RoleName = mangoUserRole.RoleName
     });
 }
Ejemplo n.º 4
0
		public override async Task<string> GetRoleIdAsync(MangoUserRole role, CancellationToken cancellationToken)
		{
			if (role == null)
			{
				throw new ArgumentNullException(nameof(role));
			}
			var userrole = await FindByNameAsync(role.RoleName, cancellationToken);
			if (userrole == null)
			{
				return null;
			}
			return userrole.Id.ToString();
		}
Ejemplo n.º 5
0
		public override async Task<IdentityResult> DeleteAsync(MangoUserRole role, CancellationToken cancellationToken)
		{
			if (role == null)
			{
				throw new ArgumentNullException(nameof(role));
			}
			try
			{
				var userrole = await _userDbContext.MangoUserRoles.Where(r => r.RoleName == role.RoleName).SingleOrDefaultAsync();
				_userDbContext.MangoUserRoles.Remove(userrole);
				await _userDbContext.SaveChangesAsync();
			}
			catch (DbUpdateException e)
			{
				return IdentityResult.Failed(new IdentityError { Description = e.Message });
			}
			return IdentityResult.Success;
		}
Ejemplo n.º 6
0
		public override async Task<IdentityResult> CreateAsync(MangoUserRole role, CancellationToken cancellationToken)
		{
			if (role == null)
			{
				throw new ArgumentNullException(nameof(role));
			}

			try
			{
				UserRoleEntity userRoleEntity = MEConversion.UserRoleM2E(role);
				await _userDbContext.MangoUserRoles.AddAsync(userRoleEntity);
				await _userDbContext.SaveChangesAsync();
			}
			catch (DbUpdateException e)
			{
				return IdentityResult.Failed(new IdentityError { Description = e.Message });
			}
			return IdentityResult.Success;
		}