Exemple #1
0
        public ActionResult List(PagerRequest request, PromotionListSearchOption search)
        {
            int totalCount;
            var storeList = new List <int>();

            if (!string.IsNullOrEmpty(search.Store))
            {
                storeList = _storeRepository.Get(s => s.Name.StartsWith(search.Store)).Select(s => s.Id).ToList();
            }

            var linq = _promotionRepository.Get(e => (!search.PId.HasValue || e.Id == search.PId.Value) &&
                                                (string.IsNullOrEmpty(search.Name) || e.Name.ToLower().StartsWith(search.Name.ToLower())) &&
                                                (!search.Status.HasValue || e.Status == (int)search.Status.Value) &&
                                                e.Status != (int)DataStatus.Deleted &&
                                                (string.IsNullOrEmpty(search.Store) || storeList.Any(m => m == e.Store_Id)));

            linq = _authRepo.AuthFilter(linq, CurrentUser.CustomerId, CurrentUser.Role) as IQueryable <PromotionEntity>;
            Func <IQueryable <PromotionEntity>, IOrderedQueryable <PromotionEntity> > orderBy = (IQueryable <PromotionEntity> e) =>
            {
                if (!search.OrderBy.HasValue)
                {
                    return(e.OrderByDescending(o => o.CreatedDate));
                }
                else
                {
                    switch (search.OrderBy.Value)
                    {
                    case GenericOrder.OrderByCreateUser:
                        return(e.OrderByDescending(o => o.CreatedUser));

                    case GenericOrder.OrderByName:
                        return(e.OrderByDescending(o => o.Name));

                    case GenericOrder.OrderByCreateDate:
                    default:
                        return(e.OrderByDescending(o => o.CreatedDate));
                    }
                }
            };

            linq       = orderBy(linq);
            totalCount = linq.Count();

            var skipCount = (request.PageIndex - 1) * request.PageSize;

            linq = skipCount == 0 ? linq.Take(request.PageSize) : linq.Skip(skipCount).Take(request.PageSize);



            var vo = MappingManager.PromotionViewMapping(linq.ToList());

            var v = new PromotionCollectionViewModel(request, totalCount)
            {
                Promotions = vo.ToList()
            };

            ViewBag.SearchOptions = search;
            return(View("List", v));
        }
