예제 #1
0
 /// <summary>
 /// Gets a C-Access Security group.
 /// </summary>
 /// <param name="groupName">The name of the group to retrieve.</param>
 /// <returns>The security group if found; otherwise, null.</returns>
 public CPGroup GetGroup(string groupName)
 {
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         return(CPGroupFactory.CreateGroup(context.SecurityGroups.FirstOrDefault(g => g.GroupName == groupName)));
     }
 }
예제 #2
0
 /// <summary>
 /// Gets a collection of all C-Access Security groups.
 /// </summary>
 /// <returns>A collection of all C-Access Security groups.</returns>
 public List <CPGroup> GetGroups()
 {
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         return(context.SecurityGroups.AsEnumerable().Select(g => CPGroupFactory.CreateGroup(g)).ToList());
     }
 }
예제 #3
0
 /// <summary>
 /// Gets a list of the groups that a user is in.
 /// </summary>
 /// <param name="username">The name of the user to return a list of groups for.</param>
 /// <returns>A collection containing the names of all the groups that the specified user is in.</returns>
 public List <CPGroup> GetGroupMembership(string username)
 {
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         return((from g in context.SecurityGroups
                 join m in context.SecurityGroupMemberships
                 on g.GroupId equals m.GroupId
                 where m.UserName == username
                 select g).AsEnumerable().Select(g => CPGroupFactory.CreateGroup(g)).ToList());
     }
 }
예제 #4
0
 public CPGroup CreateGroup(string groupName)
 {
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         if (!context.SecurityGroups.Any(g => g.GroupName == groupName))
         {
             SecurityGroup group = new SecurityGroup()
             {
                 GroupName = groupName
             };
             try
             {
                 context.SecurityGroups.AddObject(group);
                 context.SaveChanges();
                 return(CPGroupFactory.CreateGroup(group));
             }
             catch (ConstraintException)
             {
             }
         }
     }
     return(null);
 }