Exemplo n.º 1
0
        public BannersCountQueryModel GetBannerCount(Guid userId)
        {
            var specification = new RetrievableBannerSpecificaion().And(new BannerMatchingInOwnerSpecification(userId));
            var query         = ReadOnlyDataContext.Banners.Where(specification.IsSatisfied()).GroupBy(d => d.IsActive).Select(d => new
            {
                d.Key,
                Count = d.Count()
            });

            var model = new BannersCountQueryModel();

            if (!query.Any())
            {
                return(model);
            }

            var activeBanners = query.SingleOrDefault(x => x.Key == false);

            if (activeBanners != null)
            {
                model.Active = activeBanners.Count;
            }

            var inactiveBanners = query.SingleOrDefault(x => x.Key);

            if (inactiveBanners != null)
            {
                model.Inactive = inactiveBanners.Count;
            }

            return(model);
        }
Exemplo n.º 2
0
        public PagingQueryResponse <Banner> GetActiveBanners(PagingQueryRequest query)
        {
            var specification = new RetrievableBannerSpecificaion().And(new BannersMatchingInActivitySpecification()).And(new BannersMatchingInConfirmedSpecification());
            var totalCount    = ReadOnlyDataContext.Banners.Where(specification.IsSatisfied()).AsNoTracking().Count();

            var result = new PagingQueryResponse <Banner>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Banners.Where(specification.IsSatisfied())
                              .Include(p => p.Picture).OrderByDescending(f => f.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }