Ejemplo n.º 1
0
        public async Task <JsonResult> GetUserPermissionByPage(UserPermissionRequest request)
        {
            var returnValue = new List <UserPermissionViewModel>();

            if (request == null)
            {
                return(Json(new { code = -1, msg = "无参数信息", count = 0, data = returnValue }, JsonRequestBehavior.AllowGet));
            }
            if (request.Page <= 0)
            {
                request.Page = 1;
            }
            if (request.Limit <= 0)
            {
                request.Limit = 50;
            }
            var memberBll    = new MemberService();
            var requestModel = new UserPermissionModel {
                Name = request.PermissionName,
                MembershipsGradeId = request.MembershipsGradeId
            };
            var count           = DALUserPermission.QueryPageCount(requestModel);
            var dataResult      = DALUserPermission.QueryPageList(requestModel, request.Page, request.Limit);
            var memberGradeList = await memberBll.GetMembershipsGradeListAsync();

            if (memberGradeList != null && memberGradeList.Count > 0 && dataResult != null && dataResult.Count > 0)
            {
                foreach (var userPermission in dataResult)
                {
                    var viewModel  = ObjectMapper.ConvertTo <UserPermissionModel, UserPermissionViewModel>(userPermission);
                    var gradeModel = memberGradeList.Find(t => t.PKID == userPermission.MembershipsGradeId);
                    viewModel.LastUpdateDateTime = userPermission.LastUpdateDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                    viewModel.CreateDatetime     = userPermission.CreateDatetime.ToString("yyyy-MM-dd HH:mm:ss");
                    if (gradeModel != null)
                    {
                        viewModel.MembershipsGradeName = gradeModel.GradeName;
                    }
                    returnValue.Add(viewModel);
                }
            }
            return(Json(new { code = 0, msg = "加载成功", count = count, data = returnValue.OrderByDescending(t => t.Id) }, JsonRequestBehavior.AllowGet));
        }