Esempio n. 1
0
        public PagedEventsDto GetAllByUser(int userId, int page, int pageSize, string eventName)
        {
            var repoUser = _contextManager.CreateRepositiry <IUserRepo>();
            var user     = repoUser.GetById(userId);

            var repoUserEvents = _contextManager.CreateRepositiry <IEventUserLinkRepo>();
            var listUserEvents = repoUserEvents.GetEventsByUser(user.Id, page, pageSize, eventName);

            var eventListDto = _mapper.Map <List <EventDto> >(listUserEvents);
            var eventIdList  = eventListDto.Select(c => c.Id).ToList();
            var eventLinks   = repoUserEvents.GetCompanyUserLinkListForUser(userId, eventIdList);

            foreach (var oneEvent in eventListDto)
            {
                var thisEventLink = eventLinks.Where(c => c.EventId == oneEvent.Id).FirstOrDefault();
                if (thisEventLink != null)
                {
                    oneEvent.UserRole = thisEventLink.UserEventRole;
                }
            }

            var retDto = new PagedEventsDto()
            {
                Events = eventListDto,
                Paging = new PagingDto()
                {
                    CurrentPage = page,
                    PageSize    = pageSize,
                    TotalItems  = repoUserEvents.GetEventsByUserCount(user.Id)
                }
            };

            return(retDto);
        }
        public PagedEventsDto GetCompanyEvents(int CompanyId, int page, int pageSize)
        {
            _subscriptionService.CheckSubscription(CompanyId);

            var repo = _contextManager.CreateRepositiry <IEventRepo>();

            var data     = repo.GetAllEventsByCompanyId(CompanyId, page, pageSize);
            var eventDto = _mapper.Map <List <EventDto> >(data);

            var retDto = new PagedEventsDto()
            {
                Events = eventDto,
                Paging = new PagingDto()
                {
                    CurrentPage = page,
                    PageSize    = pageSize,
                    TotalItems  = repo.GetAllEventsByCompanyIdCount(CompanyId)
                }
            };

            return(retDto);
        }