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); }
//NOTE - SetCompanyButtons, SetBranchButtons, SetUserButtons, must run in that order as the user rely on the branch rely on the company //There is also a check on block as if Block is set then no buttons should be shown for that level downwards. public static ViewButtons SetCompanyButtons(ApplicationDbContext db, ViewButtons buttons, Guid viewItemcompanyId, Guid currentCompanyId) { buttons.CompanyBlockButton = !BlockHelpers.IsReferenceBlocked(db, LevelEnum.Company, viewItemcompanyId, currentCompanyId); //if company block then do not show company and lower add buttons if (!buttons.CompanyBlockButton) { buttons.CompanyAddFriendButton = buttons.CompanyBlockButton; buttons.CompanyAddToGroupButton = buttons.CompanyBlockButton; } else { buttons.CompanyAddFriendButton = !FriendHelpers.IsReferenceAnActiveFriendRequest(db, LevelEnum.Company, viewItemcompanyId, currentCompanyId); buttons.CompanyAddToGroupButton = !GroupHelpers.IsReferenceInGroup(db, LevelEnum.Company, viewItemcompanyId, currentCompanyId); } return(buttons); }
public static List <GroupViewModel> GetGroupsViewContainingOrg(ApplicationDbContext db, EntityStatusEnum memberStatus, IPrincipal user) { List <GroupViewModel> groupsViewContainingOrg = new List <GroupViewModel>(); //get organisation from User Organisation organisation = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetOrganisationIdFromUser(db, user)); //get list of groups containing this organisation List <Group> groupsContainingOrg = GroupHelpers.GetGroupsContainingOrg(db, organisation.OrganisationId, memberStatus); //build view foreach (Group group in groupsContainingOrg) { //Build members view for this group (NOTE, this will not be added to for this list as this is just a list of groups we are part of, no need currently to show the members. List <GroupMemberViewModel> membersView = new List <GroupMemberViewModel>(); //If we do need to show the members then change this to "List<GroupMemberViewModel> membersView = GroupMembersViewHelpers.GetGroupMembersViewForGroup(db, group.GroupId);" //Build objects of guid details AppUser recordChangedBy = AppUserHelpers.GetAppUser(db, group.RecordChangeBy); AppUser groupOriginatorAppUser = AppUserHelpers.GetAppUser(db, group.GroupOriginatorAppUserId); Organisation groupOriginatorOrganisation = OrganisationHelpers.GetOrganisation(db, group.GroupOriginatorOrganisationId); //Build group view GroupViewModel groupView = new GroupViewModel() { GroupId = group.GroupId, Name = group.Name, InviteLevel = group.InviteLevel, VisibilityLevel = group.VisibilityLevel, AcceptanceLevel = group.AcceptanceLevel, EntityStatus = group.EntityStatus, RecordChange = group.RecordChange, RecordChangeOn = group.RecordChangeOn, RecordChangeBy = recordChangedBy, GroupOriginatorAppUser = groupOriginatorAppUser, GroupOriginatorOrganisation = groupOriginatorOrganisation, GroupOriginatorDateTime = group.GroupOriginatorDateTime, GroupMembers = membersView }; groupsViewContainingOrg.Add(groupView); } return(groupsViewContainingOrg); }
public static List <GroupViewModel> GetGroupsViewCreatedByOrg(ApplicationDbContext db, IPrincipal user) { List <GroupViewModel> groupsViewCreatedByOrg = new List <GroupViewModel>(); //get organisation from User Organisation organisation = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetOrganisationIdFromUser(db, user)); //get list of groups created by this organisation List <Group> groupsCreatedByOrg = GroupHelpers.GetGroupsCreatedByOrg(db, organisation.OrganisationId); //build view foreach (Group group in groupsCreatedByOrg) { //Build members view for this group List <GroupMemberViewModel> membersView = GroupMembersViewHelpers.GetGroupMembersViewForGroup(db, group.GroupId); //Build objects of guid details AppUser recordChangedBy = AppUserHelpers.GetAppUser(db, group.RecordChangeBy); AppUser groupOriginatorAppUser = AppUserHelpers.GetAppUser(db, group.GroupOriginatorAppUserId); Organisation groupOriginatorOrganisation = OrganisationHelpers.GetOrganisation(db, group.GroupOriginatorOrganisationId); //Build group view GroupViewModel groupView = new GroupViewModel() { GroupId = group.GroupId, Name = group.Name, InviteLevel = group.InviteLevel, VisibilityLevel = group.VisibilityLevel, AcceptanceLevel = group.AcceptanceLevel, EntityStatus = group.EntityStatus, RecordChange = group.RecordChange, RecordChangeOn = group.RecordChangeOn, RecordChangeBy = recordChangedBy, GroupOriginatorAppUser = groupOriginatorAppUser, GroupOriginatorOrganisation = groupOriginatorOrganisation, GroupOriginatorDateTime = group.GroupOriginatorDateTime, GroupMembers = membersView }; groupsViewCreatedByOrg.Add(groupView); } return(groupsViewCreatedByOrg); }
public static ViewButtons SetUserButtons(ApplicationDbContext db, ViewButtons buttons, Guid viewItemUserId, Guid currentUserId) { //if the button is hidden at branch level then hide at user level if (!buttons.BranchBlockButton) { buttons.UserBlockButton = buttons.BranchBlockButton; } else { buttons.UserBlockButton = !BlockHelpers.IsReferenceBlocked(db, LevelEnum.User, viewItemUserId, currentUserId); } //If user block then do not show user buttons if (!buttons.UserBlockButton) { buttons.UserAddFriendButton = buttons.UserBlockButton; buttons.UserAddToGroupButton = buttons.UserBlockButton; } else { if (!buttons.BranchAddFriendButton) { buttons.UserAddFriendButton = buttons.BranchAddFriendButton; } else { buttons.UserAddFriendButton = !FriendHelpers.IsReferenceAnActiveFriendRequest(db, LevelEnum.User, viewItemUserId, currentUserId); } if (!buttons.BranchAddToGroupButton) { buttons.UserAddToGroupButton = buttons.BranchAddToGroupButton; } else { buttons.UserAddToGroupButton = !GroupHelpers.IsReferenceInGroup(db, LevelEnum.User, viewItemUserId, currentUserId); } } return(buttons); }
public static ViewButtons SetBranchButtons(ApplicationDbContext db, ViewButtons buttons, Guid viewItemBranchId, Guid currentBranchId) { //if the button is hidden at company level then hide at branch level if (!buttons.CompanyBlockButton) { buttons.BranchBlockButton = buttons.CompanyBlockButton; } else { buttons.BranchBlockButton = !BlockHelpers.IsReferenceBlocked(db, LevelEnum.Branch, viewItemBranchId, currentBranchId); } //if branch block then do not show branch and lower add buttons if (!buttons.BranchBlockButton) { buttons.BranchAddFriendButton = buttons.BranchBlockButton; buttons.BranchAddToGroupButton = buttons.BranchBlockButton; } else { if (!buttons.CompanyAddFriendButton) { buttons.BranchAddFriendButton = buttons.CompanyAddFriendButton; } else { buttons.BranchAddFriendButton = !FriendHelpers.IsReferenceAnActiveFriendRequest(db, LevelEnum.Branch, viewItemBranchId, currentBranchId); } if (!buttons.CompanyAddToGroupButton) { buttons.BranchAddToGroupButton = buttons.CompanyAddToGroupButton; } else { buttons.BranchAddToGroupButton = !GroupHelpers.IsReferenceInGroup(db, LevelEnum.Branch, viewItemBranchId, currentBranchId); } } return(buttons); }
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); }