Пример #1
0
        private async Task AddChildrenToListAsync(TEntityVM item, List <TEntityVM> list)
        {
            PropertyInfo idProp     = ((IEnumerable <PropertyInfo>) typeof(TEntityVM).GetProperties()).FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(pInfo => pInfo.Name.ToLower() == "id"));
            object       id         = idProp.GetValue((object)item);
            FilterInfo   filterInfo = new FilterInfo()
            {
                Filters = new List <FilterData>()
                {
                    new FilterData()
                    {
                        Field    = "ParentId",
                        Operator = "eq",
                        Value    = id.ToString()
                    }
                },
                Logic = "and"
            };
            Expression <Func <TEntity, bool> > expression = filterInfo.TranslateFilter <TEntity>(true);
            List <TEntity> children = await this.BusinessRule.Queryable(false, true, (List <Expression <Func <TEntity, object> > >) null).Where <TEntity>(expression).ToListAsync <TEntity>();

            foreach (TEntity entity in children)
            {
                TEntity child = entity;
                if (!list.Any <TEntityVM>((Func <TEntityVM, bool>)(e => (int)idProp.GetValue((object)e) == child.ID)))
                {
                    TEntityVM childEntityVm = this.TranslateEntityToEntityVM(child);
                    childEntityVm.AsUnicode1256 <TEntityVM>();
                    list.Add(childEntityVm);
                    await this.AddChildrenToListAsync(childEntityVm, list);

                    childEntityVm = default(TEntityVM);
                }
            }
        }
        protected async Task AddParentToListAsync(
            TCustomQueryEntity item,
            List <TCustomQueryEntity> list)
        {
            PropertyInfo parentIdProp = item.GetType().GetProperty("ParentId");

            if (parentIdProp == (PropertyInfo)null)
            {
                return;
            }
            object parentIdValue = parentIdProp.GetValue((object)item);

            if (parentIdValue == null)
            {
                return;
            }
            FilterInfo filterInfo = new FilterInfo()
            {
                Filters = new List <FilterData>()
                {
                    new FilterData()
                    {
                        Field    = "ID",
                        Operator = "eq",
                        Value    = parentIdValue.ToString()
                    }
                }
            };
            Expression <Func <TCustomQueryEntity, bool> > expression = filterInfo.TranslateFilter <TCustomQueryEntity>(true);

            if (list.Any <TCustomQueryEntity>(expression.Compile()))
            {
                return;
            }
            int     parentIDIntVal = parentIdValue.ConvertTo <int>();
            TEntity entity         = await this.BusinessRule.Queryable(false, true, (List <Expression <Func <TEntity, object> > >) null).Where <TEntity>((Expression <Func <TEntity, bool> >)(en => en.ID == parentIDIntVal)).SingleOrDefaultAsync2 <TEntity>();

            TEntity parentEntity = entity;

            entity = default(TEntity);
            if ((object)parentEntity == null)
            {
                parentIdProp.SetValue((object)item, (object)null);
            }
            else
            {
                TCustomQueryEntity customQueryEntity = this.TranslateEntityToCustomQueryEntity(parentEntity);
                list.Add(customQueryEntity);
                await this.AddParentToListAsync(customQueryEntity, list);
            }
        }
Пример #3
0
        public async Task <List <Operation> > GetOperationAndMenusAsync(QueryInfo searchRequestInfo)
        {
            SecurityManager.ThrowIfUserContextNull();

            using (var uow = new UnitOfWork())
            {
                var operationQuery = uow.RepositoryAsync <Operation>()
                                     .Queryable()
                                     .Where(op => !op.IsDeleted && op.ApplicationId == ConfigurationController.ApplicationID);

                if (searchRequestInfo.Filter != null && searchRequestInfo.Filter.Filters != null && searchRequestInfo.Filter.Filters.Any())
                {
                    FilterInfo nameFilterInfo = new FilterInfo();
                    FilterInfo codeFilterInfo = new FilterInfo();

                    string namPropName = Entity.GetPropertyName <Operation>(op => op.Name);
                    if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == namPropName))
                    {
                        FilterData nameFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == namPropName);
                        nameFilterInfo.Filters.Add(new FilterData()
                        {
                            Field = namPropName, Operator = nameFilterData.Operator, Value = nameFilterData.Value
                        });

                        var operationExpression = nameFilterInfo.TranslateFilter <Operation>();
                        operationQuery = operationQuery.Where(operationExpression);
                    }

                    string codePropName = Entity.GetPropertyName <Operation>(op => op.Code);
                    if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == codePropName))
                    {
                        FilterData codeFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == codePropName);
                        codeFilterInfo.Filters.Add(new FilterData()
                        {
                            Field = codePropName, Operator = codeFilterData.Operator, Value = codeFilterData.Value
                        });

                        var operationExpression = codeFilterInfo.TranslateFilter <Operation>();
                        operationQuery = operationQuery.Where(operationExpression);
                    }
                }

                //if (!SecurityManager.CurrentUserContext.IsDeveloperUser())
                //    operationQuery = operationQuery.Where(op => !op.IsSystem);

                operationQuery = operationQuery.Where(op => op.OperationType != OperationType.Other);
                return(await operationQuery.ToListAsync2());
            }
        }
