Esempio n. 1
0
        public async Task <int> Count(StoreRepresentFilter filter)
        {
            IQueryable <StoreRepresentDAO> StoreRepresents = DataContext.StoreRepresent.AsNoTracking();

            StoreRepresents = DynamicFilter(StoreRepresents, filter);
            return(await StoreRepresents.CountAsync());
        }
Esempio n. 2
0
        public async Task <List <StoreRepresent> > List(StoreRepresentFilter filter)
        {
            if (filter == null)
            {
                return(new List <StoreRepresent>());
            }
            IQueryable <StoreRepresentDAO> StoreRepresentDAOs = DataContext.StoreRepresent.AsNoTracking();

            StoreRepresentDAOs = DynamicFilter(StoreRepresentDAOs, filter);
            StoreRepresentDAOs = DynamicOrder(StoreRepresentDAOs, filter);
            List <StoreRepresent> StoreRepresents = await DynamicSelect(StoreRepresentDAOs, filter);

            return(StoreRepresents);
        }
Esempio n. 3
0
        private IQueryable <StoreRepresentDAO> OrFilter(IQueryable <StoreRepresentDAO> query, StoreRepresentFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <StoreRepresentDAO> initQuery = query.Where(q => false);

            foreach (StoreRepresentFilter StoreRepresentFilter in filter.OrFilter)
            {
                IQueryable <StoreRepresentDAO> queryable = query;
                if (StoreRepresentFilter.Id != null && StoreRepresentFilter.Id.HasValue)
                {
                    queryable = queryable.Where(q => q.Id, StoreRepresentFilter.Id);
                }
                if (StoreRepresentFilter.Name != null && StoreRepresentFilter.Name.HasValue)
                {
                    queryable = queryable.Where(q => q.Name, StoreRepresentFilter.Name);
                }
                if (StoreRepresentFilter.DateOfBirth != null && StoreRepresentFilter.DateOfBirth.HasValue)
                {
                    queryable = queryable.Where(q => q.DateOfBirth.HasValue).Where(q => q.DateOfBirth, StoreRepresentFilter.DateOfBirth);
                }
                if (StoreRepresentFilter.Phone != null && StoreRepresentFilter.Phone.HasValue)
                {
                    queryable = queryable.Where(q => q.Phone, StoreRepresentFilter.Phone);
                }
                if (StoreRepresentFilter.PositionId != null && StoreRepresentFilter.PositionId.HasValue)
                {
                    queryable = queryable.Where(q => q.PositionId.HasValue).Where(q => q.PositionId, StoreRepresentFilter.PositionId);
                }
                if (StoreRepresentFilter.StoreId != null && StoreRepresentFilter.StoreId.HasValue)
                {
                    queryable = queryable.Where(q => q.StoreId, StoreRepresentFilter.StoreId);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Esempio n. 4
0
 private IQueryable <StoreRepresentDAO> DynamicFilter(IQueryable <StoreRepresentDAO> query, StoreRepresentFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     if (filter.Id != null && filter.Id.HasValue)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.Name != null && filter.Name.HasValue)
     {
         query = query.Where(q => q.Name, filter.Name);
     }
     if (filter.DateOfBirth != null && filter.DateOfBirth.HasValue)
     {
         query = query.Where(q => q.DateOfBirth == null).Union(query.Where(q => q.DateOfBirth.HasValue).Where(q => q.DateOfBirth, filter.DateOfBirth));
     }
     if (filter.Phone != null && filter.Phone.HasValue)
     {
         query = query.Where(q => q.Phone, filter.Phone);
     }
     if (filter.PositionId != null && filter.PositionId.HasValue)
     {
         query = query.Where(q => q.PositionId.HasValue).Where(q => q.PositionId, filter.PositionId);
     }
     if (filter.StoreId != null && filter.StoreId.HasValue)
     {
         query = query.Where(q => q.StoreId, filter.StoreId);
     }
     query = OrFilter(query, filter);
     return(query);
 }
Esempio n. 5
0
        private async Task <List <StoreRepresent> > DynamicSelect(IQueryable <StoreRepresentDAO> query, StoreRepresentFilter filter)
        {
            List <StoreRepresent> StoreRepresents = await query.Select(q => new StoreRepresent()
            {
                Id          = filter.Selects.Contains(StoreRepresentSelect.Id) ? q.Id : default(long),
                Name        = filter.Selects.Contains(StoreRepresentSelect.Name) ? q.Name : default(string),
                DateOfBirth = filter.Selects.Contains(StoreRepresentSelect.DateOfBirth) ? q.DateOfBirth : default(DateTime?),
                Phone       = filter.Selects.Contains(StoreRepresentSelect.Phone) ? q.Phone : default(string),
                PositionId  = filter.Selects.Contains(StoreRepresentSelect.Position) ? q.PositionId : default(long?),
                StoreId     = filter.Selects.Contains(StoreRepresentSelect.Store) ? q.StoreId : default(long),
                Position    = filter.Selects.Contains(StoreRepresentSelect.Position) && q.Position != null ? new Position
                {
                    Id       = q.Position.Id,
                    Code     = q.Position.Code,
                    Name     = q.Position.Name,
                    StatusId = q.Position.StatusId,
                    RowId    = q.Position.RowId,
                    Used     = q.Position.Used,
                } : null,
                Store = filter.Selects.Contains(StoreRepresentSelect.Store) && q.Store != null ? new Store
                {
                    Id                = q.Store.Id,
                    Code              = q.Store.Code,
                    CodeDraft         = q.Store.CodeDraft,
                    Name              = q.Store.Name,
                    UnsignName        = q.Store.UnsignName,
                    ParentStoreId     = q.Store.ParentStoreId,
                    OrganizationId    = q.Store.OrganizationId,
                    StoreTypeId       = q.Store.StoreTypeId,
                    StoreGroupingId   = q.Store.StoreGroupingId,
                    Telephone         = q.Store.Telephone,
                    ProvinceId        = q.Store.ProvinceId,
                    DistrictId        = q.Store.DistrictId,
                    WardId            = q.Store.WardId,
                    Address           = q.Store.Address,
                    UnsignAddress     = q.Store.UnsignAddress,
                    DeliveryAddress   = q.Store.DeliveryAddress,
                    Latitude          = q.Store.Latitude,
                    Longitude         = q.Store.Longitude,
                    DeliveryLatitude  = q.Store.DeliveryLatitude,
                    DeliveryLongitude = q.Store.DeliveryLongitude,
                    OwnerName         = q.Store.OwnerName,
                    OwnerPhone        = q.Store.OwnerPhone,
                    OwnerEmail        = q.Store.OwnerEmail,
                    TaxCode           = q.Store.TaxCode,
                    LegalEntity       = q.Store.LegalEntity,
                    AppUserId         = q.Store.AppUserId,
                    StatusId          = q.Store.StatusId,
                    RowId             = q.Store.RowId,
                    Used              = q.Store.Used,
                    StoreStatusId     = q.Store.StoreStatusId,
                } : null,
            }).ToListAsync();

            return(StoreRepresents);
        }
Esempio n. 6
0
        private IQueryable <StoreRepresentDAO> DynamicOrder(IQueryable <StoreRepresentDAO> query, StoreRepresentFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case StoreRepresentOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case StoreRepresentOrder.Name:
                    query = query.OrderBy(q => q.Name);
                    break;

                case StoreRepresentOrder.DateOfBirth:
                    query = query.OrderBy(q => q.DateOfBirth);
                    break;

                case StoreRepresentOrder.Phone:
                    query = query.OrderBy(q => q.Phone);
                    break;

                case StoreRepresentOrder.Position:
                    query = query.OrderBy(q => q.PositionId);
                    break;

                case StoreRepresentOrder.Store:
                    query = query.OrderBy(q => q.StoreId);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case StoreRepresentOrder.Id:
                    query = query.OrderByDescending(q => q.Id);
                    break;

                case StoreRepresentOrder.Name:
                    query = query.OrderByDescending(q => q.Name);
                    break;

                case StoreRepresentOrder.DateOfBirth:
                    query = query.OrderByDescending(q => q.DateOfBirth);
                    break;

                case StoreRepresentOrder.Phone:
                    query = query.OrderByDescending(q => q.Phone);
                    break;

                case StoreRepresentOrder.Position:
                    query = query.OrderByDescending(q => q.PositionId);
                    break;

                case StoreRepresentOrder.Store:
                    query = query.OrderByDescending(q => q.StoreId);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }