示例#1
0
        private FilterDefinition <Moments> ComposeConditionsFilter(Moments.Citeria criteria)
        {
            // 组合查询条件
            var conditions = new List <FilterDefinition <Moments> >();

            if (!string.IsNullOrEmpty(criteria.UserName))
            {
                conditions.Add(Builders <Moments> .Filter.Eq(x => x.User.NickName, criteria.UserName));
            }
            if (criteria.Type != 0)
            {
                conditions.Add(Builders <Moments> .Filter.Eq(x => x.Type, criteria.Type));
            }
            if (!string.IsNullOrEmpty(criteria.Telphone))
            {
                var userIds = _zdDBContext.UserInfo.Where(x => x.Telphone == criteria.Telphone).Select(x => x.UserId.ToString().ToLower()).ToList();
                if (userIds.Count > 0)
                {
                    conditions.Add(Builders <Moments> .Filter.In(x => x.User.UserId, userIds));
                }
            }
            conditions.Add(Builders <Moments> .Filter.Gte(x => x.CreateDate, criteria.StartDate));
            conditions.Add(Builders <Moments> .Filter.Lte(x => x.CreateDate, criteria.EndDate.AddDays(1)));
            var filter = Builders <Moments> .Filter.Empty;

            if (conditions.Any())
            {
                filter = Builders <Moments> .Filter.And(conditions);
            }
            return(filter);
        }
示例#2
0
        public IEnumerable <Moments> GetMomentsList(Moments.Citeria criteria)
        {
            var fields = MGExt.GetModelFields <Moments>(typeof(Moments.UserInfo)).ToArray();
            var filter = ComposeConditionsFilter(criteria);
            var sorter = Builders <Moments> .Sort.Descending(x => x.CreateDate);

            var moments = _mongoDBBase.FindListByPage(colName, filter, criteria.PageIndex, criteria.PageSize, out long totalCount, fields, sorter);

            criteria.SetProps(x => x.TotalCount = (int)totalCount);
            return(JoinUserInfo(moments));
        }
 public IActionResult GetMomentsList(Moments.Citeria criteria)
 => TryCatch(() => criteria.PageOf(c => _momentsRepo.GetMomentsList(criteria ?? new Moments.Citeria())));