Пример #4
0
        protected virtual Expression <Func <TEntityVM, bool> > CreateSearchExpressionByFilterInfo(
            FilterInfo filterInfo)
        {
            if (ConfigurationController.P1Enabled)
            {
                foreach (FilterData filter in filterInfo.Filters)
                {
                    if (filter.Field.EndsWith("P1"))
                    {
                        FilterData filterData = filter;
                        string     input      = filter.Value;
                        string     str        = input != null?input.ToP1() : (string)null;

                        filterData.Value = str;
                    }
                }
            }
            return(filterInfo.TranslateFilter <TEntityVM>(true));
        }
Пример #5
0
        protected virtual async Task <List <TEntityVM> > PostExecuteQueryAsync(
            List <TEntityVM> list,
            QueryInfo searchRequestInfo)
        {
            list.ForEach((Action <TEntityVM>)(entityVm => entityVm.AsUnicode1256 <TEntityVM>()));
            bool isISelfReferenceEntity = (object)new TEntity() is ISelfReferenceEntity;

            if (!isISelfReferenceEntity || searchRequestInfo == null || (searchRequestInfo.Filter == null || searchRequestInfo.Filter.Filters == null) || !searchRequestInfo.Filter.Filters.Any <FilterData>())
            {
                return(list);
            }
            if (this.needSetHasChildren)
            {
                PropertyInfo hasChildrenPropInfo = ((IEnumerable <PropertyInfo>) typeof(TEntityVM).GetProperties()).FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(pInfo => pInfo.Name.ToLower() == "haschildren"));
                PropertyInfo idProp = ((IEnumerable <PropertyInfo>) typeof(TEntityVM).GetProperties()).FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(pInfo => pInfo.Name.ToLower() == "id"));
                if (hasChildrenPropInfo != (PropertyInfo)null && idProp != (PropertyInfo)null)
                {
                    TEntityVM[] entityVmArray = list.ToArray();
                    for (int index = 0; index < entityVmArray.Length; ++index)
                    {
                        TEntityVM  item       = entityVmArray[index];
                        object     id         = idProp.GetValue((object)item);
                        FilterInfo filterInfo = new FilterInfo()
                        {
                            Filters = new List <FilterData>()
                            {
                                new FilterData()
                                {
                                    Field    = "ParentId",
                                    Operator = "eq",
                                    Value    = id.ToString()
                                }
                            },
                            Logic = "and"
                        };
                        Expression <Func <TEntity, bool> > expression = filterInfo.TranslateFilter <TEntity>(true);
                        hasChildrenPropInfo.SetValue((object)item, (object)this.BusinessRule.Queryable(false, true, (List <Expression <Func <TEntity, object> > >)null).Where <TEntity>(expression).Any <TEntity>());
                        id         = (object)null;
                        filterInfo = (FilterInfo)null;
                        expression = (Expression <Func <TEntity, bool> >)null;
                        item       = default(TEntityVM);
                    }
                    entityVmArray = (TEntityVM[])null;
                }
                hasChildrenPropInfo = (PropertyInfo)null;
                idProp = (PropertyInfo)null;
            }
            if (searchRequestInfo.Filter.Filters.Count <FilterData>() == 1 && searchRequestInfo.Filter.Filters.Any <FilterData>((Func <FilterData, bool>)(fd => fd.Field.ToLower() == "parentid")))
            {
                return(list);
            }
            TEntityVM[] entityVmArray1 = list.ToArray();
            for (int index = 0; index < entityVmArray1.Length; ++index)
            {
                TEntityVM item = entityVmArray1[index];
                if (this.addChildrenToFilteredList)
                {
                    await this.AddChildrenToListAsync(item, list);
                }
                await this.AddParentToListAsync(item, list);

                item = default(TEntityVM);
            }
            entityVmArray1 = (TEntityVM[])null;
            return(list);
        }
