Exemplo n.º 1
0
        private async Task <DataAccess.Entities.Role> GetRole(Role role)
        {
            var roleName = GetEnumItemDescription.GetEnumDescription(role);
            var findRole = await _context.RoleRepository.FindByAsync(x => x.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase));

            return(findRole.SingleOrDefault());
        }
        public async Task Delete_Role()
        {
            //Arrange
            var userService = _container.Resolve <IUserService>();
            var user        = await userService.Get(1);

            //Assert
            Assert.Multiple(async() =>
            {
                Assert.DoesNotThrowAsync(async() => await userService.DeleteRole(user, Role.VenueManager));
                var roles = await userService.GetRoles(user.UserName);

                Assert.IsFalse(roles.Any(x => x.Equals(GetEnumItemDescription.GetEnumDescription(Role.VenueManager), StringComparison.OrdinalIgnoreCase)));
            });
        }
Exemplo n.º 3
0
        public async Task DeleteRole(UserDto user, Role role)
        {
            var roles = await GetRoles(user.UserName);

            var deletingRole = GetEnumItemDescription.GetEnumDescription(role);

            if (!roles.Any(x => x.Equals(deletingRole)))
            {
                throw new UserException("User does not has such role");
            }

            var deletingRoleInfo = await GetRole(role);

            var row = await _context.UserRoleRepository.FindByAsync(x => x.RoleId == deletingRoleInfo.Id && x.UserId == user.Id);

            _context.UserRoleRepository.Delete(row.SingleOrDefault());
            await _context.SaveAsync();
        }
Exemplo n.º 4
0
        public async Task AddRole(UserDto user, Role role)
        {
            var roleName = GetEnumItemDescription.GetEnumDescription(role);
            var findRole = await _context.RoleRepository.FindByAsync(x => x.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase));

            var roleRow = findRole.SingleOrDefault();

            if (roleRow is null)
            {
                throw new UserException("Role does not exists");
            }

            _context.UserRoleRepository.Create(new UserRole
            {
                RoleId = roleRow.Id,
                UserId = user.Id
            });
            await _context.SaveAsync();
        }
Exemplo n.º 5
0
 private Role?FindRoleEnumValueByDescription(string str)
 {
     return(Enum.GetValues(typeof(Role)).Cast <Role>().
            Where(x => GetEnumItemDescription.GetEnumDescription(x).Equals(str, StringComparison.OrdinalIgnoreCase))
            .SingleOrDefault());
 }