예제 #1
0
        protected List <long> FilterOrganization(List <Organization> Organizations, IdFilter IdFilter)
        {
            List <long> In    = null;
            List <long> NotIn = null;

            if (IdFilter.Equal != null)
            {
                if (In == null)
                {
                    In = new List <long>();
                }
                In.Add(IdFilter.Equal.Value);
            }
            if (IdFilter.In != null)
            {
                if (In == null)
                {
                    In = new List <long>();
                }
                In.AddRange(IdFilter.In);
            }

            if (IdFilter.NotEqual != null)
            {
                if (NotIn == null)
                {
                    NotIn = new List <long>();
                }
                NotIn.Add(IdFilter.NotEqual.Value);
            }
            if (IdFilter.NotIn != null)
            {
                if (NotIn == null)
                {
                    NotIn = new List <long>();
                }
                NotIn.AddRange(IdFilter.NotIn);
            }
            if (In != null)
            {
                List <string> InPaths = Organizations.Where(o => In.Count == 0 || In.Contains(o.Id)).Select(o => o.Path).ToList();
                Organizations = Organizations.Where(o => InPaths.Any(p => o.Path.StartsWith(p))).ToList();
            }
            if (NotIn != null)
            {
                List <string> NotInPaths = Organizations.Where(o => NotIn.Count == 0 || NotIn.Contains(o.Id)).Select(o => o.Path).ToList();
                Organizations = Organizations.Where(o => !NotInPaths.Any(p => o.Path.StartsWith(p))).ToList();
            }
            return(Organizations.Select(o => o.Id).ToList());
        }
예제 #2
0
        public bool Validate(dynamic entity)
        {
            dynamic value = entity.GetMember(Property);

            if (value == null && IgnoreNull == true)
            {
                return(true);
            }

            if (value == null)
            {
                return(false);
            }

            int length = value.Length;

            if (Minimum != null && length < Minimum)
            {
                return(false);
            }

            if (Maximum != null && length > Maximum)
            {
                return(false);
            }

            if (In != null && !In.Contains(length))
            {
                return(false);
            }

            if (Is != null && length != Is)
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
        protected async Task <List <long> > FilterOrganization(IOrganizationService OrganizationService, ICurrentContext CurrentContext)
        {
            if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
            {
                return(new List <long>());
            }
            List <Organization> Organizations = await OrganizationService.List(new OrganizationFilter
            {
                Skip      = 0,
                Take      = int.MaxValue,
                Selects   = OrganizationSelect.ALL,
                OrderBy   = OrganizationOrder.Id,
                OrderType = OrderType.ASC
            });

            List <long> In    = null;
            List <long> NotIn = null;

            foreach (var currentFilter in CurrentContext.Filters)
            {
                List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
                foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
                {
                    if (FilterPermissionDefinition.Name == "OrganizationId")
                    {
                        if (FilterPermissionDefinition.IdFilter.Equal != null)
                        {
                            if (In == null)
                            {
                                In = new List <long>();
                            }
                            In.Add(FilterPermissionDefinition.IdFilter.Equal.Value);
                        }
                        if (FilterPermissionDefinition.IdFilter.In != null)
                        {
                            if (In == null)
                            {
                                In = new List <long>();
                            }
                            In.AddRange(FilterPermissionDefinition.IdFilter.In);
                        }

                        if (FilterPermissionDefinition.IdFilter.NotEqual != null)
                        {
                            if (NotIn == null)
                            {
                                NotIn = new List <long>();
                            }
                            NotIn.Add(FilterPermissionDefinition.IdFilter.NotEqual.Value);
                        }
                        if (FilterPermissionDefinition.IdFilter.NotIn != null)
                        {
                            if (NotIn == null)
                            {
                                NotIn = new List <long>();
                            }
                            NotIn.AddRange(FilterPermissionDefinition.IdFilter.NotIn);
                        }
                    }
                }
            }

            if (In != null)
            {
                List <string> InPaths = Organizations.Where(o => In.Count == 0 || In.Contains(o.Id)).Select(o => o.Path).ToList();
                Organizations = Organizations.Where(o => InPaths.Any(p => o.Path.StartsWith(p))).ToList();
            }
            if (NotIn != null)
            {
                List <string> NotInPaths = Organizations.Where(o => NotIn.Count == 0 || NotIn.Contains(o.Id)).Select(o => o.Path).ToList();
                Organizations = Organizations.Where(o => !NotInPaths.Any(p => o.Path.StartsWith(p))).ToList();
            }

            List <long> organizationIds = Organizations.Select(o => o.Id).ToList();

            return(organizationIds);
        }