public MGGroup GetGroup(int id)
        {
            MGGroup         result      = null;
            GroupOperations groupHelper = null;

            try {
                groupHelper = new GroupOperations(Lcf);
                result      = groupHelper.GetGroup(id);
                if (result == null)
                {
                    Logger.LogWarning("Null Group found in the database for group ID = " + id.ToString());
                }
            } catch (Exception ex) {
                Logger.LogError(5, "Error getting a group given its ID from database at: " + ex);
                return(null);
            } finally {
                if (groupHelper != null)
                {
                    groupHelper.Finish();
                }
            }
            return(result);
        }
        public MGGroup GetGroup(string name)
        {
            MGGroup         result      = null;
            GroupOperations groupHelper = null;

            Logger.Log("Start getting a group from databas where name of group is '" + name + "'.");
            try {
                groupHelper = new GroupOperations(Lcf);
                result      = groupHelper.GetGroup(name);
                if (result == null)
                {
                    Logger.LogWarning("Null Group found in the database for group Name = " + name);
                }
            } catch (Exception ex) {
                Logger.LogError(5, "Error getting a group from databas where name of group is '" + name + "'." + "at: " + ex);
                return(null);
            } finally {
                if (groupHelper != null)
                {
                    groupHelper.Finish();
                }
            }
            return(result);
        }
Esempio n. 3
0
        public List <MGGroup> GetUserGroups(MGUser user, bool isFilterOutSuperGroup)
        {
            if (user == null)
            {
                Logger.LogError(5, "Cannot GetUserGroups for NULL user!");
                return(null);
            }
            else if (user.ID < 1)
            {
                Logger.LogError(5, "Cannot GetUserGroups for invalid user.ID (" + user.ID + ")!");
                return(null);
            }

            List <MGGroup> userGroups = null;

            UserOperations  userHelper  = null;
            GroupOperations groupHelper = null;

            try
            {
                userHelper = new UserOperations(Lcf);

                List <int> userGroupIDs = userHelper.GetUserGroupsIDs(user.ID);
                if (userGroupIDs == null)
                {
                    Logger.LogError(5, "Cannot GetUserGroups as retrieved NULL list of userGroupIDs for user.ID (" + user.ID + ")!");
                    return(null);
                }

                userGroups = new List <MGGroup>(userGroupIDs.Count);

                groupHelper = new GroupOperations(Lcf);
                MGGroup group;
                foreach (int groupID in userGroupIDs)
                {
                    if (groupID < 1)
                    {
                        Logger.LogError(5, "Invalid groupID detected, skipping it ...");
                        continue;
                    }

                    group = groupHelper.GetGroup(groupID);
                    if (group == null)
                    {
                        Logger.LogError(5, "NULL MGGroup detected, skipping it ...");
                        continue;
                    }

                    if (isFilterOutSuperGroup)
                    {
                        if (group.Name != null && group.Name.Equals(GroupAdministration.SUPER_USER_GROUP_NAME, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                    }

                    userGroups.Add(group);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(5, "Failure getting UserGroups for user.ID (" + user.ID + ") at " + ex.StackTrace);
                return(null);
            }
            finally
            {
                if (userHelper != null)
                {
                    userHelper.Finish();
                }
                if (groupHelper != null)
                {
                    groupHelper.Finish();
                }
            }

            return(userGroups);
        }