private IQueryable <BrandDAO> DynamicFilter(IQueryable <BrandDAO> query, BrandFilter filter) { if (filter == null) { return(query.Where(q => false)); } if (filter.Id != null) { query = query.Where(q => q.Id, filter.Id); } if (filter.Name != null) { query = query.Where(q => q.Name, filter.Name); } if (filter.CategoryId != null) { query = query.Where(q => q.CategoryId, filter.CategoryId); } if (filter.Ids != null) { query = query.Where(q => filter.Ids.Contains(q.Id)); } if (filter.ExceptIds != null) { query = query.Where(q => !filter.ExceptIds.Contains(q.Id)); } return(query); }
private IQueryable <BrandDAO> OrFilter(IQueryable <BrandDAO> query, BrandFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <BrandDAO> initQuery = query.Where(q => false); foreach (BrandFilter BrandFilter in filter.OrFilter) { IQueryable <BrandDAO> queryable = query; if (BrandFilter.Id != null) { queryable = queryable.Where(q => q.Id, BrandFilter.Id); } if (BrandFilter.Code != null) { queryable = queryable.Where(q => q.Code, BrandFilter.Code); } if (BrandFilter.Name != null) { queryable = queryable.Where(q => q.Name, BrandFilter.Name); } if (BrandFilter.StatusId != null) { queryable = queryable.Where(q => q.StatusId, BrandFilter.StatusId); } if (BrandFilter.Description != null) { queryable = queryable.Where(q => q.Description, BrandFilter.Description); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private static Expression <Func <Brand, bool> > Filter(BrandFilter filter) { var query = PredicateBuilder.True <Brand>(); if (filter != null) { if (!String.IsNullOrWhiteSpace(filter.NamePrefix)) { query = PredicateBuilder.And(query, v => v.Name.StartsWith(filter.NamePrefix) || v.EnglishName.StartsWith(filter.NamePrefix)); } if (!String.IsNullOrWhiteSpace(filter.Name)) { query = PredicateBuilder.And(query, v => v.Name.Equals(filter.Name) || v.EnglishName.Equals(filter.Name)); } if (filter.Status != null) { query = PredicateBuilder.And(query, v => v.Status == filter.Status.Value); } else { query = PredicateBuilder.And(query, v => v.Status > 0); } } return(query); }
public async Task <List <ProductMaster_BrandDTO> > SingleListBrand([FromBody] ProductMaster_BrandFilterDTO ProductMaster_BrandFilterDTO) { BrandFilter BrandFilter = new BrandFilter(); BrandFilter.Skip = 0; BrandFilter.Take = 20; BrandFilter.OrderBy = BrandOrder.Id; BrandFilter.OrderType = OrderType.ASC; BrandFilter.Selects = BrandSelect.ALL; BrandFilter.Id = new LongFilter { Equal = ProductMaster_BrandFilterDTO.Id }; BrandFilter.Name = new StringFilter { StartsWith = ProductMaster_BrandFilterDTO.Name }; BrandFilter.CategoryId = new LongFilter { Equal = ProductMaster_BrandFilterDTO.CategoryId }; List <Brand> Brands = await BrandService.List(BrandFilter); List <ProductMaster_BrandDTO> ProductMaster_BrandDTOs = Brands .Select(x => new ProductMaster_BrandDTO(x)).ToList(); return(ProductMaster_BrandDTOs); }
private static Expression <Func <Section, bool> > Filter4Section(BrandFilter filter) { var query = PredicateBuilder.True <Section>(); if (filter != null) { if (filter.CounterId != null) { //return v => v.SectionId == filter.CounterId; query = PredicateBuilder.And(query, v => v.Id == filter.CounterId); } if (filter.Status != null) { query = PredicateBuilder.And(query, v => v.Status == filter.Status.Value); } else { query = PredicateBuilder.And(query, v => v.Status > 0); } } return(query); //return v => true; }
public async Task <int> Count(BrandFilter filter) { IQueryable <BrandDAO> Brands = DataContext.Brand.AsNoTracking(); Brands = DynamicFilter(Brands, filter); return(await Brands.CountAsync()); }
public void FilterBrandTest() { var inv = TestInitialize(); var brandFilter = new BrandFilter("Ehsandar"); var filtered = inv.Filter(new List <IFilter> { brandFilter }); CollectionAssert.Contains(filtered, inv.Items[1]); }
public async Task <int> Count([FromBody] BrandMaster_BrandFilterDTO BrandMaster_BrandFilterDTO) { if (!ModelState.IsValid) { throw new MessageException(ModelState); } BrandFilter BrandFilter = ConvertFilterDTOToFilterEntity(BrandMaster_BrandFilterDTO); return(await BrandService.Count(BrandFilter)); }
public async Task <List <BrandMaster_BrandDTO> > List([FromBody] BrandMaster_BrandFilterDTO BrandMaster_BrandFilterDTO) { if (!ModelState.IsValid) { throw new MessageException(ModelState); } BrandFilter BrandFilter = ConvertFilterDTOToFilterEntity(BrandMaster_BrandFilterDTO); List <Brand> Brands = await BrandService.List(BrandFilter); return(Brands.Select(c => new BrandMaster_BrandDTO(c)).ToList()); }
public async Task <List <Brand> > List(BrandFilter filter) { if (filter == null) { return(new List <Brand>()); } IQueryable <BrandDAO> BrandDAOs = DataContext.Brand.AsNoTracking(); BrandDAOs = DynamicFilter(BrandDAOs, filter); BrandDAOs = DynamicOrder(BrandDAOs, filter); List <Brand> Brands = await DynamicSelect(BrandDAOs, filter); return(Brands); }
public BrandFilter ConvertFilterDTOToFilterEntity(BrandMaster_BrandFilterDTO BrandMaster_BrandFilterDTO) { BrandFilter BrandFilter = new BrandFilter(); BrandFilter.Selects = BrandSelect.ALL; BrandFilter.Id = new LongFilter { Equal = BrandMaster_BrandFilterDTO.Id }; BrandFilter.Name = new StringFilter { StartsWith = BrandMaster_BrandFilterDTO.Name }; BrandFilter.CategoryId = new LongFilter { Equal = BrandMaster_BrandFilterDTO.CategoryId }; return(BrandFilter); }
public BrandFilter ToFilter(BrandFilter filter) { if (filter.OrFilter == null) { filter.OrFilter = new List <BrandFilter>(); } if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0) { return(filter); } foreach (var currentFilter in CurrentContext.Filters) { BrandFilter subFilter = new BrandFilter(); filter.OrFilter.Add(subFilter); List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value; foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions) { if (FilterPermissionDefinition.Name == nameof(subFilter.Id)) { subFilter.Id = FilterPermissionDefinition.IdFilter; } if (FilterPermissionDefinition.Name == nameof(subFilter.Code)) { subFilter.Code = FilterPermissionDefinition.StringFilter; } if (FilterPermissionDefinition.Name == nameof(subFilter.Name)) { subFilter.Name = FilterPermissionDefinition.StringFilter; } if (FilterPermissionDefinition.Name == nameof(subFilter.StatusId)) { subFilter.StatusId = FilterPermissionDefinition.IdFilter; } if (FilterPermissionDefinition.Name == nameof(subFilter.Description)) { subFilter.Description = FilterPermissionDefinition.StringFilter; } } } return(filter); }
public async Task <bool> ValidateId(Brand Brand) { BrandFilter BrandFilter = new BrandFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = Brand.Id }, Selects = BrandSelect.Id }; int count = await UOW.BrandRepository.Count(BrandFilter); if (count == 0) { Brand.AddError(nameof(BrandValidator), nameof(Brand.Id), ErrorCode.IdNotExisted); } return(count == 1); }
private IQueryable <BrandDAO> DynamicOrder(IQueryable <BrandDAO> query, BrandFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case BrandOrder.Id: query = query.OrderBy(q => q.Id); break; case BrandOrder.Name: query = query.OrderBy(q => q.Name); break; case BrandOrder.Category: query = query.OrderBy(q => q.Category.Id); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case BrandOrder.Id: query = query.OrderByDescending(q => q.Id); break; case BrandOrder.Name: query = query.OrderByDescending(q => q.Name); break; case BrandOrder.Category: query = query.OrderByDescending(q => q.Category.Id); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
public IHttpActionResult GetList([FromUri] BrandFilter filter, [UserId] int userId) { int total; if (filter == null) { filter = new BrandFilter(); } var pagerRequest = new PagerRequest(filter.Page ?? 1, filter.PageSize ?? 10); var model = _brandRepository.GetPagedList(pagerRequest, out total, filter, filter.SortOrder ?? BrandSortOrder.Default); var dto = Mapper.Map <List <Brand>, List <BrandDto> >(model); var pagerdto = new PagerInfo <BrandDto>(pagerRequest, total); pagerdto.Datas = dto; return(RetrunHttpActionResult(pagerdto)); }
private IQueryable <BrandDAO> DynamicFilter(IQueryable <BrandDAO> query, BrandFilter filter) { if (filter == null) { return(query.Where(q => false)); } query = query.Where(q => !q.DeletedAt.HasValue); if (filter.CreatedAt != null) { query = query.Where(q => q.CreatedAt, filter.CreatedAt); } if (filter.UpdatedAt != null) { query = query.Where(q => q.UpdatedAt, filter.UpdatedAt); } if (filter.Id != null) { query = query.Where(q => q.Id, filter.Id); } if (filter.Code != null) { query = query.Where(q => q.Code, filter.Code); } if (filter.Name != null) { query = query.Where(q => q.Name, filter.Name); } if (filter.StatusId != null) { query = query.Where(q => q.StatusId, filter.StatusId); } if (filter.Description != null) { query = query.Where(q => q.Description, filter.Description); } query = OrFilter(query, filter); return(query); }
public async Task <List <Brand> > List(BrandFilter BrandFilter) { try { List <Brand> Brands = await UOW.BrandRepository.List(BrandFilter); return(Brands); } catch (Exception ex) { if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(BrandService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(BrandService)); throw new MessageException(ex.InnerException); } } }
public async Task <int> Count(BrandFilter BrandFilter) { try { int result = await UOW.BrandRepository.Count(BrandFilter); return(result); } catch (Exception ex) { if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(BrandService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(BrandService)); throw new MessageException(ex.InnerException); } } }
public async Task <int> Count(BrandFilter BrandFilter) { int result = await UOW.BrandRepository.Count(BrandFilter); return(result); }
/// <summary> /// 分页 /// </summary> /// <param name="pagerRequest"></param> /// <param name="totalCount"></param> /// <param name="filter"></param> /// <param name="sortOrder"></param> /// <returns></returns> public List <Brand> GetPagedList(PagerRequest pagerRequest, out int totalCount, BrandFilter filter, BrandSortOrder sortOrder) { var brandFilter = Filter(filter); var fi = Filter4SectionBrand(filter); var sectionFilter = Filter4Section(filter); var result = Func(c => { int t; var q = from s in c.Set <Brand>().AsExpandable().Where(brandFilter) let sb_let = (from sb in c.Set <IMS_SectionBrand>().AsExpandable().Where(fi) //join s in c.Set<Sse>() where s.Id == sb.BrandId select new { sb.SectionId }) select new { s, Sectons = sb_let }; t = q.Count(); var q1 = from b in q.OrderBy(v => v.s.Id).Skip(pagerRequest.SkipCount).Take(pagerRequest.PageSize) let sup = (from s in c.Set <OpcSupplierInfo>() join sb in c.Set <Supplier_Brand>() on s.Id equals sb.Supplier_Id where sb.Brand_Id == b.s.Id select new OpcSupplierInfoClone { Address = s.Address, Contact = s.Contact, Corporate = s.Corporate, Contract = s.Contract, CreatedDate = s.CreatedDate, CreatedUser = s.CreatedUser, FaxNo = s.FaxNo, Id = s.Id, Memo = s.Memo, Status = s.Status, StoreId = s.StoreId, SupplierName = s.SupplierName, SupplierNo = s.SupplierNo, TaxNo = s.TaxNo, Telephone = s.Telephone, UpdatedDate = s.UpdatedDate, UpdatedUser = s.UpdatedUser, }) let se = (from s in c.Set <Section>().AsExpandable().Where(sectionFilter) join s_b in c.Set <IMS_SectionBrand>().AsExpandable() on s.Id equals s_b.SectionId where (s_b.BrandId == b.s.Id) select new SectionClone { BrandId = s.BrandId, ChannelSectionId = s.ChannelSectionId, ContactPerson = s.ContactPerson, ContactPhone = s.ContactPhone, CreateDate = s.CreateDate, CreateUser = s.CreateUser, Id = s.Id, Location = s.Location, Name = s.Name, Status = s.Status, StoreCode = s.StoreCode, StoreId = s.StoreId, UpdateDate = s.UpdateDate, UpdateUser = s.UpdateUser, SectionCode = s.SectionCode }) select new BrandClone() { ChannelBrandId = b.s.ChannelBrandId, CreatedDate = b.s.CreatedDate, CreatedUser = b.s.CreatedUser, Description = b.s.Description, EnglishName = b.s.EnglishName, Group = b.s.Group, Id = b.s.Id, Logo = b.s.Logo, Name = b.s.Name, Sections = se, Status = b.s.Status, Suppliers = sup, UpdatedDate = b.s.UpdatedDate, UpdatedUser = b.s.UpdatedUser, WebSite = b.s.WebSite }; var rst = q1.ToList(); return(new { totalCount = t, Data = rst }); }); totalCount = result.totalCount; return(AutoMapper.Mapper.Map <List <BrandClone>, List <Brand> >(result.Data)); }
private static Expression <Func <IMS_SectionBrand, bool> > Filter4SectionBrand(BrandFilter filter) { var query = PredicateBuilder.True <IMS_SectionBrand>(); if (filter != null) { if (filter.CounterId != null) { //return v => v.SectionId == filter.CounterId; query = PredicateBuilder.And(query, v => v.SectionId == filter.CounterId); } } return(query); //return v => true; }
private async Task <List <Brand> > DynamicSelect(IQueryable <BrandDAO> query, BrandFilter filter) { List <Brand> Brands = await query.Select(q => new Brand() { Id = filter.Selects.Contains(BrandSelect.Id) ? q.Id : default(long), Name = filter.Selects.Contains(BrandSelect.Name) ? q.Name : default(string), CategoryId = filter.Selects.Contains(BrandSelect.Category) ? q.CategoryId : default(long), Category = filter.Selects.Contains(BrandSelect.Category) && q.Category != null ? new Category { Id = q.Category.Id, Code = q.Category.Code, Name = q.Category.Name, ParentId = q.Category.ParentId, Icon = q.Category.Icon, } : null, }).ToListAsync(); return(Brands); }
public async Task <IEnumerable <Domain.Models.Brand> > Get(BrandFilter filter) { return(await _database.Brand.Filter(filter).ToListAsync()); }
public async Task <List <Brand> > List(BrandFilter BrandFilter) { List <Brand> Brands = await UOW.BrandRepository.List(BrandFilter); return(Brands); }
private async Task <List <Brand> > DynamicSelect(IQueryable <BrandDAO> query, BrandFilter filter) { List <Brand> Brands = await query.Select(q => new Brand() { Id = filter.Selects.Contains(BrandSelect.Id) ? q.Id : default(long), Code = filter.Selects.Contains(BrandSelect.Code) ? q.Code : default(string), Name = filter.Selects.Contains(BrandSelect.Name) ? q.Name : default(string), StatusId = filter.Selects.Contains(BrandSelect.Status) ? q.StatusId : default(long), Description = filter.Selects.Contains(BrandSelect.Description) ? q.Description : default(string), Used = filter.Selects.Contains(BrandSelect.Used) ? q.Used : default(bool), CreatedAt = q.CreatedAt, UpdatedAt = q.UpdatedAt, }).ToListAsync(); return(Brands); }
public static IQueryable <Domain.Models.Brand> Filter(this IQueryable <Domain.Models.Brand> brands, BrandFilter filter) { if (filter.Id != null) { brands = brands.Where(b => b.Id == filter.Id); } if (!string.IsNullOrEmpty(filter.NameOrBarcode)) { brands = brands.Where(b => string.IsNullOrEmpty(filter.NameOrBarcode) || b.Name.Contains(filter.NameOrBarcode) || b.Barcode.Contains(filter.NameOrBarcode)); } return(brands); }