Example #1
0
        public void AddUserToGroup(string loginName, long groupId)
        {
            UserProfile userProfile;
            GroupUsers  group;

            try { userProfile = UsersProfileDao.FindByLoginName(loginName); }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }
            try { group = GroupUsersDao.Find(groupId); }
            catch (InstanceNotFoundException)
            {
                throw new GroupNotFoundException(groupId);
            }
            if ((group.UsersOnGroup.Contains(userProfile)) || (userProfile.SubscribedGroups.Contains(group)))
            {
                throw new UserAlreadyInGroupException(loginName);
            }
            else
            {
                try
                {
                    group.UsersOnGroup.Add(userProfile);
                    userProfile.SubscribedGroups.Add(group);
                }
                catch (NotSupportedException e)
                {
                    throw new InternalProblemException(e);
                }
            }
            GroupUsersDao.Update(group);
            UsersProfileDao.Update(userProfile);
        }
Example #2
0
        public void AbandonGroup(string loginName, long groupId)
        {
            UserProfile user;
            GroupUsers  group;

            try { user = UsersProfileDao.FindByLoginName(loginName); }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }
            try { group = GroupUsersDao.Find(groupId); }
            catch (InstanceNotFoundException)
            {
                throw new GroupNotFoundException(groupId);
            }

            if (user.userId == group.gr_owner)
            {
                throw new OwnerGroupAbandonException(groupId, loginName);
            }
            else
            {
                user.GroupUsers.Remove(group);
                group.UsersOnGroup.Remove(user);

                UsersProfileDao.Update(user);
                GroupUsersDao.Update(group);
            }
        }