Пример #1
0
        public List <VM.RoleItemModel> GetRoleList(VM.RoleSearchModel search)
        {
            Expression <Func <MD.Common_Authen_Role, bool> > expr = null;
            string sortBy        = "RoleName";
            string sortDirection = "DESC";

            if (string.IsNullOrWhiteSpace(search.SortBy))
            {
                search.SortBy        = sortBy;
                search.SortDirection = sortDirection;
            }
            IQueryable <MD.Common_Authen_Role> resultQuery = null;

            expr = this.BuildSearchCriteria(search);
            if (expr == null)
            {
                resultQuery = ctx.Common_Authen_Role.SortWith(search.SortBy, search.SortDirection);
            }
            else
            {
                resultQuery = ctx.Common_Authen_Role.Where(expr).SortWith(search.SortBy, search.SortDirection);
            }
            search.RecordCount = resultQuery.Count();
            resultQuery        = resultQuery.Skip(search.PageSkip).Take(search.PageSize);
            Message            = new MessageModel()
            {
                IsSuccess = true, MessageType = Model.Common.MessageType.SelectSuccess, Message = MessageResource.Message_CommonLoadSuccessful
            };
            return(this.ConvertViewModelList(resultQuery));
        }
Пример #2
0
        private Expression <Func <MD.Common_Authen_Role, bool> > BuildSearchCriteria(VM.RoleSearchModel search)
        {
            Expression <Func <MD.Common_Authen_Role, bool> > expr  = null;
            DynamicLambda <MD.Common_Authen_Role>            bulid = new DynamicLambda <MD.Common_Authen_Role>();

            if (!string.IsNullOrEmpty(search.RoleName))
            {
                Expression <Func <MD.Common_Authen_Role, bool> > temp = s => s.RoleName.Contains(search.RoleName);
                expr = bulid.BuildQueryAnd(expr, temp);
            }
            return(expr);
        }