예제 #1
0
 public HttpResponseMessage Index(string key = null, int page = 1, int pageSize = 10)
 {
     var settingCon = new SettingSearchCondition
     {
         Key = key,
         Page = page,
         PageCount = pageSize
     };
     var settingList = _settingService.GetSettingsByCondition(settingCon).Select(a => new SettingModel
     {
         Key = a.Key,
         Value = a.Value
     }).ToList();
     return PageHelper.toJson(settingList);
 }
예제 #2
0
		public int GetSettingCount (SettingSearchCondition condition)
		{
			var query = _settingRepository.Table;
			try
			{
				if (!string.IsNullOrEmpty(condition.Key))
                {
                    query = query.Where(q => q.Key == condition.Key);
                }
				if (!string.IsNullOrEmpty(condition.Value))
                {
                    query = query.Where(q => q.Value == condition.Value);
                }
				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;
			}
		}
예제 #3
0
	    public IQueryable<SettingEntity> GetSettingsByCondition(SettingSearchCondition condition)
		{
			var query = _settingRepository.Table;
			try
			{
				if (!string.IsNullOrEmpty(condition.Key))
                {
                    query = query.Where(q => q.Key == condition.Key);
                }
				if (!string.IsNullOrEmpty(condition.Value))
                {
                    query = query.Where(q => q.Value == condition.Value);
                }
				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 EnumSettingSearchOrderBy.OrderById:
							query = condition.IsDescending?query.OrderByDescending(q=>q.Id):query.OrderBy(q=>q.Id);
							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;
			}
		}