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 long CreateGroup(string groupName, string description, string loginName)
        {
            if (GroupUsersDao.ExistGroupName(groupName))
            {
                throw new GroupAlreadyExistsException(groupName);
            }

            UserProfile userProfile;
            GroupUsers  group;

            try { userProfile = UsersProfileDao.FindByLoginName(loginName); }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }

            group = new GroupUsers
            {
                gr_description = description,
                gr_name        = groupName,
                gr_owner       = userProfile.userId
            };

            GroupUsersDao.Create(group);

            AddUserToGroup(loginName, group.group_usersId);

            return(group.group_usersId);
        }
Example #3
0
        public void DeleteGroup(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)
            {
                GroupUsersDao.Remove(group.group_usersId);
            }
            else
            {
                throw new OnlyOwnerCanDeleteException(user.userId);
            }
        }
Example #4
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);
            }
        }
Example #5
0
        public long AddRecommendation(string loginName, long eventId, List <long> groupsIds, string recomendation_text)
        {
            UserProfile user;

            GroupUsers group;
            SportEvent sportEvent;

            try { user = UsersProfileDao.FindByLoginName(loginName); }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }

            try { sportEvent = SportEventDao.Find(eventId); }
            catch (InstanceNotFoundException)
            {
                throw new SportEventNotFoundException(eventId);
            }

            Recommendation recommendation = new Recommendation
            {
                eventId             = eventId,
                userId              = user.userId,
                publishDate         = DateTime.UtcNow,
                recommendation_text = recomendation_text,
            };

            foreach (long groupId in groupsIds)
            {
                try { group = GroupUsersDao.Find(groupId); }
                catch (InstanceNotFoundException)
                {
                    throw new GroupNotFoundException(groupId);
                }

                recommendation.GroupUsers.Add(group);
                group.Recommendation.Add(recommendation);
                GroupUsersDao.Update(group);
                RecommendationDao.Update(recommendation);
            }

            return(recommendation.recommendationId);
        }
Example #6
0
        public HashSet <DTORecommendation> ShowUserRecommendations(string loginName)
        {
            UserProfile userProfile;

            try { userProfile = UsersProfileDao.FindByLoginName(loginName); }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }
            List <DTOGroupsUser> groupUsers = this.ShowUserGroups(loginName);

            HashSet <DTORecommendation> recommendations = new HashSet <DTORecommendation>(new DTORecommendationComparer());

            List <DTORecommendation> localRecommendations = new List <DTORecommendation>();

            foreach (DTOGroupsUser group in groupUsers)
            {
                localRecommendations = ShowGroupRecommendations(group.group_usersId);
                recommendations.UnionWith(localRecommendations);
            }
            return(recommendations);
        }
Example #7
0
        public List <DTOGroupsUser> ShowUserGroups(string loginName)
        {
            UserProfile user;

            try { user = UsersProfileDao.FindByLoginName(loginName); }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }
            List <GroupUsers>    grupos    = GroupUsersDao.FindGroupUsersByUserId(user.userId);
            List <DTOGroupsUser> dtoGroups = new List <DTOGroupsUser>();

            foreach (var group in grupos)
            {
                UserProfile userOwner = UsersProfileDao.Find(group.gr_owner);
                dtoGroups.Add(new DTOGroupsUser(group.group_usersId, group.gr_name));
            }

            return(dtoGroups);

            //Decolver mejor lista de dtos.
        }