public async Task <ActionResult <PagedResults <AssetResponse> > > GetAssets([FromQuery] PagingAssetRequest request) { int brandId = Convert.ToInt32(User.FindFirst("BrandId")?.Value); var rs = await _assetsService.GetAsset(request, brandId); return(Ok(rs)); }
public async Task <PagedResults <AssetResponse> > GetAsset(PagingAssetRequest request, int brandId) { List <AssetResponse> list = null; try { List <Asset> assets = null; if (request.StoreId != 0) { assets = await _unitOfWork.Repository <Asset>() .GetAll() .Where(x => x.Name.ToLower() .Contains(request.KeySearch.ToLower()) && x.IsDeleted == false && x.StoreId == request.StoreId).ToListAsync(); } else { var stores = await _unitOfWork.Repository <Store>().GetAll().Where(x => x.BrandId == brandId && x.Status != (int)Status.Deleted && x.Status != (int)Status.Reject && x.Status != (int)Status.NeedApproval).ToListAsync(); assets = await _unitOfWork.Repository <Asset>() .GetAll() .Where(x => x.Name.ToLower() .Contains(request.KeySearch.ToLower()) && x.IsDeleted == false).ToListAsync(); assets = assets.Where(x => stores.AsEnumerable().Any(f => x.StoreId == f.Id)).ToList(); } if (request.TypeAsset != 0) { assets = assets.Where(x => x.Type == (int)request.TypeAsset).ToList(); } IEnumerable <AssetResponse> rs = assets.Select(x => new AssetResponse { Name = x.Name, StoreId = x.StoreId, Id = x.Id, Type = x.Type, IsDeleted = x.IsDeleted, StoreName = x.Store?.Name }).AsEnumerable(); list = PageHelper <AssetResponse> .Sorting(request.SortType, rs, request.ColName); var result = PageHelper <AssetResponse> .Paging(list, request.Page, request.PageSize); return(result); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get Asset Error!!!", e.InnerException?.Message); } }