Example #1
0
        public PagingQueryResponse <Discount> GetAllAactiveDiscounts(PagingQueryRequest query, Guid storeId)
        {
            var specification = new RetrievableDiscountSpecification().And(new DiscountsMatchingInActivitySpecification()).And(new DiscountMatchingInStoreSpecification(storeId));
            var totalCount    = ReadOnlyDataContext.Discounts.Where(specification.IsSatisfied()).AsNoTracking().Count();

            var result = new PagingQueryResponse <Discount>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Discounts.
                              Where(specification.IsSatisfied())
                              .OrderByDescending(c => c.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }
Example #2
0
        public DiscountsCountQueryModel GetDiscountsCount(Guid storeId)
        {
            var specification = new RetrievableDiscountSpecification().And(new DiscountMatchingInStoreSpecification(storeId));

            var query = ReadOnlyDataContext.Discounts.Where(specification.IsSatisfied()).GroupBy(d => d.Stopped).Select(d => new
            {
                d.Key,
                Count = d.Count()
            });

            var model = new DiscountsCountQueryModel();

            if (query.Any())
            {
                model.Active   = query.SingleOrDefault(x => x.Key == false).Count;
                model.Inactive = query.SingleOrDefault(x => x.Key).Count;
            }

            return(model);
        }