Beispiel #1
0
        public static List <GroupListView> GetGroupListViewsCreatedByUser(ApplicationDbContext db, Guid appUserId)
        {
            List <GroupListView> list = new List <GroupListView>();

            List <Group> allGroupsCreatedByUser = GroupHelpers.GetGroupsCreatedByUser(db, appUserId);

            foreach (Group group in allGroupsCreatedByUser)
            {
                //Get members of the group
                List <GroupMember>         groupMembers     = GroupMemberHelpers.GetMembersForGroup(db, group.GroupId);
                List <GroupMemberListView> groupMembersView = new List <GroupMemberListView>();

                foreach (GroupMember member in groupMembers)
                {
                    string memberName = null;

                    switch (member.Type)
                    {
                    case LevelEnum.User:
                        memberName = AppUserHelpers.GetAppUserName(db, member.ReferenceId);
                        break;

                    case LevelEnum.Branch:
                        memberName = BranchHelpers.GetBranchNameTownPostCode(db, member.ReferenceId);
                        break;

                    case LevelEnum.Company:
                        memberName = CompanyHelpers.GetCompanyNameTownPostCode(db, member.ReferenceId);
                        break;
                    }

                    GroupMemberListView groupMemberListView = new GroupMemberListView()
                    {
                        GroupMember     = member,
                        GroupMemberName = memberName
                    };

                    groupMembersView.Add(groupMemberListView);
                }

                //create view record to add to list of view records
                GroupListView view = new GroupListView();
                view.Group = group;
                view.GroupOriginatorName = AppUserHelpers.GetAppUserName(db, view.Group.GroupOriginatorAppUserId);
                view.Members             = groupMembersView;

                list.Add(view);
            }

            return(list);
        }
Beispiel #2
0
        public static bool IsReferenceInGroup(ApplicationDbContext db, LevelEnum referenceLevel, Guid ofReferenceId, Guid byReferenceId)
        {
            bool inGroup = false;

            //Find groups for byReference
            List <Group> byReferenceGroups = GetGroupsForTypeAndReferenceId(db, referenceLevel, byReferenceId);

            //For each group the, check that the ofReference is not there, else set to inGroup to "Y"
            foreach (Group group in byReferenceGroups)
            {
                //if we find 1 group in which this reference is there then reutrn true and jump out.
                if (GroupMemberHelpers.IsReferenceInGroupForType(db, group.GroupId, referenceLevel, ofReferenceId))
                {
                    return(true);
                }
            }

            return(inGroup);
        }
Beispiel #3
0
        public static List <GroupListView> GetGroupListViewsRelevantToUser(ApplicationDbContext db, Guid appUserId)
        {
            List <GroupListView> list = new List <GroupListView>();

            List <Group> allGroupsRelevantUser = new List <Group>();

            //Get user groups containing this user
            allGroupsRelevantUser = GroupHelpers.GetGroupsForUser(db, appUserId);
            //Get branch groups containing this users branches
            List <Branch> usersBranches = BranchHelpers.GetBranchesForUser(db, appUserId);

            foreach (Branch branch in usersBranches)
            {
                List <Group> groups = GroupHelpers.GetGroupsForTypeAndReferenceId(db, LevelEnum.Branch, branch.BranchId);
                foreach (Group group in groups)
                {
                    allGroupsRelevantUser.Add(group);
                }
            }
            //Get company groups containing this users company
            List <Group> companyGroups = GroupHelpers.GetGroupsForTypeAndReferenceId(db, LevelEnum.Company, CompanyHelpers.GetCompanyForUser(db, appUserId).CompanyId);

            foreach (Group group in companyGroups)
            {
                allGroupsRelevantUser.Add(group);
            }


            foreach (Group group in allGroupsRelevantUser)
            {
                //Get members of the group
                List <GroupMember>         groupMembers     = GroupMemberHelpers.GetMembersForGroup(db, group.GroupId);
                List <GroupMemberListView> groupMembersView = new List <GroupMemberListView>();

                foreach (GroupMember member in groupMembers)
                {
                    string memberName = null;

                    switch (member.Type)
                    {
                    case LevelEnum.User:
                        memberName = AppUserHelpers.GetAppUserName(db, member.ReferenceId);
                        break;

                    case LevelEnum.Branch:
                        memberName = BranchHelpers.GetBranchNameTownPostCode(db, member.ReferenceId);
                        break;

                    case LevelEnum.Company:
                        memberName = CompanyHelpers.GetCompanyNameTownPostCode(db, member.ReferenceId);
                        break;
                    }

                    GroupMemberListView groupMemberListView = new GroupMemberListView()
                    {
                        GroupMember     = member,
                        GroupMemberName = memberName
                    };

                    groupMembersView.Add(groupMemberListView);
                }

                //create view record to add to list of view records
                GroupListView view = new GroupListView();
                view.Group = group;
                view.GroupOriginatorName = AppUserHelpers.GetAppUserName(db, view.Group.GroupOriginatorAppUserId);
                view.Members             = groupMembersView;

                list.Add(view);
            }

            return(list);
        }