Пример #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 <TEntity> GetAll(Func <TEntity, bool> expressionQuery, int pageIndex, int pageSize)
        {
            var total = _dbset.AsNoTracking().Count();

            var result = new PagingQueryResponse <TEntity>
            {
                PageSize    = pageSize,
                CurrentPage = pageIndex,
                TotalCount  = total,
                Result      = _dataContext.Set <TEntity>().OrderBy(c => c.CreationDate)
                              .Where(expressionQuery).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList()
            };

            return(result);
        }
Пример #4
0
        public PagingQueryResponse <TEntity> GetAll(ISpecification <TEntity> specification, int pageIndex, int pageSize)
        {
            var total = _dbset.AsNoTracking().Count();

            var result = new PagingQueryResponse <TEntity>
            {
                PageSize    = pageSize,
                CurrentPage = pageIndex,
                TotalCount  = total,
                Result      = _dataContext.Set <TEntity>()
                              .OrderBy(c => c.CreationDate).Where(specification.IsSatisfied())
                              .Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList()
            };

            return(result);
        }
Пример #5
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);
        }
Пример #6
0
        public PagingQueryResponse <Order> GetCancelledOrders(PagingQueryRequest query)
        {
            var specification = new OrderMatchingInOwnerSpecification(query.UserId).And(new OrderMatchingInCancelledStatusSpecification());
            var totalCount    = ReadOnlyDataContext.Orders.Where(specification.IsSatisfied());

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

            return(result);
        }
Пример #7
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);
        }
Пример #8
0
        public PagingQueryResponse <GiftDesk> GetGiftDesks(PagingQueryRequest query)
        {
            var specification = new RetrievableGiftDeskSpecification();
            var totalCount    = ReadOnlyDataContext.GiftDesks.Where(specification.IsSatisfied()).AsNoTracking().Count();

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

            return(result);
        }
Пример #9
0
        public PagingQueryResponse <Payment> GetPaymentHistory(PagingQueryRequest query)
        {
            var specification = new RetrievablePaymentSpecification().And(new PaymentMatchingInOwnerSpecification(query.UserId));
            var totalCount    = ReadOnlyDataContext.Payments.Where(specification.IsSatisfied()).AsNoTracking().Count();

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

            return(result);
        }
Пример #10
0
        public PagingQueryResponse <Favorite> GetUserFavorites(PagingQueryRequest query)
        {
            var totalCount = ReadOnlyDataContext.Favorites.Where(f => f.Users.Any(c => c.Id == query.UserId)).AsNoTracking().Count();

            var result = new PagingQueryResponse <Favorite>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Favorites.
                              Where(f => f.Users.Any(c => c.Id == query.UserId))
                              .Include(f => f.Products)
                              .Include(f => f.Stores)
                              .OrderByDescending(c => c.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }
Пример #11
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);
        }
Пример #12
0
        public PagingQueryResponse <Store> GetInactiveStores(PagingQueryRequest query)
        {
            var specificaion = new StoreMatchingInInactivitySpecification().And(new StoreMatchingInOwnerSpecificaion(query.UserId));
            var totalCount   = DataContext.Stores.AsNoTracking().Count(specificaion.IsSatisfied());

            var result = new PagingQueryResponse <Store>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Stores
                              .Where(specificaion.IsSatisfied())
                              .Include(c => c.Location)
                              .Include(c => c.Pictures)
                              .OrderByDescending(c => c.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }
Пример #13
0
        public PagingQueryResponse <User> GetInactiveUsers(PagingQueryRequest query)
        {
            var specification = new MatchingInInactivityUserSpecification(query.Keyword);
            var totalCount    = ReadOnlyDataContext.Users.Where(specification.IsSatisfied()).AsNoTracking().Count();

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

            return(result);
        }
Пример #14
0
        public PagingQueryResponse <Store> GetDiscountedStores(PagingQueryRequest query)
        {
            //ToDo Scnerio should be completed
            var specificaion = new RetrievableStoreSpecification();
            var totalCount   = ReadOnlyDataContext.Stores.Where(specificaion.IsSatisfied()).AsNoTracking().Count();

            var result = new PagingQueryResponse <Store>
            {
                PageSize    = query.PageSize,
                CurrentPage = query.PageIndex,
                TotalCount  = totalCount,
                Result      = DataContext.Stores
                              .Where(specificaion.IsSatisfied())
                              .Include(c => c.Location)
                              .Include(c => c.Pictures)
                              .OrderByDescending(c => c.CreationDate)
                              .Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList()
            };

            return(result);
        }
Пример #15
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);
        }
Пример #16
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);
        }