예제 #1
0
        public ActionResult GoodsSearch(string search, FilterModelDTO filterDto)
        {
            var goods = _goodLogic.Search(search, filterDto);

            var goodViews = _adminHelper.GoodDtoListToGoodAdminViewList(goods);

            if (goodViews.Any())
            {
                return(PartialView(goodViews));
            }
            return(PartialView("SearchNull"));
        }
예제 #2
0
        public ActionResult GoodsSearch(string search, FilterModelDTO filterDto, int page = 1)
        {
            var goods = _goodLogic.Search(search, filterDto);

            var goodViews = Mapper.Map <IEnumerable <GoodDTO>, IEnumerable <GoodViewModel> >(goods);

            var id = User.Identity.GetUserId();

            var user = _clientLogic.Get(id);

            if (user != null)
            {
                foreach (var goodView in goodViews)
                {
                    var dis = (100 - user.Discount) / 100;
                    goodView.PriceWithDiscount = goodView.PriceSale * (decimal)dis;
                }
            }


            //todo: refactor -take goods grop _goodLogic
            int pageSize = 5; // количество объектов на страницу
            IEnumerable <GoodViewModel> goodssPerPages = goodViews.Skip((page - 1) * pageSize).Take(pageSize);
            PageInfo pageInfo = new PageInfo {
                PageNumber = page, PageSize = pageSize, TotalItems = goodViews.Count()
            };
            GoodListViewModel ivm = new GoodListViewModel {
                PageInfo = pageInfo, Goods = goodssPerPages
            };

            if (ivm.Goods.Any())
            {
                return(PartialView(goodViews.ToPagedList(page, pageSize)));
            }

            return(PartialView("SearchNull"));
        }