Esempio n. 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));
        }
        public ExecuteResult <PromotionCollectionResponse> GetPromotionForBanner(GetPromotionBannerListRequest request)
        {
            var page = new PagerRequest(request.Page, request.Pagesize, 40);

            int totalCount;
            var entities = _promotionRepository.Get(page, out totalCount, request.SortOrder, null, PromotionFilterMode.NotTheEnd,
                                                    DataStatus.Normal, true);

            var response = new PromotionCollectionResponse(page, totalCount)
            {
                Promotions = MappingManager.PromotionResponseMapping(entities, request.CoordinateInfo, true)
            };


            var result = new ExecuteResult <PromotionCollectionResponse> {
                Data = response
            };

            return(result);
        }
Esempio n. 3
0
        private ItemsCollectionResponse Get(float version, PagerRequest pagerRequest, Timestamp timestamp, int userid)
        {
            var pager = new PagerRequest(pagerRequest.PageIndex, pagerRequest.PageSize, pagerRequest.PageSize * 2);

            int total1, total2;
            IEnumerable <ItemsInfoResponse> infolist;

            if (version > 2.09)
            {
                var productList = _productRepository.Get(pager, out total1, ProductSortOrder.CreatedDateDesc, new ProductFilter
                {
                    Timestamp     = timestamp,
                    RecommendUser = userid
                });

                var promotionList = _promotionRepository.Get(pager, out total2, PromotionSortOrder.CreatedDateDesc, new PromotionFilter
                {
                    RecommendUser = userid
                });

                infolist = MappingManager.ItemsInfoResponseMapping(productList, promotionList, null, false);
            }
            else
            {
                var productList = _productRepository.GetPagedList(pager, out total1, ProductSortOrder.CreatedDateDesc,
                                                                  timestamp, null, userid, null);

                var promotionList = _promotionRepository.GetPagedList(pager, out total2, PromotionSortOrder.CreatedDateDesc, null, null, null, userid);

                infolist = MappingManager.ItemsInfoResponseMapping(productList, promotionList);
            }

            var data = infolist.OrderByDescending(v => v.CreatedDate).Take(pagerRequest.PageSize).ToList();

            var reponse = new ItemsCollectionResponse(pagerRequest, total1 + total2)
            {
                Items = data
            };

            return(reponse);
        }
Esempio n. 4
0
 public ResultMessage <Promotion> Get(Expression <Func <Promotion, bool> > filter)
 {
     return(_promotionRepository.Get(filter));
 }