Exemple #1
0
		public IQueryable<AreaEntity> GetAreasByCondition(AreaSearchCondition condition)
		{
			var query = _areaRepository.Table;
			try
			{
                if (!string.IsNullOrEmpty(condition.Parent_Id))
                {
                    query = query.Where(q => q.Parent.Id.ToString() == condition.Parent_Id);
                }
                if (condition.AdddateBegin.HasValue)
                {
                    query = query.Where(q => q.AddDate>= condition.AdddateBegin.Value);
                }
                if (condition.AdddateEnd.HasValue)
                {
                    query = query.Where(q => q.AddDate < condition.AdddateEnd.Value);
                }
				if (!string.IsNullOrEmpty(condition.Codeid))
                {
                    query = query.Where(q => q.CodeId == condition.Codeid);
                }
				if (!string.IsNullOrEmpty(condition.Name))
                {
                    query = query.Where(q => q.Name.Contains(condition.Name));
                }
                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }

                if (condition.father == true)
                {
                    query = query.Where(q => q.Parent.Id == null);
                }
                if (condition.father == false && condition.fatherid>0)
                {
                    query = query.Where(q => q.Parent.Id == condition .fatherid);
                }
				if(condition.OrderBy.HasValue)
				{
					switch (condition.OrderBy.Value)
                    {
						case EnumAreaSearchOrderBy.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;
			}
		}
Exemple #2
0
		public int GetAreaCount (AreaSearchCondition condition)
		{
			var query = _areaRepository.Table;
			try
			{
				if (condition.AdddateBegin.HasValue)
                {
                    query = query.Where(q => q.AddDate>= condition.AdddateBegin.Value);
                }
                if (condition.AdddateEnd.HasValue)
                {
                    query = query.Where(q => q.AddDate < condition.AdddateEnd.Value);
                }
				if (!string.IsNullOrEmpty(condition.Codeid))
                {
                    query = query.Where(q => q.CodeId == condition.Codeid);
                }
				if (!string.IsNullOrEmpty(condition.Name))
                {
                    query = query.Where(q => q.Name.Contains(condition.Name));
                }
				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;
			}
		}