public async Task <IEnumerable <Category> > ListPaginationAsync(CategoriesQuery query) { // AsNoTracking tells EF Core it doesn't need to track changes on listed entities. Disabling entity // tracking makes the code a little faster IQueryable <Category> queryable = _categories .AsNoTracking(); if (!string.IsNullOrEmpty(query.Search)) { queryable = queryable.Where(p => query.Search.Contains(p.Name)); } // Here I apply a simple calculation to skip a given number of items, according to the current page and amount of items per page, // and them I return only the amount of desired items. The methods "Skip" and "Take" do the trick here. if (query.Limit.HasValue && query.Offset.HasValue) { queryable = queryable.Skip(query.Offset.Value) .Take(query.Limit.Value); } return(await queryable.ToListAsync()); }
public int Categories_GetCount(string serializedQuery) { CategoriesQuery query = CategoriesQuery.SerializeHelper.FromXml( serializedQuery, typeof(CategoriesQuery), AllKnownTypes) as CategoriesQuery; return(query.ExecuteScalar <int>()); }
public async Task <CategoriesResponse> GetAll() { var categoriesQuery = new CategoriesQuery(); var categoriesResponse = await QueryBus.Execute <CategoriesQuery, CategoriesResponse>(categoriesQuery); return(categoriesResponse); }
protected void EsDataSource1_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e) { ProductsQuery p = new ProductsQuery("p"); CategoriesQuery c = new CategoriesQuery("c"); p.Select(p, c.CategoryName); p.InnerJoin(c).On(p.CategoryID == c.CategoryID); if (e.PrimaryKeys != null) { p.Where(p.ProductID == (int)e.PrimaryKeys[0]); } else { // They want to add a new one, lets do a select that brings back // no records so that our CategoryName column (virutal) will be // present in the underlying record format p.Where(1 == 0); } Products prd = new Products(); prd.Load(p); // load the data (if any) // Assign the Entity e.Entity = prd; }
public async Task <IActionResult> List([FromQuery] CategoriesQuery request) { try { var result = await _service.GetCategories(request); return(Ok(result)); } catch (BusinessLogicException ex) { return(BadRequest(new Response { Status = false, Message = ex.Message })); } catch (Exception e) { return(BadRequest(new Response { Status = false, Message = ErrorMessages.UnkownError })); } }
public async Task <IEnumerable <CategoryServiceResult> > GetCategoriesAsync(CategoriesQuery qp) { try { // Here I list the query result from cache if they exist, but now the data can vary according to the category ID, page and amount of // items per page. I have to compose a cache to avoid returning wrong data. string cacheKey = GetCacheKeyForCategoriesQuery(qp); var entities = await _cache.GetOrCreateAsync(cacheKey, (entry) => { entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1); return(_categoriesRepository.ListPaginationAsync(qp)); }); var models = entities != null && entities.Any() ? _mapper.Map(entities, new List <CategoryServiceResult>()) : new List <CategoryServiceResult>(); return(models); } catch (Exception ex) { _logger?.LogError(ex.ToString()); throw; } }
public async Task <List <Category> > HandleAsync(CategoriesQuery query) { var data = await db.Categories.ToListAsync(); var categories = mapper.Map <List <Category> >(data); return(categories); }
public DbQueryResult Query(CategoriesQuery query) { StringBuilder stringBuilder = new StringBuilder("1=1"); if (!string.IsNullOrEmpty(query.Name)) { stringBuilder.AppendFormat("and Name like '%{0}%' ", query.Name); } return(DataHelper.PagingByRownumber(query.PageIndex, 10000, query.SortBy, query.SortOrder, query.IsCount, "Hishop_Categories", "VoteId", stringBuilder.ToString(), "*")); }
public CategoriesCollection Categories_LoadByDynamic(string serializedQuery) { CategoriesQuery query = CategoriesQuery.SerializeHelper.FromXml( serializedQuery, typeof(CategoriesQuery), AllKnownTypes) as CategoriesQuery; CategoriesCollection coll = new CategoriesCollection(); coll.es.IsLazyLoadDisabled = true; coll.Load(query); return(coll); }
public DbQueryResult Query(CategoriesQuery query) { StringBuilder builder = new StringBuilder("1=1 "); if (!string.IsNullOrEmpty(query.Name)) { builder.AppendFormat("and Name like '%{0}%' ", query.Name); } builder.AppendFormat("and wid = '{0}' ", query.wid); return(DataHelper.PagingByRownumber(query.PageIndex, query.PageSize, query.SortBy, query.SortOrder, query.IsCount, "Hishop_Categories", "CategoryId", builder.ToString(), "*")); }
private string GetCacheKeyForCategoriesQuery(CategoriesQuery query) { string key = CacheKeys.CategoriesList.ToString(); if (!string.IsNullOrEmpty(query.Search)) { key = string.Concat(key, "_", query.Search); } key = string.Concat(key, "_", query.Limit, "_", query.Offset); return(key); }
public CategoriesCollectionProxyStub Categories_QueryForCollection(string serializedQuery) { CategoriesQuery query = CategoriesQuery.SerializeHelper.FromXml( serializedQuery, typeof(CategoriesQuery), AllKnownTypes) as CategoriesQuery; CategoriesCollection coll = new CategoriesCollection(); if (coll.Load(query)) { return(coll); } return(null); }
public CategoriesProxyStub Categories_QueryForEntity(string serializedQuery) { CategoriesQuery query = CategoriesQuery.SerializeHelper.FromXml( serializedQuery, typeof(CategoriesQuery), AllKnownTypes) as CategoriesQuery; Categories obj = new Categories(); if (obj.Load(query)) { return(obj); } return(null); }
protected void EsDataSource1_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e) { ProductsQuery p = new ProductsQuery("P"); CategoriesQuery c = new CategoriesQuery("c"); // All columns from our products table and the CategoryName from the Category table, we really do not // display all of the product fields so I could have selected individual fields out of the products // table p.Select(p, c.CategoryName); p.InnerJoin(c).On(p.CategoryID == c.CategoryID); // We supply the Collection and the Query, because we're letting the grid to auto paging and // auto sorting. Otherwise, we could just load the collection ourselves and only supply the // collection e.Collection = new ProductsCollection(); e.Query = p; }
public IList <CategoryInfo> GetCategoryList(CategoriesQuery query) { IList <CategoryInfo> result = new List <CategoryInfo>(); StringBuilder stringBuilder = new StringBuilder("1=1 "); if (!string.IsNullOrEmpty(query.Name)) { stringBuilder.AppendFormat("and Name like '%{0}%' ", query.Name); } DbCommand sqlStringCommand = base.database.GetSqlStringCommand("SELECT * FROM Hishop_Categories WHERE " + stringBuilder.ToString() + "ORDER BY CategoryId ASC"); using (IDataReader objReader = base.database.ExecuteReader(sqlStringCommand)) { result = DataHelper.ReaderToList <CategoryInfo>(objReader); } return(result); }
public async Task <Response <CategoriesDto> > GetCategories(CategoriesQuery request) { var result = _context.Categories.AsQueryable(); if (!string.IsNullOrEmpty(request.Title)) { result = result.Where(x => x.Title.Contains(request.Title)); } ///pagenating int take = request.PageSize; int skip = (request.PageId - 1) * take; int totalPages = (int)Math.Ceiling(result.Count() / (double)take); var finalResult = result.OrderBy(x => x.Title).Skip(skip).Take(take).AsQueryable(); //---------------- var resultData = new CategoriesDto { Dtos = await finalResult.Select(d => new CategoryDto() { Id = d.Id, Title = d.Title }).ToListAsync(), PageId = request.PageId, PageSize = request.PageSize, Total = await result.CountAsync() }; return(new Response <CategoriesDto> { Data = resultData, Status = true, Message = "success" }); }
public async Task <List <CategoryDto> > Handle(CategoriesQuery request, CancellationToken cancellationToken) { ICollection <Category> result; try { result = await _repository.GetAllAsync(); _logger.LogInformation($"Returning {result.Count} categories."); } catch (Exception e) { _logger.LogError(e.Message); throw; } var resultDto = _mapper.Map <ICollection <CategoryDto> >(result); return(resultDto.ToList()); }
public static IList <CategoryInfo> GetSequenceCategories(string categoryname = "") { IList <CategoryInfo> list = null; if (!string.IsNullOrEmpty(categoryname)) { CategoriesQuery categoriesQuery = new CategoriesQuery(); categoriesQuery.Name = categoryname; list = CatalogHelper.GetCategoryList(categoriesQuery); } else { list = new List <CategoryInfo>(); IEnumerable <CategoryInfo> mainCategories = CatalogHelper.GetMainCategories(); foreach (CategoryInfo item in mainCategories) { list.Add(item); CatalogHelper.LoadSubCategorys(item.CategoryId, list); } } return(list); }
public static IList <CategoryInfo> GetCategoryList(CategoriesQuery query) { return(new CategoryDao().GetCategoryList(query)); }
public CategoriesQueryExecutor(CategoriesQuery query) : base(query) { this.categoriesQuery = query; }
public static DbQueryResult Query(CategoriesQuery query) { return((new CategoryDao()).Query(query)); }
public override async Task <IEnumerable <CategorySmallDto> > HandleAsync(CategoriesQuery query, CancellationToken token) { return(await ProjectTo <CategorySmallDto>(Entities).OrderBy(p => p.Name).ToArrayAsync(token)); }
public async Task <IEnumerable <CategorySmallDto> > CategoriesAsync() { var query = new CategoriesQuery(Dispatcher); return(await query.ExecuteAsync()); }
{/* * public CouchbaseCategoryQuery(IContentQuery<TextContent> contentQuery) * : base(contentQuery) * { * * }*/ public CouchbaseCategoryQuery(CategoriesQuery contentQuery) : base(contentQuery) { this._categoriesQuery = contentQuery; }
public CategoriesQueryExecutor(CategoriesQuery categoriesQuery) { this.CategoriesQuery = categoriesQuery; }
{/* public CouchbaseCategoryQuery(IContentQuery<TextContent> contentQuery) : base(contentQuery) { }*/ public CouchbaseCategoryQuery(CategoriesQuery contentQuery) : base(contentQuery) { this._categoriesQuery = contentQuery; }