Beispiel #1
0
        /// <summary>
        /// Get paging by condition
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="parentId"></param>
        /// <param name="isPanel"></param>
        /// <param name="group"></param>
        /// <param name="status"></param>
        /// <param name="userId"></param>
        /// <param name="isDeleted"></param>
        /// <param name="order"></param>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static PageResult <MenuModel> GetPaging(string keyword, int?parentId, bool?isPanel, MenuGroup?group, MenuStatus?status, int?userId,
                                                       bool?isDeleted, string order, int start, int limit)
        {
            // init condition
            var condition = "1=1";

            // keyword
            if (!string.IsNullOrEmpty(keyword))
            {
                condition += " AND ([MenuName] LIKE N'%{0}%' OR [TabName] LIKE N'%{0}%')".FormatWith(keyword.EscapeQuote());
            }

            // parent id
            if (parentId != null)
            {
                condition += " AND [ParentId]={0}".FormatWith(parentId.Value);
            }

            // is panel
            if (isPanel != null)
            {
                condition += " AND [IsPanel]={0}".FormatWith(isPanel.Value ? 1 : 0);
            }

            // group
            if (group != null)
            {
                condition += " AND [Group]={0}".FormatWith((int)group.Value);
            }

            // status
            if (status != null)
            {
                condition += " AND [Status]={0}".FormatWith((int)status.Value);
            }

            // userId
            if (userId != null)
            {
                condition += @" AND [Id] IN (" +
                             "      SELECT [MenuId] FROM [MenuRole] WHERE [RoleId] IN (" +
                             "          SELECT [RoleId] FROM [UserRole] WHERE [UserId]='{0}'))".FormatWith(userId.Value);
            }

            // deleted
            if (isDeleted != null)
            {
                condition += " AND [IsDeleted]={0}".FormatWith(isDeleted.Value ? 1 : 0);
            }

            // get result
            var result = MenuServices.GetPaging(condition, order, start, limit);

            // return
            return(new PageResult <MenuModel>(result.Total, result.Data.Select(r => new MenuModel(r)).ToList()));
        }