Beispiel #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);
        }
Beispiel #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);
            }
        }
Beispiel #3
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);
        }