示例#1
0
        public ApiPageResultModel NewsList([FromUri] PagedSearchModel 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);

                    // 获取指定物业小区id的公告列表
                    IPostBLL postBll = BLLFactory <IPostBLL> .GetBLL("PostBLL");

                    var placeList = owner.UserPlaces.Select(m => m.PropertyPlaceId);
                    Expression <Func <T_Post, bool> > where = u => placeList.Contains(u.PropertyPlaceId) && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && u.PublishedFlag == ConstantParam.PUBLISHED_TRUE;
                    // TODO:此处Content不需要全部返回,待优化
                    var list = postBll.GetPageList(where, "PublishedTime", false, model.PageIndex).Select(s => new
                    {
                        ID           = s.Id,
                        propertyName = s.PropertyPlace.Name,
                        propertyPic  = string.IsNullOrEmpty(s.PropertyPlace.ImgThumbnail) ? "/Images/news_item_default.png" : s.PropertyPlace.ImgThumbnail,
                        pubDate      = s.PublishedTime.ToString(),
                        title        = s.Title
                    }).ToList();
                    resultModel.result = list;
                    resultModel.Total  = postBll.GetList(where).Count();
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }
            return(resultModel);
        }