Пример #1
0
        public PagingQueryResponse <Product> GetProducts(PagingQueryRequest query)
        {
            var specification = new RetrievableProductSpecification().And(new ProductMatchingInOwnerSpecification(query.UserId));
            var totalCount    = ReadOnlyDataContext.Products.Where(specification.IsSatisfied()).AsNoTracking().Count();

            var result = new PagingQueryResponse <Product>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Products
                              .Where(specification.IsSatisfied())
                              .Include(c => c.ProductPictures)
                              .Include(c => c.Stores)
                              .Include(c => c.ProductBrand)
                              .Include(c => c.ProductTags)
                              .Include(c => c.ProductSizes)
                              .Include(c => c.ProductColors)
                              .Include(c => c.ProductComments)
                              .OrderByDescending(c => c.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }
Пример #2
0
        public PagingQueryResponse <Product> GetDiscountedProductsOfACategory(PagingQueryRequest query, string category, Guid storeId)
        {
            var specification =
                new RetrievableProductSpecification();
            //  .And(new DiscountsMatchingInCategorySpecification(category));

            var totalCount = ReadOnlyDataContext.Products.Where(specification.IsSatisfied()).AsNoTracking().Count();

            var result = new PagingQueryResponse <Product>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Products.
                              Where(specification.IsSatisfied())
                              .Include(c => c.ProductPictures)
                              .Include(c => c.ProductTags)
                              .Include(c => c.ProductSizes)
                              .Include(c => c.ProductColors)
                              .OrderByDescending(c => c.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }
Пример #3
0
        public PagingQueryResponse <Product> GetMostvisitedProducts(PagingQueryRequest query)
        {
            var specification = new RetrievableProductSpecification();
            var totalCount    = ReadOnlyDataContext.Products.Where(specification.IsSatisfied()).AsNoTracking().Count();

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

            return(result);
        }
Пример #4
0
        public PagingQueryResponse <Product> GetProductsBySize(PagingQueryRequest query, string category, string size)
        {
            var specification = new RetrievableProductSpecification().And(new ProductsMatchingInSizeSpecification(category, size));
            var totalCount    = ReadOnlyDataContext.Products.Where(specification.IsSatisfied()).AsNoTracking().Count();

            var result = new PagingQueryResponse <Product>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Products
                              .Where(specification.IsSatisfied())
                              .Include(p => p.ProductSizes.Where(c => c.Name == size))
                              .Include(c => c.ProductPictures)
                              .Include(c => c.ProductBrand)
                              .Include(c => c.ProductTags)
                              .Include(c => c.ProductColors)
                              .OrderByDescending(f => f.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }
Пример #5
0
        public ProducsCountQueryModel GetProducsCount(Guid userId)
        {
            var specification = new RetrievableProductSpecification().And(new ProductMatchingInOwnerSpecification(userId));
            var query         = ReadOnlyDataContext.Products.Where(specification.IsSatisfied()).GroupBy(d => d.IsInactive).Select(d => new
            {
                d.Key,
                Count = d.Count()
            });

            var model = new ProducsCountQueryModel();

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

            return(model);
        }
Пример #6
0
        public PagingQueryResponse <Product> SearchInProducts(PagingQueryRequest query, string category)
        {
            var specification = new RetrievableProductSpecification();
            var totalCount    = ReadOnlyDataContext.Products.Where(specification.IsSatisfied()).AsNoTracking().Count();

            var result = new PagingQueryResponse <Product>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = string.IsNullOrWhiteSpace(query.Keyword)
                ? DataContext.Products.Where(t => t.IsDeleted == false &&
                                             t.ProductCategory.Name == category).ToList()

                   : DataContext.Products.Where(t => t.IsDeleted == false && t.Name.Contains(query.Keyword) &&
                                                t.ProductCategory.Name == category).ToList()
                              .OrderByDescending(f => f.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }