public async Task <JsonResult> GetAsync([FromQuery] TownQueryDto condition, int?pageIndex, int?pageSize) { if (pageIndex == null || pageSize == null) { if (condition.AreaNumber != null || condition.Address != null || condition.ChairmanName != null || condition.ContactPhone != null || condition.GovernmentLevel != null || condition.MayorName != null || condition.SecretaryName != null || condition.TownName != null) { var list = _service.Search(condition); return(new JsonResult(new { code = 20000, list })); } var items = await _service.GetAll(); return(new JsonResult(new { code = 20000, items })); } else { var items = await _service.GetPaginationAsync(pageIndex.Value, pageSize.Value); return(new JsonResult(new { code = 20000, items })); } }
public List <Town> Get(TownQueryDto condition) { IQueryable <Town> query = _repository.Query(); if (condition.TownName != null && condition.TownName.Trim() != "") { query = query.Where(town => town.TownName.Contains(condition.TownName)); } if (condition.Address != null && condition.Address.Trim() != "") { query = query.Where(town => town.Address.Contains(condition.Address)); } if (condition.MayorName != null && condition.MayorName.Trim() != "") { query = query.Where(town => town.MayorName.Contains(condition.MayorName)); } if (condition.SecretaryName != null && condition.SecretaryName.Trim() != "") { query = query.Where(town => town.Address.Contains(condition.SecretaryName)); } if (condition.ChairmanName != null && condition.ChairmanName.Trim() != "") { query = query.Where(town => town.ChairmanName.Contains(condition.ChairmanName)); } if (condition.ContactPhone != null && condition.ContactPhone.Trim() != "") { query = query.Where(town => town.ContactPhone.Contains(condition.ContactPhone)); } if (condition.AreaNumber != null && condition.AreaNumber.Trim() != "") { query = query.Where(town => town.AreaNumber.Contains(condition.AreaNumber)); } if (condition.GovernmentLevel != null) { query = query.Where(town => town.GovernmentLevel == condition.GovernmentLevel); } return(query.ToList()); }
public List <Town> Search(TownQueryDto condition) { return(_domain.Get(condition)); }