public ApiPageResultModel ShopList([FromUri] ShopSearchModel model)
        {
            ApiPageResultModel resultModel = new ApiPageResultModel();

            try
            {
                //根据用户ID查找业主
                IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

                T_User owner = ownerBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                //如果业主存在
                if (owner != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > owner.TokenInvalidTime || model.Token != owner.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    owner.LatelyLoginTime  = DateTime.Now;
                    owner.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    ownerBll.Update(owner);

                    IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                    Expression <Func <T_Shop, bool> > where = u => u.Type.Contains(model.Type.ToString());
                    //如果是生活小卖店或五金店
                    if (model.Type == 2 || model.Type == 3)
                    {
                        var placeList = owner.UserPlaces.Select(m => m.PropertyPlaceId);
                        where = PredicateBuilder.And(where, u => u.ShopPlaces.Count(p => placeList.Contains(p.PropertyPlaceId)) > 0);
                    }
                    resultModel.Total  = shopBll.Count(where);
                    resultModel.result = shopBll.GetPageList(where, "Id", false, model.PageIndex).ToList().Select(s => new
                    {
                        Id       = s.Id,
                        ShopName = s.ShopName,
                        Content  = s.MainSale,
                        Phone    = string.IsNullOrEmpty(s.Phone) ? "" : s.Phone,
                        Img      = string.IsNullOrEmpty(s.ImgThumbnail) ? "" : s.ImgThumbnail.Split(';')[0]
                    });
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }
            return(resultModel);
        }
Example #2
0
        public async Task <IActionResult> Search(ShopSearchModel model)
        {
            // Default price and max price.
            var defaultMinPrice = double.Parse(_configuration["Default:MinPrice"]);
            var defaultMaxPrice = double.Parse(_configuration["Default:MaxPrice"]);

            // Get all the default colors to show on the page.
            var defaultColors = await _mediator.Send(new SearchProductAllColorsCommand());

            // Create command for executing searhcing for products.
            var command = new SearchProductCommand(
                model.MinPrice,
                model.MaxPrice,
                model.Colors);

            // Get the result of Search.
            var result = await _mediator.Send(command);

            // Apply sorting out from the selected sorting.
            if (model.SortBy == ShopSearchModel.Sorting.Highest)
            {
                result = result.OrderByDescending(x => x.Inventory.Price).ToList();
            }
            else if (model.SortBy == ShopSearchModel.Sorting.Lowest)
            {
                result = result.OrderBy(x => x.Inventory.Price).ToList();
            }

            // Prepare view model.
            var viewModel = new ShopSearchViewModel()
            {
                DefaultColors   = defaultColors.ToList(),
                DefaultMinPrice = defaultMinPrice,
                DefaultMaxPrice = defaultMaxPrice,

                Colors   = model.Colors ?? defaultColors.Select(x => x.Id).ToList(),
                MaxPrice = model.MaxPrice,
                MinPrice = model.MinPrice,
                Products = result.Select(x => new ShopSearchProductViewModel()
                {
                    Name    = x.Name,
                    Price   = x.Inventory.Price,
                    Picture = x.Picture,
                    Id      = x.Id,
                    Color   = x.Color
                }),
                SortBy = model.SortBy
            };

            return(View("Index", viewModel));
        }
Example #3
0
        public ActionResult ShopList(ShopSearchModel model)
        {
            IShopBLL ShopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

            Expression <Func <T_Shop, bool> > where = u => (string.IsNullOrEmpty(model.ShopName) ? true : u.ShopName.Contains(model.ShopName));
            if (model.Type != null)
            {
                where = PredicateBuilder.And <T_Shop>(where, u => u.Type.Contains(model.Type.Value.ToString()));
            }
            var sortModel = SettingSorting("Id", false);

            model.List     = ShopBll.GetPageList(where, sortModel.SortName, sortModel.IsAsc, model.PageIndex) as PagedList <T_Shop>;
            model.TypeList = GetTypeList();
            return(View(model));
        }