Beispiel #1
0
 public HttpResponseMessage SearchAllBank()
 {
     var bankSearchCon = new BankSearchCondition();
     var bankList = _bankService.GetBanksByCondition(bankSearchCon).Select(p => new
     {
         p.Id,
         p.Codeid,
         p.Addtime
     }).ToList();
     //var bankListCount = _bankService.GetBankCount(bankSearchCon);
     return PageHelper.toJson(new {List = bankList});
 }
Beispiel #2
0
        public IQueryable<BankEntity> GetBanksByCondition(BankSearchCondition condition)
        {
            var query = _bankRepository.Table;
            try
            {
                if (!string.IsNullOrEmpty(condition.Codeid))
                {
                    query = query.Where(q => q.Codeid.Contains(condition.Codeid));
                }
               
                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                if (condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy.Value)
                    {
                        case EnumBankSearchOrderBy.OrderById:
                            query = condition.isDescending ? query.OrderByDescending(q => q.Id) : query.OrderBy(q => q.Id);
                            break;
                        case EnumBankSearchOrderBy.OrderByCodeid:
                            query = condition.isDescending ? query.OrderByDescending(q => q.Codeid) : query.OrderBy(q => q.Codeid);
                            break;
                        case EnumBankSearchOrderBy.OrderByAddtime:
                            query = condition.isDescending ? query.OrderByDescending(q => q.Addtime) : query.OrderBy(q => q.Addtime);
                            break;
                    }
                }
                else
                {
                    query = query.OrderBy(q => q.Id);
                }

                if (condition.Page.HasValue && condition.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1) * condition.PageCount.Value).Take(condition.PageCount.Value);
                }
                return query;
            }
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return null;
            }
        }
Beispiel #3
0
        public HttpResponseMessage SearchBanks(EnumBankSearchOrderBy orderByAll = EnumBankSearchOrderBy.OrderById, bool isDes = true, int page = 1, int pageSize = 10)
        {
            var bankSearchCon = new BankSearchCondition
            {
                Page = Convert.ToInt32(page),
                PageCount = pageSize,
                OrderBy =orderByAll ,
                isDescending =isDes 
            };

            var bankList = _bankService.GetBanksByCondition(bankSearchCon).Select(p => new
            {
                p.Id,
                p.Codeid,
                p.Addtime
            }).ToList();
            var bankListCount = _bankService.GetBankCount(bankSearchCon);
            return PageHelper.toJson(new {List = bankList, Condition = bankSearchCon, totalCount = bankListCount});
        }
Beispiel #4
0
 public int GetBankCount(BankSearchCondition condition)
 {
     var query = _bankRepository.Table;
     try
     {
         if (!string.IsNullOrEmpty(condition.Codeid))
         {
             query = query.Where(q => q.Codeid.Contains(condition.Codeid));
         }
        
         if (condition.Ids != null && condition.Ids.Any())
         {
             query = query.Where(q => condition.Ids.Contains(q.Id));
         }
         return query.Count();
     }
     catch (Exception e)
     {
         _log.Error(e, "数据库操作出错");
         return -1;
     }
 }