Пример #6
0
        protected override IQueryable <UserInfoVM> CreateCustomQuery(IQueryable <UserInfo> query, QueryInfo searchRequestInfo)
        {
            var userRoleQuery = BusinessContext.GetBusinessRule <UserRole>(this.BusinessRule.OperationAccess, this.BusinessRule.UnitOfWork)
                                .Queryable();

            var roleQuery = this.BusinessRule.UnitOfWork.RepositoryAsync <RoleBase>()
                            .Queryable()
                            .Where(r => r.IsActive);

            #region FullName Filteration
            if (searchRequestInfo.Filter != null && searchRequestInfo.Filter.Filters != null && searchRequestInfo.Filter.Filters.Any())
            {
                string     userFullNamePropName   = Entity.GetPropertyName <UserInfoVM>(uVm => uVm.FullName);
                FilterData userFullNameFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == userFullNamePropName);
                if (userFullNameFilterData != null)
                {
                    FilterInfo userFullNamefilterInfo = new FilterInfo();
                    FilterData filterData             = new FilterData()
                    {
                        Logic = "or", Filters = new List <FilterData>()
                    };

                    string firstNameProp = Entity.GetPropertyName <UserInfo>(u => u.FirstName);
                    filterData.Filters.Add(new FilterData()
                    {
                        Field = firstNameProp, Operator = userFullNameFilterData.Operator, Value = userFullNameFilterData.Value
                    });

                    string lastNameProp = Entity.GetPropertyName <UserInfo>(u => u.LastName);
                    filterData.Filters.Add(new FilterData()
                    {
                        Field = lastNameProp, Operator = userFullNameFilterData.Operator, Value = userFullNameFilterData.Value
                    });

                    userFullNamefilterInfo.Filters.Add(filterData);
                    var userExpression = userFullNamefilterInfo.TranslateFilter <UserInfo>();
                    query = query.Where(userExpression);

                    searchRequestInfo.Filter.Filters.Remove(userFullNameFilterData);
                }
            }

            FilterInfo roleFilterInfo = new FilterInfo();
            if (searchRequestInfo.Filter != null && searchRequestInfo.Filter.Filters != null && searchRequestInfo.Filter.Filters.Any())
            {
                string roleNamesStrPropName = Entity.GetPropertyName <UserInfoVM>(uVm => uVm.RoleNamesStr);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == roleNamesStrPropName))
                {
                    FilterData roleNamesStrFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == roleNamesStrPropName);
                    string     roleNamesProp          = Entity.GetPropertyName <RoleBase>(role => role.Name);

                    roleFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = roleNamesProp, Operator = roleNamesStrFilterData.Operator, Value = roleNamesStrFilterData.Value
                    });

                    var roleExpression = roleFilterInfo.TranslateFilter <RoleBase>();
                    roleQuery = roleQuery.Where(roleExpression);
                }
            }
            #endregion

            #region Create CustomQuery
            var joinQuery = from user in query
                            join userRole in
                            (from userRole in userRoleQuery
                             join role in roleQuery
                             on userRole.RoleId equals role.ID
                             select new
            {
                UserID = userRole.UserId,
                RoleName = role.Name
            })
                            on user.ID equals userRole.UserID into userRoleGroup
                            select new
            {
                ID                 = user.ID,
                FirstName          = user.FirstName,
                LastName           = user.LastName,
                UserName           = user.UserName,
                MobileNo           = user.MobileNo,
                AuthenticationType = (int)user.AuthenticationType,
                Gender             = user.Gender,
                NationalCode       = user.NationalCode,
                UserRoleGroup      = userRoleGroup,
                IsActive           = user.IsActive,
                ApplicationId      = user.ApplicationId
            };

            if (roleFilterInfo.Filters.Any())
            {
                joinQuery = joinQuery.Where(q => q.UserRoleGroup.Any());
            }


            IQueryable <UserInfoVM> endQuery = joinQuery.Select(item => new UserInfoVM
            {
                ID                 = item.ID,
                LastName           = item.LastName,
                FirstName          = item.FirstName,
                UserName           = item.UserName,
                MobileNo           = item.MobileNo,
                AuthenticationType = item.AuthenticationType,
                NationalCode       = item.NationalCode,
                Gender             = item.Gender,
                RoleNames          = item.UserRoleGroup.Select(ur => ur.RoleName),
                IsActive           = item.IsActive,
                ApplicationId      = item.ApplicationId
            });

            return(endQuery);

            #endregion
        }
 protected virtual Expression <Func <TEntity, bool> > CreateSearchExpressionByFilterInfo(
     FilterInfo filterInfo)
 {
     return(filterInfo.TranslateFilter <TEntity>(true));
 }
