public async Task <ActionResult <PagedResults <SystemZoneResponse> > > GetSystemZone([FromQuery] SystemZonePagingRequest request) { Guid accountId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier)?.Value); var rs = await _systemZoneService.GetSystemZone(request, accountId); return(Ok(rs)); }
public async Task <PagedResults <SystemZoneResponse> > GetSystemZone(SystemZonePagingRequest request, Guid accountId) { List <SystemZoneResponse> list = null; var systemZoneAcc = await _unitOfWork.Repository <Account>().GetAll().Where(x => x.Id == accountId).Include(x => x.SystemZones).SingleOrDefaultAsync(); try { List <SystemZoneResponse> systemZone = null; if (request.IsMe) { systemZone = systemZoneAcc.SystemZones.Select(x => new SystemZoneResponse { Id = x.Id, CreateDate = x.CreateDate, Geom = x.Geom, ModifyDate = x.ModifyDate, Name = x.Name, IsMySystemZone = true, WardId = x.WardId, }).ToList(); } else { if (request.DistrictId != 0) { var district = await _unitOfWork.Repository <District>().GetAll().Where(x => x.Id == request.DistrictId).FirstOrDefaultAsync(); systemZone = await _unitOfWork.Repository <SystemZone>() .GetAll() .Where(x => x.Name.ToLower() .Contains(request.KeySearch.ToLower()) && district.Geom.Intersects(x.Geom)).Select(x => new SystemZoneResponse { Id = x.Id, CreateDate = x.CreateDate, Geom = x.Geom, ModifyDate = x.ModifyDate, Name = x.Name, IsMySystemZone = IsMySystemZone(systemZoneAcc, x.Id) , WardId = x.WardId }).ToListAsync(); } else { systemZone = await _unitOfWork.Repository <SystemZone>() .GetAll() .Where(x => x.Name.ToLower() .Contains(request.KeySearch.ToLower()) ).Select(x => new SystemZoneResponse { Id = x.Id, CreateDate = x.CreateDate, Geom = x.Geom, ModifyDate = x.ModifyDate, Name = x.Name, IsMySystemZone = IsMySystemZone(systemZoneAcc, x.Id), WardId = x.WardId }).ToListAsync(); } } list = PageHelper <SystemZoneResponse> .Sorting(request.SortType, systemZone.AsEnumerable(), request.ColName); var result = PageHelper <SystemZoneResponse> .Paging(list, request.Page, request.PageSize); return(result); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get System-zone Error!!!", e.InnerException?.Message); } }