chore
This commit is contained in:
@@ -69,8 +69,11 @@ namespace Atomx.Admin.Controllers
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
var result = new ApiResult<PagingList<Area>>();
|
||||
var list = new PagingList<Area>() { Index = page, Size = size };
|
||||
var result = new ApiResult<PagingList<AreaItem>>();
|
||||
var list = new PagingList<AreaItem>() { Index = page, Size = size };
|
||||
var countries = new List<Country>();
|
||||
var stateProvices = new List<StateProvince>();
|
||||
|
||||
var query = from p in _dbContext.Areas
|
||||
select p;
|
||||
|
||||
@@ -94,7 +97,51 @@ namespace Atomx.Admin.Controllers
|
||||
select p;
|
||||
}
|
||||
list.Count = query.Count();
|
||||
list.Items = query.OrderByDescending(p => p.DisplayOrder).Skip((page - 1) * size).Take(size).ToList();
|
||||
var data = query.OrderByDescending(p => p.DisplayOrder).Skip((page - 1) * size).Take(size).ToList();
|
||||
|
||||
if (search.CountryId > 0)
|
||||
{
|
||||
var country = _dbContext.Countries.SingleOrDefault(p => p.Id == search.CountryId);
|
||||
if (country != null)
|
||||
{
|
||||
countries.Add(country);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var countryIds = data.Select(p => p.CountryId).Distinct().ToList();
|
||||
countries = _dbContext.Countries.Where(p => countryIds.Contains(p.Id)).ToList();
|
||||
}
|
||||
|
||||
if(search.StateProvinceId > 0)
|
||||
{
|
||||
var state = _dbContext.StateProvinces.SingleOrDefault(p => p.Id == search.StateProvinceId);
|
||||
if (state != null)
|
||||
{
|
||||
stateProvices.Add(state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var stateIds = data.Select(p => p.StateProvinceId).Distinct().ToList();
|
||||
stateProvices = _dbContext.StateProvinces.Where(p => stateIds.Contains(p.Id)).ToList();
|
||||
}
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
var model = _mapper.Map<AreaItem>(item);
|
||||
var country = countries.SingleOrDefault(p => p.Id == item.CountryId);
|
||||
if (country != null)
|
||||
{
|
||||
model.CountryName = country.Name;
|
||||
}
|
||||
var state = stateProvices.SingleOrDefault(p => p.Id == item.StateProvinceId);
|
||||
if (state != null)
|
||||
{
|
||||
model.StateProvinceName = state.Name;
|
||||
}
|
||||
list.Items.Add(model);
|
||||
}
|
||||
|
||||
result = result.IsSuccess(list);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user