예제 #1
0
        public async Task <Guid[]> GetUserOrganizations(Guid userId)
        {
            Guid[] memberships = (await OrganizationMemberRepository.GetByUserId(userId)).Select(x => x.OrganizationId).ToArray();

            Guid[] administrations = (await OrganizationAdminRepository.GetByUserId(userId)).Select(x => x.OrganizationId).ToArray();

            Guid[] ownerships = (await OrganizationRepository.GetByOwnerId(userId)).Select(x => x.Id).ToArray();

            return(memberships.Concat(administrations).Concat(ownerships).Distinct().ToArray());
        }
예제 #2
0
        public async Task <bool> RemoveMemberFromOrganization(Guid organizationId, Guid userId)
        {
            OrganizationMember[] memberships = await OrganizationMemberRepository.GetByUserId(userId);

            OrganizationMember membership = memberships.FirstOrDefault(x => x.OrganizationId == organizationId);

            bool success = false;

            if (membership != null)
            {
                success = await OrganizationMemberRepository.Delete(membership.Id);
            }

            return(success);
        }
예제 #3
0
        public async Task <OrganizationMember> AddMemberToOrganization(Guid organizationId, Guid userId)
        {
            OrganizationMember[] memberships = await OrganizationMemberRepository.GetByUserId(userId);

            OrganizationMember membership = memberships.FirstOrDefault(x => x.OrganizationId == organizationId);

            if (membership == null)
            {
                membership = new OrganizationMember {
                    OrganizationId = organizationId, UserId = userId
                };

                membership = await OrganizationMemberRepository.Create(membership);
            }

            return(membership);
        }