public OperationResponse <PageResult <BasicProductAliasPageQueryCommandOutputDTO> > PageQuery(PageQuery <BasicProductAliasPageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <BasicProductAliasPageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <BasicProductAlias>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.Name.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <BasicProductAlias>().AsQueryable(); var advancedSorting = new List <SortItem <BasicProductAlias> >(); Expression <Func <BasicProductAlias, object> > expression; if (input.Sort.ContainsKey("productName")) { expression = o => o.Product.Name; advancedSorting.Add(new SortItem <BasicProductAlias> { PropertyName = "productName", SortExpression = expression, SortOrder = "desc" }); } var sorting = new SortingDTO <BasicProductAlias>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <BasicProductAlias, BasicProductAliasPageQueryCommandOutputDTO>(predicate, input, sorting, o => new BasicProductAliasPageQueryCommandOutputDTO { Id = o.Id, Name = o.Name, ProductId = o.ProductId, ProductName = o.Product.Name, ProductCategorySizeId = o.ProductCategorySizeId, ProductCategorySize = o.ProductCategorySize.Size, ColorTypeId = o.ColorTypeId, ColorTypeName = o.ColorType.Name, CreatedAt = o.CreatedAt }); } } catch (Exception ex) { result.AddException($"Error getting Basic Product Alias page query", ex); } return(result); }
public OperationResponse <PageResult <CustomerFreightoutPageQueryCommandOutputDTO> > PageQuery(PageQuery <CustomerFreightoutPageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <CustomerFreightoutPageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <CustomerFreightout>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.Customer.Name.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <CustomerFreightout>().AsQueryable(); var advancedSorting = new List <SortItem <CustomerFreightout> >(); Expression <Func <CustomerFreightout, object> > expression; if (input.Sort.ContainsKey("customerName")) { expression = o => o.Customer.Name; advancedSorting.Add(new SortItem <CustomerFreightout> { PropertyName = "customerName", SortExpression = expression, SortOrder = "desc" }); } var sorting = new SortingDTO <CustomerFreightout>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <CustomerFreightout, CustomerFreightoutPageQueryCommandOutputDTO>(predicate, input, sorting, o => new CustomerFreightoutPageQueryCommandOutputDTO { Id = o.Id, CustomerName = o.Customer.Name, Cost = o.Cost, CustomerFreightoutRateTypeId = o.CustomerFreightoutRateTypeId, CustomerId = o.CustomerId, DateFrom = o.DateFrom, DateTo = o.DateTo, SecondLeg = o.SecondLeg, SurchargeHourly = o.SurchargeHourly, SurchargeYearly = o.SurchargeYearly, WProtect = o.WProtect, }); } } catch (Exception ex) { result.AddException($"Error getting customer freightout page query", ex); } return(result); }
public OperationResponse <PageResult <ProductPageQueryCommandOutputDTO> > PageQuery(PageQuery <ProductPageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <ProductPageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <AbstractProduct>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.Name.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <AbstractProduct>().AsQueryable(); var advancedSorting = new List <SortItem <AbstractProduct> >(); Expression <Func <AbstractProduct, object> > expression; if (input.Sort.ContainsKey("productType")) { expression = o => o.ProductType.Name; advancedSorting.Add(new SortItem <AbstractProduct> { PropertyName = "productType", SortExpression = expression, SortOrder = "desc" }); } var sorting = new SortingDTO <AbstractProduct>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <AbstractProduct, ProductPageQueryCommandOutputDTO>(predicate, input, sorting, o => new ProductPageQueryCommandOutputDTO { Id = o.Id, Name = o.Name, FlowerProductCategoryName = o.ProductTypeId == "FLW" && ((FlowerProduct)o).ProductCategory != null ? ((FlowerProduct)o).ProductCategory.Name : null, CreatedAt = o.CreatedAt, MainPicture = o.ProductMedias.Select(m => new FileItemRefOutputDTO { Id = m.Id, FullUrl = m.FileRepository.FullFilePath }).FirstOrDefault() }); } } catch (Exception ex) { result.AddException($"Error getting customer page query", ex); } return(result); }
public OperationResponse <PageResult <SaleOpportunityPageQueryCommandOutputDTO> > PageQuery(PageQuery <SaleOpportunityPageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <SaleOpportunityPageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <SaleOpportunity>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.Name.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <SaleOpportunity>().AsQueryable(); var advancedSorting = new List <SortItem <SaleOpportunity> >(); Expression <Func <SaleOpportunity, object> > expression = null; if (input.Sort.ContainsKey("SaleSeasonType")) { expression = o => o.SaleOpportunityTargetPrices.FirstOrDefault().SaleSeasonType.Name; advancedSorting.Add(new SortItem <SaleOpportunity> { PropertyName = "SaleOpportunityType", SortExpression = expression, SortOrder = "desc" }); } var sorting = new SortingDTO <SaleOpportunity>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <SaleOpportunity, SaleOpportunityPageQueryCommandOutputDTO>(predicate, input, sorting, o => new SaleOpportunityPageQueryCommandOutputDTO { Id = o.Id, Name = o.Name, //SaleSeasonTypeId = o.SaleSeasonTypeId, //SaleSeasonTypeName = o.SaleSeasonType.Name, CustomerId = o.CustomerId, CustomerName = o.Customer.Name, //TargetPrice = o.TargetPrice, CreatedAt = o.CreatedAt, }); } } catch (Exception ex) { result.AddException($"Error getting sale opportunity page query", ex); } return(result); }
public OperationResponse <PageResult <AppUserPageQueryCommandOutputDTO> > PageQuery(PageQuery <AppUserPageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <AppUserPageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <AppUser>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.UserName.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase) || o.Email.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <AppUser>().AsQueryable(); var advancedSorting = new List <SortItem <AppUser> >(); //Expression<Func<AppUser, object>> expression; //if (input.Sort.ContainsKey("email")) //{ // expression = o => o.AppUserThirdPartyAppSettings.Where(third => third.ThirdPartyAppTypeId == ThirdPartyAppTypeEnum.BusinessERP).SingleOrDefault().ThirdPartyAppUserId; // advancedSorting.Add(new SortItem<AppUser> { PropertyName = "erpId", SortExpression = expression, SortOrder = "desc" }); //} var sorting = new SortingDTO <AppUser>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <AppUser, AppUserPageQueryCommandOutputDTO>(predicate, input, sorting, o => new AppUserPageQueryCommandOutputDTO { Id = o.Id, UserName = o.UserName, Email = o.Email, FirstName = o.FirstName, LastName = o.LastName }); return(result); } } catch (Exception ex) { result.AddException($"Error getting users", ex); } return(result); }
public OperationResponse <PageResult <CustomerPageQueryCommandOutputDTO> > PageQuery(PageQuery <CustomerPageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <CustomerPageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <Customer>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.Name.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <Customer>().AsQueryable(); var advancedSorting = new List <SortItem <Customer> >(); Expression <Func <Customer, object> > expression; if (input.Sort.ContainsKey("erpId")) { expression = o => o.CustomerThirdPartyAppSettings.Where(third => third.ThirdPartyAppTypeId == ThirdPartyAppTypeEnum.BusinessERP).SingleOrDefault().ThirdPartyCustomerId; advancedSorting.Add(new SortItem <Customer> { PropertyName = "erpId", SortExpression = expression, SortOrder = "desc" }); } var sorting = new SortingDTO <Customer>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <Customer, CustomerPageQueryCommandOutputDTO>(predicate, input, sorting, o => new CustomerPageQueryCommandOutputDTO { Id = o.Id, Name = o.Name, ERPId = o.CustomerThirdPartyAppSettings.Where(third => third.ThirdPartyAppTypeId == DomainModel._Commons.Enums.ThirdPartyAppTypeEnum.BusinessERP).Select(thid => thid.ThirdPartyCustomerId).FirstOrDefault(), SalesforceId = o.CustomerThirdPartyAppSettings.Where(third => third.ThirdPartyAppTypeId == DomainModel._Commons.Enums.ThirdPartyAppTypeEnum.Salesforce).Select(thid => thid.ThirdPartyCustomerId).FirstOrDefault(), CreatedAt = o.CreatedAt }); } } catch (Exception ex) { result.AddException($"Error getting customer page query", ex); } return(result); }
public OperationResponse <PageResult <ProductBridgePageQueryCommandOutputDTO> > PageQuery(PageQuery <ProductBridgePageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <ProductBridgePageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <CompositionProductBridge>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.CompositionProduct.Name.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <CompositionProductBridge>().AsQueryable(); var advancedSorting = new List <SortItem <CompositionProductBridge> >(); Expression <Func <AbstractProduct, object> > expression; if (input.Sort.ContainsKey("productType")) { expression = o => o.ProductType.Name; advancedSorting.Add(new SortItem <CompositionProductBridge> { PropertyName = "productType", SortExpression = expression, SortOrder = "desc" }); } var sorting = new SortingDTO <CompositionProductBridge>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <CompositionProductBridge, ProductBridgePageQueryCommandOutputDTO>(predicate, input, sorting, o => new ProductBridgePageQueryCommandOutputDTO { Id = o.Id, ProductId = o.CompositionProductId, RelatedProductId = o.CompositionItemId, Stems = o.CompositionItemAmount }); } } catch (Exception ex) { result.AddException($"Error getting Product Bridge page query", ex); } return(result); }
public OperationResponse <PageResult <ProductPageQueryCommandOutput> > PageQuery(PageQuery <ProductPageQueryCommandInput> input) { var result = new OperationResponse <PageResult <ProductPageQueryCommandOutput> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <Product>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.ReferenceDescription.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <FunzaDBContext>(); { var query = dbLocator.Set <Product>().AsQueryable(); var advancedSorting = new List <SortItem <Product> >(); Expression <Func <Product, object> > expression = null; //if (input.Sort.ContainsKey("erpId")) //{ // expression = o => o.CustomerThirdPartyAppSettings.Where(third => third.ThirdPartyAppTypeId == ThirdPartyAppTypeEnum.BusinessERP).SingleOrDefault().ThirdPartyCustomerId; // advancedSorting.Add(new SortItem<Product> { PropertyName = "erpId", SortExpression = expression, SortOrder = "desc" }); //} var sorting = new SortingDTO <Product>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <Product, ProductPageQueryCommandOutput>(predicate, input, sorting, o => new ProductPageQueryCommandOutput { Id = o.Id, Name = o.ReferenceDescription, CreatedAt = o.CreatedAt }); } } catch (Exception ex) { result.AddException($"Error getting customer page query", ex); } return(result); }
public OperationResponse <PageResult <ProductColorTypePageQueryCommandOutputDTO> > PageQuery(PageQuery <ProductColorTypePageQueryCommandInputDTO> input) { var result = new OperationResponse <PageResult <ProductColorTypePageQueryCommandOutputDTO> >(); try { // predicate construction var predicate = PredicateBuilderExtension.True <ProductColorType>(); if (input.CustomFilter != null) { var filter = input.CustomFilter; if (!string.IsNullOrWhiteSpace(filter.Term)) { predicate = predicate.And(o => o.Name.Contains(filter.Term, StringComparison.InvariantCultureIgnoreCase)); } } var dbLocator = this.AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var query = dbLocator.Set <ProductColorType>().AsQueryable(); var advancedSorting = new List <SortItem <ProductColorType> >(); //var advancedSorting = new List<Expression<Func<ProductColorType, object>>>(); //Expression<Func<ProductColorType, object>> expression; var sorting = new SortingDTO <ProductColorType>(input.Sort, advancedSorting); result.Bag = query.ProcessPagingSort <ProductColorType, ProductColorTypePageQueryCommandOutputDTO>(predicate, input, sorting, o => new ProductColorTypePageQueryCommandOutputDTO { Id = o.Id, Name = o.Name, HexCode = o.HexCode, IsBasicColor = o.IsBasicColor, }); } } catch (Exception ex) { result.AddException($"Error getting customer freightout page query", ex); } return(result); }
public IActionResult Index([Bind("SearchName")] FilteringDTO filtering, SortingDTO sorting, PagingDTO paging) { ViewBag.CurrentPage = paging.PageNumber; ViewBag.OrderBy = sorting.OrderBy == "DESC" ? "ASC" : "DESC"; ViewBag.CurrentOrder = sorting.OrderBy; ViewBag.CurrentSort = sorting.SortBy; paging.CountItems = MakeService.CountMakers(); paging.PageSize = 3; if (paging.PageNumber < 1) { paging.PageNumber = 1; } if (paging.HasNextPage) { ViewBag.HasNext = true; } else { ViewBag.HasNext = false; } if (paging.HasPreviousPage) { ViewBag.HasPrevious = true; } else { ViewBag.HasPrevious = false; } var filter = Mapper.Map <Filtering>(filtering); var sort = Mapper.Map <Sorting>(sorting); var page = Mapper.Map <Paging>(paging); var make = MakeService.GetVehicleMakes(filter, sort, page); if (make == null) { return(NotFound(filtering.SearchName + " not Found")); } return(View(make.Select(Mapper.Map <VehicleMake, VehicleMakeDTO>))); }
public static PageResult <R> ProcessPagingSort <T, R>(this IQueryable <T> query, Expression <Func <T, bool> > filterPredicate, IPaging paging, SortingDTO <T> sorting, Expression <Func <T, R> > mapping) where R : class { // Get Total Count var totalCount = query.Count(); // Filter query = query.Where(filterPredicate); // Get Filtered Count var filteredCount = query.Count(); // Apply Order query = query.ProcessSorting <T>(sorting); //Paging query = (paging != null) ? query.Skip(paging.PageSize * paging.PageIndex).Take(paging.PageSize) : query; // Mapping var castedQuery = (mapping != null) ? query.Select(mapping) : query.Cast <R>(); // Get Items var queryResult = castedQuery.ToList(); var result = new PageResult <R> { FilteredCount = filteredCount, TotalCount = totalCount, Size = paging == null ? 0 : paging.PageSize, Items = queryResult }; return(result); }
public static PageResult <T> ProcessPagingSort <T>(this IQueryable <T> query, Expression <Func <T, bool> > filterPredicate, IPaging paging, SortingDTO <T> sorting) where T : class { return(query.ProcessPagingSort <T, T>(filterPredicate, paging, sorting, null)); }