public async Task <int> Count(RelationshipCustomerTypeFilter filter) { IQueryable <RelationshipCustomerTypeDAO> RelationshipCustomerTypes = DataContext.RelationshipCustomerType.AsNoTracking(); RelationshipCustomerTypes = DynamicFilter(RelationshipCustomerTypes, filter); return(await RelationshipCustomerTypes.CountAsync()); }
public async Task <List <RelationshipCustomerType> > List(RelationshipCustomerTypeFilter filter) { if (filter == null) { return(new List <RelationshipCustomerType>()); } IQueryable <RelationshipCustomerTypeDAO> RelationshipCustomerTypeDAOs = DataContext.RelationshipCustomerType.AsNoTracking(); RelationshipCustomerTypeDAOs = DynamicFilter(RelationshipCustomerTypeDAOs, filter); RelationshipCustomerTypeDAOs = DynamicOrder(RelationshipCustomerTypeDAOs, filter); List <RelationshipCustomerType> RelationshipCustomerTypes = await DynamicSelect(RelationshipCustomerTypeDAOs, filter); return(RelationshipCustomerTypes); }
public async Task <bool> ValidateId(RelationshipCustomerType RelationshipCustomerType) { RelationshipCustomerTypeFilter RelationshipCustomerTypeFilter = new RelationshipCustomerTypeFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = RelationshipCustomerType.Id }, Selects = RelationshipCustomerTypeSelect.Id }; int count = await UOW.RelationshipCustomerTypeRepository.Count(RelationshipCustomerTypeFilter); if (count == 0) { RelationshipCustomerType.AddError(nameof(RelationshipCustomerTypeValidator), nameof(RelationshipCustomerType.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <RelationshipCustomerTypeFilter> ToFilter(RelationshipCustomerTypeFilter filter) { if (filter.OrFilter == null) { filter.OrFilter = new List <RelationshipCustomerTypeFilter>(); } if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0) { return(filter); } foreach (var currentFilter in CurrentContext.Filters) { RelationshipCustomerTypeFilter subFilter = new RelationshipCustomerTypeFilter(); filter.OrFilter.Add(subFilter); List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value; foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions) { if (FilterPermissionDefinition.Name == nameof(subFilter.Id)) { subFilter.Id = FilterBuilder.Merge(subFilter.Id, FilterPermissionDefinition.IdFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Name)) { subFilter.Name = FilterBuilder.Merge(subFilter.Name, FilterPermissionDefinition.StringFilter); } if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null) { if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id) { } if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id) { } } } } return(filter); }
public async Task <List <RelationshipCustomerType> > List(RelationshipCustomerTypeFilter RelationshipCustomerTypeFilter) { try { List <RelationshipCustomerType> RelationshipCustomerTypes = await UOW.RelationshipCustomerTypeRepository.List(RelationshipCustomerTypeFilter); return(RelationshipCustomerTypes); } catch (Exception ex) { if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(RelationshipCustomerTypeService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(RelationshipCustomerTypeService)); throw new MessageException(ex.InnerException); } } }
public async Task <int> Count(RelationshipCustomerTypeFilter RelationshipCustomerTypeFilter) { try { int result = await UOW.RelationshipCustomerTypeRepository.Count(RelationshipCustomerTypeFilter); return(result); } catch (Exception ex) { if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(RelationshipCustomerTypeService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(RelationshipCustomerTypeService)); throw new MessageException(ex.InnerException); } } }
public async Task <List <Store_RelationshipCustomerTypeDTO> > SingleListRelationshipCustomerType([FromBody] Store_RelationshipCustomerTypeFilterDTO Store_RelationshipCustomerTypeFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } RelationshipCustomerTypeFilter RelationshipCustomerTypeFilter = new RelationshipCustomerTypeFilter(); RelationshipCustomerTypeFilter.Skip = 0; RelationshipCustomerTypeFilter.Take = int.MaxValue; RelationshipCustomerTypeFilter.OrderBy = RelationshipCustomerTypeOrder.Id; RelationshipCustomerTypeFilter.OrderType = OrderType.ASC; RelationshipCustomerTypeFilter.Selects = RelationshipCustomerTypeSelect.ALL; RelationshipCustomerTypeFilter.Id = Store_RelationshipCustomerTypeFilterDTO.Id; RelationshipCustomerTypeFilter.Name = Store_RelationshipCustomerTypeFilterDTO.Name; List <RelationshipCustomerType> RelationshipCustomerTypes = await RelationshipCustomerTypeService.List(RelationshipCustomerTypeFilter); List <Store_RelationshipCustomerTypeDTO> Store_RelationshipCustomerTypeDTOs = RelationshipCustomerTypes .Select(x => new Store_RelationshipCustomerTypeDTO(x)).ToList(); return(Store_RelationshipCustomerTypeDTOs); }
private IQueryable <RelationshipCustomerTypeDAO> DynamicOrder(IQueryable <RelationshipCustomerTypeDAO> query, RelationshipCustomerTypeFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case RelationshipCustomerTypeOrder.Id: query = query.OrderBy(q => q.Id); break; case RelationshipCustomerTypeOrder.Name: query = query.OrderBy(q => q.Name); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case RelationshipCustomerTypeOrder.Id: query = query.OrderByDescending(q => q.Id); break; case RelationshipCustomerTypeOrder.Name: query = query.OrderByDescending(q => q.Name); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private IQueryable <RelationshipCustomerTypeDAO> OrFilter(IQueryable <RelationshipCustomerTypeDAO> query, RelationshipCustomerTypeFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <RelationshipCustomerTypeDAO> initQuery = query.Where(q => false); foreach (RelationshipCustomerTypeFilter RelationshipCustomerTypeFilter in filter.OrFilter) { IQueryable <RelationshipCustomerTypeDAO> queryable = query; if (RelationshipCustomerTypeFilter.Id != null && RelationshipCustomerTypeFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, RelationshipCustomerTypeFilter.Id); } if (RelationshipCustomerTypeFilter.Name != null && RelationshipCustomerTypeFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, RelationshipCustomerTypeFilter.Name); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <RelationshipCustomerTypeDAO> DynamicFilter(IQueryable <RelationshipCustomerTypeDAO> query, RelationshipCustomerTypeFilter 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); } query = OrFilter(query, filter); return(query); }
private async Task <List <RelationshipCustomerType> > DynamicSelect(IQueryable <RelationshipCustomerTypeDAO> query, RelationshipCustomerTypeFilter filter) { List <RelationshipCustomerType> RelationshipCustomerTypes = await query.Select(q => new RelationshipCustomerType() { Id = filter.Selects.Contains(RelationshipCustomerTypeSelect.Id) ? q.Id : default(long), Name = filter.Selects.Contains(RelationshipCustomerTypeSelect.Name) ? q.Name : default(string), }).ToListAsync(); return(RelationshipCustomerTypes); }