Beispiel #1
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);
        }
Beispiel #2
0
        public ICollection <Recommendation> AddRecommendation(long eventId, ICollection <long> groups, long userId, string description)
        {
            Event e = EventDao.Find(eventId);
            ICollection <Recommendation> recs = new List <Recommendation>();

            foreach (long groupId in groups)
            {
                Recommendation r = RecommendationDao.FindByGroupIdAndEventIdAndUsrId(groupId, userId, eventId);
                if (r != null)
                {
                    r.reason = description;
                    RecommendationDao.Update(r);
                }
                else
                {
                    UserGroup      g   = GroupDao.Find(groupId);
                    UserProfile    u   = UserProfileDao.Find(userId);
                    Recommendation rec = new Recommendation();
                    rec.UserGroup   = g;
                    rec.UserProfile = u;
                    rec.Event       = e;
                    rec.reason      = description;
                    RecommendationDao.Create(rec);
                    recs.Add(rec);
                }
            }
            return(recs);
        }
Beispiel #3
0
        public ICollection <RecommendationDto> FindAllRecommendations()
        {
            ICollection <Recommendation>    rs      = RecommendationDao.GetAllElements();
            ICollection <RecommendationDto> recsDto = new List <RecommendationDto>();

            foreach (Recommendation r in rs)
            {
                recsDto.Add(new RecommendationDto(r, EventDao.Find(r.eventId).name));
            }
            return(recsDto);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public int CountFindGroupRecommendation(long groupId)
        {
            String          clave  = "CountFindRecommendation" + groupId.ToString();
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(5.0);
            object cacheCountRecommendation = (object)cache.Get(clave);
            int    countRecommendation;

            if (cacheCountRecommendation == null)
            {
                countRecommendation = RecommendationDao.CountFindGroupRecommendation(groupId);
                cache.Add(clave, countRecommendation, policy);
            }
            else
            {
                countRecommendation = (int)cacheCountRecommendation;
            }

            return((int)countRecommendation);
        }
Beispiel #6
0
        public ICollection <RecommendationDto> FindGroupRecommendations(long groupId, long userId, int startIndex, int count)
        {
            UserProfile u = UserProfileDao.Find(userId);
            UserGroup   g = GroupDao.Find(groupId);

            if (g.UserProfiles.Contains(u))
            {
                ICollection <Recommendation>    recs    = RecommendationDao.FindByGroupId(groupId, startIndex, count);
                ICollection <RecommendationDto> recsDto = new List <RecommendationDto>();

                foreach (Recommendation r in recs)
                {
                    Event e = EventDao.Find(r.eventId);
                    recsDto.Add(new RecommendationDto(r, e.name));
                }
                return(recsDto);
            }
            else
            {
                throw new Exception();
            }
        }