Exemplo n.º 1
0
        public Result <EmptyResult> AssociateOrganizationUserToGroup(AssociateOrganizationUserToGroupCommand command)
        {
            if (command.OrganizationId <= 0)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidAssociateOrganizationUserToGroupDataError(nameof(command.OrganizationId))));
            }

            if (command.GroupId <= 0)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidAssociateOrganizationUserToGroupDataError(nameof(command.GroupId))));
            }

            if (!groupRepository.GroupExists(command.GroupId, command.OrganizationId))
            {
                return(new Result <EmptyResult>(GroupServiceErrors.GroupNotFoundError()));
            }

            if (groupRepository.OrganizationUserAssociationWithGroupExists(command.GroupId, command.OrganizationUserId, command.OrganizationId))
            {
                return(new Result <EmptyResult>(GroupServiceErrors.AssociationAlreadyExistsError()));
            }

            // want to check allowed user types to prevent non authorized user-types being added to a group
            var orgUserType = organizationUserRepository.GetOrganizationUserType(command.OrganizationUserId, command.OrganizationId);

            if (!orgUserType.HasValue || !command.AllowedUserTypes.Contains(orgUserType.Value))
            {
                return(new Result <EmptyResult>(GroupServiceErrors.OrganizationUserNotFoundError()));
            }

            groupRepository.AssociateOrganizationUserToGroup(command);

            return(new Result <EmptyResult>());
        }
Exemplo n.º 2
0
        public Result <EmptyResult> DisassociateOrganizationUserFromGroup(DisassociateOrganizationUserFromGroupCommand command)
        {
            if (command.OrganizationId <= 0)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidDisassociateOrganizationUserFromGroupDataError(nameof(command.OrganizationId))));
            }

            if (command.GroupId <= 0)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidDisassociateOrganizationUserFromGroupDataError(nameof(command.GroupId))));
            }

            if (!groupRepository.GroupExists(command.GroupId, command.OrganizationId))
            {
                return(new Result <EmptyResult>(GroupServiceErrors.GroupNotFoundError()));
            }

            if (!organizationUserRepository.OrganizationUserExists(command.OrganizationUserId, command.OrganizationId))
            {
                return(new Result <EmptyResult>(GroupServiceErrors.OrganizationUserNotFoundError()));
            }

            var result = groupRepository.DisassociateOrganizationUserFromGroup(command);

            if (!result)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidDisassociateOrganizationUserFromGroupDataError()));
            }

            return(new Result <EmptyResult>());
        }