예제 #1
0
        public void RemoveUserGroup(string username, string group)
        {
            AdGroup refreshedGroup = directoryDataService.groups.Where(it => it.displayName == group).SingleOrDefault();
            var     users          = directoryDataService.users.ToList();

            directoryDataService.DeleteLink(refreshedGroup, "members", users.Single(it => (it.userPrincipalName == username)));
            directoryDataService.SaveChanges();
        }
예제 #2
0
        public void DeleteGroup(string groupname)
        {
            AdGroup group = directoryDataService.groups.Where(it => (it.displayName == groupname)).SingleOrDefault();

            if (group == null)
            {
                return;
            }
            directoryDataService.DeleteObject(group);
            directoryDataService.SaveChanges();
        }
 public ActionResult Create(Group group)
 {
     ValidateGroup(group);
     if (ModelState.IsValid)
     {
         group.mailEnabled = false;
         DirectoryService.AddTogroups(group);
         DirectoryService.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(group);
 }
예제 #4
0
        public void AddUserGroupList(IEnumerable <DtUserGroup> userGroups)
        {
            var users = directoryDataService.users.ToList();

            foreach (var usergroup in userGroups)
            {
                AdGroup refreshedGroup = directoryDataService.groups.Where(it => it.displayName == usergroup.Group).SingleOrDefault();
                if (refreshedGroup == null)
                {
                    continue;
                }
                directoryDataService.AddLink(refreshedGroup, "members", users.Single(it => (it.userPrincipalName == usergroup.AdUsername)));
                directoryDataService.SaveChanges();
            }
        }
예제 #5
0
        public bool IsUserInGroup(string upn, string groupName)
        {
            // Get the Group object.
            AdGroup group = directoryDataService.groups.Where(it => (it.displayName == groupName)).SingleOrDefault();

            if (group == null)
            {
                return(false);
            }

            directoryDataService.LoadProperty(group, "members");

            var currentGroupUsers = group.members.OfType <AdUser>().ToList <AdUser>();

            return(currentGroupUsers.Where(cu => cu.userPrincipalName == upn).SingleOrDefault() != null);
        }
예제 #6
0
        public void CreateGroup(DtGroup dtGroup)
        {
            if (directoryDataService.groups.Where(u => u.displayName == dtGroup.Name).FirstOrDefault() != null)
            {
                return;
            }

            var group = new AdGroup();

            group.displayName  = dtGroup.Name;
            group.mailNickname = dtGroup.MailNickName;
            //make all groups security enabled (i.e. not mailing lists)
            group.securityEnabled = true;
            group.mailEnabled     = false;
            directoryDataService.AddTogroups(group);
            directoryDataService.SaveChanges();
        }
예제 #7
0
        public DummyDataSource()
        {
            this.Groups = new ObservableCollection<Group>();
            for(int i = 0; i < 10; i++)
            {
                var grp = new Group();
                grp.displayName = Guid.NewGuid().ToString();
                grp.description = "my stupid groups desciptions is here";
                this.Groups.Add(grp);
            }

            this.Users = new ObservableCollection<User>();
            for (int i = 0; i < 10; i++)
            {
                var usr = new User();
                usr.displayName = Guid.NewGuid().ToString();

                this.Users.Add(usr);
            }
        }
예제 #8
0
        public void CreateGroupList(IEnumerable <DtGroup> dtGroupList)
        {
            foreach (var dtGroup in dtGroupList)
            {
                if (directoryDataService.groups.Where(gp => gp.displayName == dtGroup.Name).FirstOrDefault() != null)
                {
                    continue;
                }

                var group = new AdGroup();
                group.displayName  = dtGroup.Name;
                group.mailNickname = dtGroup.MailNickName;
                //make all groups security enabled (i.e. not mailing lists)
                group.securityEnabled = true;
                group.mailEnabled     = false;
                directoryDataService.AddTogroups(group);
            }

            directoryDataService.SaveChanges();
        }
 /// <summary>
 /// Validate the Create and Edit requests for presence of values for Required fields.
 /// </summary>
 /// <param name="group"></param>
 private void ValidateGroup(Group group)
 {
     ModelValidationHelper.ValidateStringProperty(ModelState, group.displayName, "DisplayName", "DisplayName is required.");
     ModelValidationHelper.ValidateStringProperty(ModelState, group.mailNickname, "MailNickname", "MailNickname is required.");
     ModelValidationHelper.ValidateProperty(ModelState, group.securityEnabled, "SecurityEnabled", "SecurityEnabled is required.");
 }
예제 #10
0
 public ActionResult Edit(Group group)
 {
     ValidateGroup(group);
     if (ModelState.IsValid)
     {
         // Fetch the group object from the service and overwrite the properties from the updated object
         // we got from the view.
         Group refreshedGroup = DirectoryService.groups.Where(it => (it.objectId == group.objectId)).SingleOrDefault();
         refreshedGroup.displayName = group.displayName;
         refreshedGroup.description = group.description;
         DirectoryService.UpdateObject(refreshedGroup);
         DirectoryService.SaveChanges(SaveChangesOptions.PatchOnUpdate);
         return RedirectToAction("Index");
     }
     return View(group);
 }
 /// <summary>
 /// Helper method for adding an object to groups collection.
 /// </summary>
 /// <param name="group"></param>
 public void AddTogroups(Group group)
 {
     base.AddObject("directoryObjects", group);
 }
예제 #12
0
 public void Init(Group group)
 {
     this.Group = group;
 }