Exemplo n.º 1
0
        public static void AddRange_List_IsNull()
        {
            // Arrange
            List <int> list = null;

            // Act
            Assert.Throws <ArgumentNullException>(() => ListHelper.AddRange(list, new[] { 1, 2, 3 }));
            Assert.Throws <ArgumentNullException>(() => ListHelper.AddRange(new List <int>(), (IEnumerable <int>)null));

            // Assert
        }
Exemplo n.º 2
0
        public static void AddRange()
        {
            // Arrange
            List <int> list = new List <int>(new[] { 1, 2, 3 });

            // Act
            ListHelper.AddRange(list, new[] { 4, 5, 6 });

            // Assert
            Assert.Equal(6, list.Count);
            Assert.Contains(4, list);
            Assert.Contains(5, list);
            Assert.Contains(6, list);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditAsync(string id, PermissionEditModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            var role = await _context
                       .Roles
                       .Include(r => r.RoleClaims)
                       .FirstOrDefaultAsync(r => r.Name == id);

            if (role == null)
            {
                return(BadRequest());
            }
            role.RoleClaims = new List <ApplicationRoleClaim>();
            var allPermissions = new List <Checkbox>();

            var selectedDepartmentPermissions = viewModel.Department.ReturnSelectedActions();

            ListHelper <Checkbox> .AddRange(allPermissions, selectedDepartmentPermissions);

            var selectedNoticePermissions = viewModel.Notice.ReturnSelectedActions();

            ListHelper <Checkbox> .AddRange(allPermissions, selectedNoticePermissions);


            var selectedLeavePermissions = viewModel.Leave.ReturnSelectedActions();

            ListHelper <Checkbox> .AddRange(allPermissions, selectedLeavePermissions);

            var selectedRolePermissions = viewModel.Role.ReturnSelectedActions();

            ListHelper <Checkbox> .AddRange(allPermissions, selectedRolePermissions);

            var selectedUserPermissions = viewModel.User.ReturnSelectedActions();

            ListHelper <Checkbox> .AddRange(allPermissions, selectedUserPermissions);

            var selectedPermissionForPermissions = viewModel.Permission.ReturnSelectedActions();

            ListHelper <Checkbox> .AddRange(allPermissions, selectedPermissionForPermissions);

            if (viewModel.Mail.IsSelected)
            {
                allPermissions.Add(viewModel.Mail);
            }

            foreach (var permission in allPermissions)
            {
                role.RoleClaims.Add(new ApplicationRoleClaim
                {
                    ClaimType  = CustomClaimType.Permission,
                    ClaimValue = permission.Value
                });
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction("Edit", new
            {
                id = id
            }).WithSuccess(string.Empty, $"permissions for {id} updated"));
        }
Exemplo n.º 4
0
 public static void AddRange <T>(this IList <T> list, IEnumerable <T> collection)
 {
     ListHelper.AddRange(list, collection);
 }