public IActionResult CatalogsList(CatalogSearchModel searchModel) { Expression <Func <Catalog, bool> > catalogWhere = x => true; if (!searchModel.SearchPhrase.IsNullEmptyOrWhiteSpace()) { catalogWhere = store => store.Name.StartsWith(searchModel.SearchPhrase); } var catalogs = _catalogService.Get(out var totalResults, catalogWhere, catalog => catalog.Id, RowOrder.Ascending, searchModel.Current, searchModel.RowCount); var models = catalogs.Select(x => _modelMapper.Map <CatalogModel>(x)).ToList(); return(R.Success.With("catalogs", models) .WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount) .Result); }
public async Task <ActionResult <IEnumerable <CatalogItemWithToken> > > Search([FromQuery] CatalogSearchModel model) { // read-only! IQueryable <CatalogItem> q = _dbContext.Catalog .AsNoTracking().OrderBy(c => c.Id) .Where(i => i.AvailableResolutions != null && i.AvailableResolutions != ""); // apply filters if (model.Text is not null or "") { q = q.Where(i => i.Title.Contains(model.Text)); } if (model.From > DateTime.MinValue) { q = q.Where(i => i.Uploaded >= model.From.Date); } if (model.To < DateTime.Now) { q = q.Where(i => i.Uploaded < model.To.Date.AddDays(1)); } if (model.Page > 1) { q = q.Skip((model.Page - 1) * MaxPageSize); } q = q.Take(MaxPageSize); var list = await q.ToListAsync(); // produce tokens (& expiry) if needed to if (_settingsService.Settings.UseTokens) { // make it a list with tokens & stuff var toReturn = new List <CatalogItemWithToken>(); DateTime expiry = DateTime.Now.AddMinutes(_settingsService.Settings.TokenExpiry); foreach (var item in list) { var newItem = new CatalogItemWithToken(item); // generate token if needed if (_settingsService.Settings.UseTokens) { newItem.Token = _tokenService.GenerateInternalToken(newItem.FileId, expiry); newItem.TokenExpiry = expiry.Ticks.ToString(); } toReturn.Add(newItem); } return(toReturn); } else { // just map all the data to the right model & return it. return(list.Select(i => new CatalogItemWithToken(i)).ToList()); } }