Example #1
0
        public async Task <ActionResult> AddMembersToGroup(GroupMembership groupMembership)
        {
            if (ModelState.IsValid)
            {
                await _groupManager.AddUserToGroup(groupMembership);

                return(Ok(groupMembership));
            }
            return(BadRequest(ModelState));
        }
        public async Task AddTeacherToGroup()
        {
            Account testaccount = TestAccounts.Teacher();
            bool    result      = await Accounts.Save(testaccount, "Abc123D!");

            Assert.IsTrue(result);

            Group testgroup = new Group(null);

            testgroup.Name = Settings.Default.teacherGroup;
            result         = await GroupManager.AddUserToGroup(testaccount, testgroup);

            Assert.IsTrue(result);

            await Accounts.LoadAccounts(testgroup);

            bool found = false;

            foreach (var account in testgroup.Accounts)
            {
                if (account.UID.Equals("UnitTeacher"))
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found);

            result = await GroupManager.RemoveUserFromGroup(testaccount, testgroup);

            Assert.IsTrue(result);

            await Accounts.LoadAccounts(testgroup);

            found = false;
            foreach (var account in testgroup.Accounts)
            {
                if (account.UID.Equals("UnitTeacher"))
                {
                    found = true;
                    break;
                }
            }
            Assert.IsFalse(found);
        }
Example #3
0
        public async Task <ActionResult> UserGroups(SelectUserGroupsViewModel selGroups)
        {
            if (ModelState.IsValid)
            {
                var userGroups = await GroupManager.GetUserGroups(selGroups.UserId);

                var deletedGroupsIds = selGroups.Groups.Where(group => userGroups.Any(userGroup => userGroup.GroupId == group.GroupId && !group.IsSelected))
                                       .Select(group => group.GroupId);
                var newGroupsIds = selGroups.Groups.Where(group => !userGroups.Any(userGroup => userGroup.GroupId == group.GroupId)).Where(group => group.IsSelected)
                                   .Select(group => group.GroupId);

                await GroupManager.RemoveUserFromGroupAsync(selGroups.UserId, deletedGroupsIds);

                await GroupManager.AddUserToGroup(selGroups.UserId, newGroupsIds);

                return(RedirectToAction("UserList"));
            }
            return(View());
        }