public IActionResult Get(CatCommodityCriteria criteria, int page, int size) { var data = catComonityService.Paging(criteria, page, size, out int rowCount); var result = new { data, totalItems = rowCount, page, size }; return(Ok(result)); }
public IQueryable <CatCommodityModel> Query(CatCommodityCriteria criteria) { Expression <Func <CatCommodityModel, bool> > query = null; var commodities = Get(); if (commodities == null) { return(null); } var catCommonityGroups = catCommodityGroupService.Get(); IQueryable <CatCommodityModel> results = from com in commodities join grCom in catCommonityGroups on com.CommodityGroupId equals grCom.Id into grpComs from grp in grpComs.DefaultIfEmpty() select new CatCommodityModel { Id = com.Id, Code = com.Code, CommodityNameVn = com.CommodityNameVn, CommodityNameEn = com.CommodityNameEn, CommodityGroupId = com.CommodityGroupId, Note = com.Note, UserCreated = com.UserCreated, DatetimeCreated = com.DatetimeCreated, UserModified = com.UserModified, DatetimeModified = com.DatetimeModified, Active = com.Active, InactiveOn = com.InactiveOn, CommodityGroupNameEn = grp != null ? grp.GroupNameEn : string.Empty, CommodityGroupNameVn = grp != null ? grp.GroupNameVn : string.Empty }; if (criteria.All == null) { query = x => (x.CommodityNameVn ?? "").IndexOf(criteria.CommodityNameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.CommodityNameEn ?? "").IndexOf(criteria.CommodityNameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.CommodityGroupNameEn ?? "").IndexOf(criteria.CommodityGroupNameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.CommodityGroupNameVn ?? "").IndexOf(criteria.CommodityGroupNameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.Code ?? "").IndexOf(criteria.Code ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.Active == criteria.Active || criteria.Active == null); } else { query = x => ((x.CommodityNameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.CommodityNameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.CommodityGroupNameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.CommodityGroupNameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.Code ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) && (x.Active == criteria.Active || criteria.Active == null); } if (results == null) { return(null); } results = results.Where(query); return(results); }
public async Task <IActionResult> ExportCommodityList(CatCommodityCriteria catCommodityCriteria) { Helper helper = new Helper(); var responseFromApi = await HttpServiceExtension.GetDataFromApi(catCommodityCriteria, aPis.CatalogueAPI + Urls.Catelogue.CatCommodityUrl); var dataObjects = responseFromApi.Content.ReadAsAsync <List <CatCommodityModel> >(); var stream = helper.CreateCommoditylistExcelFile(dataObjects.Result); return(new FileHelper().ExportExcel(stream, FilesNames.CommodityList)); }
public List <CatCommodityModel> Paging(CatCommodityCriteria criteria, int page, int size, out int rowsCount) { var data = Query(criteria); if (data == null) { rowsCount = 0; return(null); } List <CatCommodityModel> results = null; rowsCount = data.Count(); data = data.OrderByDescending(x => x.DatetimeModified); if (size > 1) { if (page < 1) { page = 1; } results = data.Skip((page - 1) * size).Take(size).ToList(); } return(results); }
public IActionResult Get(CatCommodityCriteria criteria) { var results = catComonityService.Query(criteria); return(Ok(results)); }