Exemple #2
0
        public ActionResult List(OrderSearchOption search, PagerRequest request)
        {
            int totalCount;

            search.CurrentUser     = CurrentUser.CustomerId;
            search.CurrentUserRole = CurrentUser.Role;
            var dbContext = _orderRepo.Context;
            var linq      = dbContext.Set <OrderEntity>().Where(p => (string.IsNullOrEmpty(search.OrderNo) || p.OrderNo == search.OrderNo) &&
                                                                (!search.CustomerId.HasValue || p.CustomerId == search.CustomerId.Value) &&
                                                                (!search.Status.HasValue || p.Status == (int)search.Status.Value) &&
                                                                (!search.Store.HasValue || p.StoreId == search.Store.Value) &&
                                                                (!search.Brand.HasValue || p.BrandId == search.Brand.Value) &&
                                                                (!search.FromDate.HasValue || p.CreateDate >= search.FromDate.Value) &&
                                                                (!search.ToDate.HasValue || p.CreateDate <= search.ToDate.Value) &&
                                                                p.Status != (int)DataStatus.Deleted);

            linq = _userAuthRepo.AuthFilter(linq, search.CurrentUser, search.CurrentUserRole) as IQueryable <OrderEntity>;

            var linq2 = linq.Join(dbContext.Set <UserEntity>().Where(u => u.Status != (int)DataStatus.Deleted),
                                  o => o.CustomerId,
                                  i => i.Id,
                                  (o, i) => new { O = o, C = i })
                        .GroupJoin(dbContext.Set <ShipViaEntity>().Where(s => s.Status != (int)DataStatus.Deleted),
                                   o => o.O.ShippingVia,
                                   i => i.Id,
                                   (o, i) => new { O = o.O, C = o.C, S = i.FirstOrDefault() }).OrderByDescending(l => l.O.CreateDate);


            totalCount = linq2.Count();

            var skipCount = (request.PageIndex - 1) * request.PageSize;

            var linq3 = skipCount == 0 ? linq2.Take(request.PageSize) : linq2.Skip(skipCount).Take(request.PageSize);


            var vo = from l in linq3.ToList()
                     select new OrderViewModel().FromEntity <OrderViewModel>(l.O, p =>
            {
                p.ShippingViaMethod = l.S;
                p.Customer          = new CustomerViewModel().FromEntity <CustomerViewModel>(l.C);
            });

            var v = new Pager <OrderViewModel>(request, totalCount)
            {
                Data = vo.ToList()
            };

            ViewBag.SearchOptions = search;
            return(View(v));
        }
        public ActionResult List(ProductSearchOption search, PagerRequest request)
        {
            int totalCount;

            search.CurrentUser     = CurrentUser.CustomerId;
            search.CurrentUserRole = CurrentUser.Role;
            var dbContext = _productRepository.Context;
            var linq      = dbContext.Set <ProductEntity>().Where(p => (!search.PId.HasValue || p.Id == search.PId.Value) &&
                                                                  (string.IsNullOrEmpty(search.Name) || p.Name.StartsWith(search.Name)) &&
                                                                  (!search.User.HasValue || p.CreatedUser == search.User.Value) &&
                                                                  (!search.Status.HasValue || p.Status == (int)search.Status.Value) &&
                                                                  p.Status != (int)DataStatus.Deleted);

            linq = _userAuthRepo.AuthFilter(linq, search.CurrentUser, search.CurrentUserRole) as IQueryable <ProductEntity>;
            if (!string.IsNullOrEmpty(search.Topic) &&
                search.Topic.Trim().Length > 0)
            {
                linq = linq.Where(p => (from s in dbContext.Set <SpecialTopicEntity>()
                                        join ps in dbContext.Set <SpecialTopicProductRelationEntity>() on s.Id equals ps.SpecialTopic_Id
                                        where s.Name.StartsWith(search.Topic) && ps.Product_Id == p.Id
                                        select s).Any());
            }
            if (!string.IsNullOrEmpty(search.Promotion) &&
                search.Promotion.Trim().Length > 0)
            {
                linq = linq.Where(p => (from pr in dbContext.Set <PromotionEntity>()
                                        join ps in dbContext.Set <Promotion2ProductEntity>() on pr.Id equals ps.ProId
                                        where pr.Name.StartsWith(search.Promotion) && ps.ProdId == p.Id
                                        select pr).Any());
            }
            var linq2 = linq.Join(dbContext.Set <StoreEntity>().Where(s => string.IsNullOrEmpty(search.Store) || s.Name.StartsWith(search.Store)), o => o.Store_Id, i => i.Id, (o, i) => new { P = o, S = i })
                        .Join(dbContext.Set <BrandEntity>().Where(b => string.IsNullOrEmpty(search.Brand) || b.Name.StartsWith(search.Brand)), o => o.P.Brand_Id, i => i.Id, (o, i) => new { P = o.P, S = o.S, B = i })
                        .Join(dbContext.Set <UserEntity>(), o => o.P.CreatedUser, i => i.Id, (o, i) => new { P = o.P, S = o.S, B = o.B, C = i })
                        .Join(dbContext.Set <TagEntity>().Where(t => string.IsNullOrEmpty(search.Tag) || t.Name.StartsWith(search.Tag)), o => o.P.Tag_Id, i => i.Id, (o, i) => new { P = o.P, S = o.S, B = o.B, C = o.C, T = i })
                        .GroupJoin(dbContext.Set <PromotionEntity>().Join(_pprRepository.GetAll(),
                                                                          o => o.Id,
                                                                          i => i.ProId,
                                                                          (o, i) => new { Pro = o, ProR = i }),
                                   o => o.P.Id,
                                   i => i.ProR.ProdId,
                                   (o, i) => new { P = o.P, S = o.S, B = o.B, C = o.C, T = o.T, Pro = i })
                        .GroupJoin(dbContext.Set <SpecialTopicEntity>().Join(_stprRepository.GetAll(), o => o.Id, i => i.SpecialTopic_Id, (o, i) => new { Spe = o, SpeR = i }),
                                   o => o.P.Id,
                                   i => i.SpeR.Product_Id,
                                   (o, i) => new { P = o.P, S = o.S, B = o.B, C = o.C, T = o.T, Pro = o.Pro, Spe = i })
                        .GroupJoin(dbContext.Set <ResourceEntity>().Where(r => r.SourceType == (int)SourceType.Product), o => o.P.Id, i => i.SourceId
                                   , (o, i) => new { P = o.P, S = o.S, B = o.B, C = o.C, T = o.T, Pro = o.Pro, Spe = o.Spe, R = i });


            if (!search.OrderBy.HasValue)
            {
                linq2 = linq2.OrderByDescending(l => l.P.CreatedDate);
            }
            else
            {
                switch (search.OrderBy.Value)
                {
                case ProductSortOrder.CreatedUserDesc:
                    linq2 = linq2.OrderByDescending(l => l.C.Nickname).ThenByDescending(l => l.P.CreatedDate);
                    break;

                case ProductSortOrder.SortOrderDesc:
                    linq2 = linq2.OrderByDescending(l => l.P.SortOrder).ThenByDescending(l => l.P.CreatedDate);
                    break;

                case ProductSortOrder.SortByBrand:
                    linq2 = linq2.OrderByDescending(l => l.B.Name).ThenByDescending(l => l.P.CreatedDate);
                    break;

                case ProductSortOrder.CreatedDateDesc:
                    linq2 = linq2.OrderByDescending(l => l.P.CreatedDate);
                    break;
                }
            }
            totalCount = linq2.Count();

            var skipCount = (request.PageIndex - 1) * request.PageSize;

            linq2 = skipCount == 0 ? linq2.Take(request.PageSize) : linq2.Skip(skipCount).Take(request.PageSize);


            var vo = from l in linq2.ToList()
                     select new ProductViewModel().FromEntity <ProductViewModel>(l.P, p => {
                p.StoreName      = l.S.Name;
                p.TagName        = l.T.Name;
                p.BrandName      = l.B.Name;
                p.CreateUserName = l.C.Nickname;
                p.PromotionName  = from pro in l.Pro
                                   select pro.Pro.Name;
                p.PromotionIds = string.Join(",", (from pro in l.Pro
                                                   select pro.Pro.Id.ToString()).ToArray());
                p.TopicName = from top in l.Spe
                              select top.Spe.Name;
                p.TopicIds = string.Join(",", (from top in l.Spe
                                               select top.Spe.Id.ToString()).ToArray());
                p.Resources = l.R.Select(r => new ResourceViewModel().FromEntity <ResourceViewModel>(r));
            });

            var v = new ProductCollectionViewModel(request, totalCount)
            {
                Products = vo.ToList()
            };

            ViewBag.SearchOptions = search;
            return(View(v));
        }