Exemple #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);
        }
Exemple #2
0
        public List <DTORecommendation> ShowGroupRecommendations(long groupId)
        {
            GroupUsers group = new GroupUsers();
            string     eventName;

            try { group = GroupUsersDao.Find(groupId); }
            catch (InstanceNotFoundException)
            {
                throw new GroupNotFoundException(groupId);
            }
            List <DTORecommendation> dtoRecommendations = new List <DTORecommendation>();

            try
            {
                List <Recommendation> recomendations = RecommendationDao.FindRecommendationsByGroupId(groupId);

                foreach (var recommedation in recomendations)
                {
                    try { eventName = recommedation.SportEvent.ev_name; }
                    catch (InstanceNotFoundException)
                    {
                        throw new SportEventNotFoundException(groupId);
                    }
                    UserProfile user = UsersProfileDao.Find(recommedation.userId);
                    dtoRecommendations.Add(new DTORecommendation(recommedation.recommendationId, eventName, user.loginName,
                                                                 recommedation.eventId, recommedation.recommendation_text));
                }
            }
            catch (InstanceNotFoundException)
            {
                throw new GroupNotFoundException(groupId);
            }
            return(dtoRecommendations);
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #5
0
        public List <DTOGroups> ShowAllGroups()
        {
            List <GroupUsers> groups = GroupUsersDao.GetAllElements();

            List <DTOGroups> dtoGroups = new List <DTOGroups>();

            foreach (var group in groups)
            {
                UserProfile user = UsersProfileDao.Find(group.gr_owner);
                dtoGroups.Add(new DTOGroups(group.group_usersId, group.gr_name, group.gr_description, group.UsersOnGroup.Count, group.Recommendation.Count));
            }

            return(dtoGroups);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
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.
        }