Ejemplo n.º 1
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <returns></returns>
        public ActionResult CollocationList(string collocationName, bool isEnabled = true, int pageIndex = 1, int pageSize = 10)
        {
            var memberId = _adminContract.GetMemberId(AuthorityHelper.OperatorId.Value);
            var query    = _memberCollocationContract.MemberCollocations.Where(e => e.MemberId == memberId);

            query = query.Where(e => e.IsEnabled == isEnabled);
            if (!string.IsNullOrEmpty(collocationName) && collocationName.Length > 0)
            {
                query = query.Where(e => e.CollocationName.StartsWith(collocationName));
            }
            string strApiUrl    = ConfigurationHelper.GetAppSetting("ApiUrl");
            var    elementQuery = _memberColloEleContract.MemberColloEles.Where(e => !e.IsDeleted && e.IsEnabled)
                                  .Where(e => !e.ParentId.HasValue);

            var joinQuery = query.Join(elementQuery, m => m.Id, e => e.MemberColloId.Value, (m, e) => new
            {
                m.Id,
                m.IsDeleted,
                m.IsEnabled,
                m.UpdatedTime,
                m.CollocationName,
                ImagePath = strApiUrl + e.ImagePath,
                IsChecked = false
            });
            var list = joinQuery
                       .OrderByDescending(e => e.UpdatedTime)
                       .Skip((pageIndex - 1) * pageSize)
                       .Take(pageSize)
                       .ToList();


            var res = new OperationResult(OperationResultType.Success, string.Empty, new
            {
                pageData = list,
                pageInfo = new PageDto
                {
                    pageIndex  = pageIndex,
                    pageSize   = pageSize,
                    totalCount = joinQuery.Count(),
                }
            });

            return(Json(res, JsonRequestBehavior.AllowGet));
        }