Пример #8
0
        //protected override Expression<Func<Personel, bool>> CreateDefaultSearchExpression()
        //{
        //    if (SecurityManager.CurrentUserContext.IsOrganizationPersonnel())
        //        return person => person.OrganizationId == VBSUserContext.Current.OrganizationId;

        //    if (SecurityManager.CurrentUserContext.IsDeveloperUser() || SecurityManager.CurrentUserContext.IsAdminUser() ||
        //        SecurityManager.CurrentUserContext.IsSupplyChainUser() || SecurityManager.CurrentUserContext.IsSystematicallyPermissionUser())
        //        return base.CreateDefaultSearchExpression();

        //    return person => person.ID == 0;
        //}

        protected override IQueryable <PersonelVM> CreateCustomQuery(IQueryable <Personel> query, QueryInfo searchRequestInfo)
        {
            IQueryable <UserInfo>     shakhsQuery       = BusinessContext.GetBusinessRule <UserInfo>(Rule.OperationAccess, Rule.UnitOfWork).Queryable();
            IQueryable <Organization> organizationQuery = BusinessContext.GetBusinessRule <Organization>(Rule.OperationAccess, Rule.UnitOfWork).Queryable();
            IQueryable <Position>     positionQuery     = BusinessContext.GetBusinessRule <Position>(Rule.OperationAccess, Rule.UnitOfWork).Queryable();

            #region Query Processing
            if (searchRequestInfo.Filter != null && searchRequestInfo.Filter.Filters != null && searchRequestInfo.Filter.Filters.Any())
            {
                FilterInfo shakhsFilterInfo       = new FilterInfo();
                FilterInfo organizationFilterInfo = new FilterInfo();
                FilterInfo positionFilterInfo     = new FilterInfo();
                FilterInfo personelFilterInfo     = new FilterInfo();

                string namPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.FirstName);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == namPropName))
                {
                    FilterData namFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == namPropName);

                    string NamProp = Entity.GetPropertyName <UserInfo>(shakhs => shakhs.FirstName);
                    shakhsFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = NamProp, Operator = namFilterData.Operator, Value = namFilterData.Value
                    });

                    var shakhsExpression = shakhsFilterInfo.TranslateFilter <UserInfo>();
                    shakhsQuery = shakhsQuery.Where(shakhsExpression);
                }

                string namKhanevadegiPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.LastName);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == namKhanevadegiPropName))
                {
                    FilterData namKhanevadegiFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == namKhanevadegiPropName);

                    string NamKhanevadegiProp = Entity.GetPropertyName <UserInfo>(shakhs => shakhs.LastName);
                    shakhsFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = NamKhanevadegiProp, Operator = namKhanevadegiFilterData.Operator, Value = namKhanevadegiFilterData.Value
                    });

                    var shakhsExpression = shakhsFilterInfo.TranslateFilter <UserInfo>();
                    shakhsQuery = shakhsQuery.Where(shakhsExpression);
                }

                string codeMeliPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.NationalCode);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == codeMeliPropName))
                {
                    FilterData codeMeliFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == codeMeliPropName);

                    string CodeMeliProp = Entity.GetPropertyName <UserInfo>(shakhs => shakhs.NationalCode);
                    shakhsFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = CodeMeliProp, Operator = codeMeliFilterData.Operator, Value = codeMeliFilterData.Value
                    });

                    var shakhsExpression = shakhsFilterInfo.TranslateFilter <UserInfo>();
                    shakhsQuery = shakhsQuery.Where(shakhsExpression);
                }

                string telHamrahPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.MobileNo);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == telHamrahPropName))
                {
                    FilterData telHamrahFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == telHamrahPropName);

                    string TelHamrahProp = Entity.GetPropertyName <UserInfo>(shakhs => shakhs.MobileNo);
                    shakhsFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = TelHamrahProp, Operator = telHamrahFilterData.Operator, Value = telHamrahFilterData.Value
                    });

                    var shakhsExpression = shakhsFilterInfo.TranslateFilter <UserInfo>();
                    shakhsQuery = shakhsQuery.Where(shakhsExpression);
                }

                string onvanOrganizationPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.OnvanOrganization);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == onvanOrganizationPropName))
                {
                    FilterData onvanFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == onvanOrganizationPropName);

                    string onvanProp = Entity.GetPropertyName <Organization>(organization => organization.Title);
                    organizationFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = onvanProp, Operator = onvanFilterData.Operator, Value = onvanFilterData.Value
                    });

                    var organizationExpression = organizationFilterInfo.TranslateFilter <Organization>();
                    organizationQuery = organizationQuery.Where(organizationExpression);
                }

                string onvanPositionPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.OnvanPosition);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == onvanPositionPropName))
                {
                    FilterData onvanFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == onvanPositionPropName);

                    string onvanProp = Entity.GetPropertyName <Position>(position => position.Name);
                    positionFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = onvanProp, Operator = onvanFilterData.Operator, Value = onvanFilterData.Value
                    });

                    var positionExpression = positionFilterInfo.TranslateFilter <Position>();
                    positionQuery = positionQuery.Where(positionExpression);
                }

                string taTarikhPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.TaTarikh);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == taTarikhPropName))
                {
                    FilterData taTarikhFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == taTarikhPropName);

                    string taTarikhProp = Entity.GetPropertyName <Personel>(Personel => Personel.TaTarikh);
                    personelFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = taTarikhPropName, Operator = taTarikhFilterData.Operator, Value = taTarikhFilterData.Value
                    });

                    var personelExpression = personelFilterInfo.TranslateFilter <Personel>();
                    query = query.Where(personelExpression);
                }
                string azTarikhPropName = Entity.GetPropertyName <PersonelVM>(personel => personel.AzTarikh);
                if (searchRequestInfo.Filter.Filters.Any(filter => filter.Field == azTarikhPropName))
                {
                    FilterData azTarikhFilterData = searchRequestInfo.Filter.Filters.FirstOrDefault(filter => filter.Field == taTarikhPropName);

                    string azTarikhProp = Entity.GetPropertyName <Personel>(Personel => Personel.AzTarikh);
                    personelFilterInfo.Filters.Add(new FilterData()
                    {
                        Field = taTarikhPropName, Operator = azTarikhFilterData.Operator, Value = azTarikhFilterData.Value
                    });

                    var personelExpression = personelFilterInfo.TranslateFilter <Personel>();
                    query = query.Where(personelExpression);
                }
            }

            #endregion Query Processing

            IQueryable <PersonelVM> joinQuery = from personel in query
                                                join shakhs in shakhsQuery
                                                on personel.UserID equals shakhs.ID
                                                join organization in organizationQuery
                                                on personel.OrganizationId equals organization.ID
                                                join position in positionQuery
                                                on personel.RoleID equals position.ID
                                                select new PersonelVM
            {
                ID                = personel.ID,
                FirstName         = shakhs.FirstName,
                LastName          = shakhs.LastName,
                NationalCode      = shakhs.NationalCode,
                MobileNo          = shakhs.MobileNo,
                OnvanOrganization = organization.Title,
                OnvanPosition     = position.Name,
                AzTarikh          = personel.AzTarikh,
                DarHalKhedmat     = personel.DarHalKhedmat,
                TaTarikh          = personel.TaTarikh,
                RoleID            = personel.RoleID,
                OrganizationId    = personel.OrganizationId
            };

            return(joinQuery);
        }