• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ASP.NETMVC4.0+EF+LINQ+bui+网站+角色权限管理系统(5)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

我参考了bui官网,里面提供了大量的接口案例和效果,之前下载的前端框架完全不需要bootstrap,所以从这一节开始,不再使用bootstrap(当然不想改变的也可以继续使用之前的框架,不影响使用),我会把现在改变的样式和js的Content文件共享出来:

下载Content替换就行:http://pan.baidu.com/s/1eQWsOIQ,密码:5fch

 然后改变_Layout_Admin.cshtml中的链接

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
      <link href="~/Content/assets/css/dpl.css" rel="stylesheet" type="text/css" />
      <link href="~/Content/assets/css/bui.css" rel="stylesheet" type="text/css" />
      <link href="~/Content/assets/css/page.css" rel="stylesheet" type="text/css" />
       <link href="~/Content/Css/style.css" rel="stylesheet" type="text/css"  />
      
      <script type="text/javascript" src="~/Content/assets/js/jquery-1.8.1.min.js"></script>
      <script type="text/javascript" src="~/Content/assets/js/bui-min.js"></script>
      <script type="text/javascript" src="~/Content/assets/js/config.js"></script>
    
      <script src="@Url.Content("~/Content/ueditor/ueditor.config.js")"></script>
     <script src="@Url.Content("~/Content/ueditor/ueditor.all.min.js")"></script>
     <script src="@Url.Content("~/Content/ueditor/lang/zh-cn/zh-cn.js")"></script>
</head>
<body>
    <div>
        @RenderBody()
    </div>
</body>
    
</html>
View Code

UserProfilesSetRole.cshtml

@model MVCSystem.Web.Models.M_UserProfile
@{
    ViewBag.Title = "UserProfilesSetRole";
    Layout = "~/Areas/Admin/Views/Shared/_Layout_Admin.cshtml";
}

@using (Html.BeginForm())
{
    <input type="hidden" id="User_ID" value="@Model.UserId"/>
  
     <table class="table table-bordered" style="width:auto;">
        <tr>
            <td width="40%" class="tableleft">角色设置</td>
            <td><span id="updateMessage"></span></td>
        </tr>
        
         <tr>
           
            <td colspan="2" class="controls"> @Html.Raw(ViewBag.roleList) </td>
        </tr>
       
    </table>
}
<script type="text/javascript">
    $(function () { 
        $(".controls input").change(function () {
            var sUserId = $("#User_ID").val();
            var value = sUserId + "," + $(this).val();

            if ($(this).is(":checked")) {

                var url = "/Admin/Users/SetRole/" + value;
            }
            else {
                url = "/Admin/Users/RemoveRole/" + value;
            }

            var objUpdateMessage = $("#updateMessage");
            $.getJSON(url, function (data) {
                if (objUpdateMessage.length > 0) {
                    objUpdateMessage.fadeIn();
                    objUpdateMessage.css("color", "green");
                    objUpdateMessage.html("设置成功!");
                    objUpdateMessage.fadeOut("slow");
                }
            });

        });
       
    })
</script>
View Code

如今效果如下

接着完成搜索查询功能

Users/Index.cshtml

@using MVCSystem.Web;
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout_Admin.cshtml";
}
<div class="container">
<form id="searchForm" class="form-horizontal"> 
    用户名:
    <input type="text"  name="SearchString" id="SearchString" class="abc input-default" placeholder="" value="">&nbsp;&nbsp;  
    <button type="button" id="SearchBtn" class="button button-primary">查询</button>&nbsp;&nbsp; <a href="/Admin/Users/UserProfilesAdd/" class="button button-success" id="addnew">新增用户</a>
</form>
<div id="gridList"  style="margin:10px auto;">     
</div>
<div id="windDlog" class="hidden">

</div>
</div>
    <script type="text/javascript">
        GridData("");
        $("#SearchBtn").click(function () {
            $("#gridList").html("");
            GridData($("#SearchString").val());
        })
        function GridData(searchKay) {
            BUI.use(['bui/grid', 'bui/data'], function (Grid, Data) {
                var Grid = Grid,
              Store = Data.Store,
              columns = [
                { title: '用户名', dataIndex: 'UserName', width: 200 },
                { title: '邮箱', dataIndex: 'UserEmail', width: 200 },
                { title: '真实姓名', dataIndex: 'RealName', width: 200 },
                { title: '状态', dataIndex: 'State', width: 100 },
                { title: '用户角色', dataIndex: 'UserRole', width: 200 },
                { title: '操作', dataIndex: 'CZ', width: 200 }
              ];

                var store = new Store({
                    url: '/Admin/Users/GetList',
                    autoLoad: true, //自动加载数据
                    params: {
                        searchString: searchKay//关键字查询
                    },
                    pageSize: 3    // 配置分页数目
                }),
                  grid = new Grid.Grid({
                      render: '#gridList',
                      columns: columns,
                      loadMask: true, //加载数据时显示屏蔽层
                      store: store,
                      // 底部工具栏
                      bbar: {
                          // pagingBar:表明包含分页栏
                          pagingBar: true
                      }
                  });

                grid.render();
            });
        }
        function DeleteShow(UserId) {
            BUI.use('bui/overlay',function(overlay){
                BUI.Message.Show({
               
                    msg : '你确定要删除吗?',
                    icon : 'question',
                    buttons : [
                      {
                          text:'确定',
                          elCls : 'button button-primary',
                          handler : function(){
                              $.post("/Admin/Users/UserProfilesDelete/" + UserId + "", function (data) {
                                 location.reload();
                                  if (data == 1) {
                                      BUI.Message.Show({
                                          msg: '删除成功',
                                          icon: 'success',
                                          buttons: [],
                                          autoHide: true,
                                          autoHideDelay: 1000
                                      });
                                  
                                  }
                                  else {
                                      BUI.Message.Show({
                                          msg: '删除失败',
                                          icon: 'error',
                                          buttons: [],
                                          autoHide: true,
                                          autoHideDelay: 1000
                                      });
                                  }

                                  
                              }, "json");
                          }
                      },
                      {
                          text:'取消',
                          elCls : 'button',
                          handler : function(){
                              this.close();
                          }
                      }
 
                    ]
          
                })
            })
        }


        function SetRole(userId){
            $("#windDlog").html("<iframe width='100%' height='98%' frameborder='0'' src='/Admin/Users/UserProfilesSetRole/" + userId + "'></iframe>");
            BUI.use(['bui/overlay','bui/form'],function(Overlay,Form){
                var dialog = new Overlay.Dialog({
                    title: '角色设置',
                    width: 240,
                    height: 210,
                    //配置DOM容器的编号
                    contentId: 'windDlog',
                    mask: false,
                    buttons: [
                      {
                          text: '确定',
                          elCls: 'button button-primary',
                          handler: function () {
                              location.reload();
                              this.close();
                          }
                      }
                    ],
                });
                dialog.show();
            })
        }
    </script>
View Code

Controllers/UsersController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using MVCSystem.Web.Common;
using MVCSystem.Web.Filters;
using MVCSystem.Web.Models;
using WebMatrix.WebData;

namespace MVCSystem.Web.Areas.Admin.Controllers
{
     [InitializeSimpleMembership]
    public class UsersController : BaseController
    {
        //
        // GET: /Admin/Users/
         /// <summary>
         /// 获取数据列表
         /// </summary>
         /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        public JsonResult GetList(GridPager pager, string searchString)
        {
            var aList = from w in db.DB_UserProfiles select w;
            if (!string.IsNullOrEmpty(searchString))
            {
                aList = aList.Where(w => w.UserName.Contains(searchString));

            }
              var json = new
            {
                results = aList.ToList().Count,
                rows = aList.ToList().Select(a => new
                        {
                            UserId = a.UserId,
                            UserName = a.UserName,
                            UserEmail = a.Email,
                            RealName = a.RealName,
                            State = (a.State==1)?"启用":"禁用",
                            UserRole=getRoleName(a.UserId),
                            CZ = "<a href='javascript:;' onclick='SetRole(" + a.UserId + ")' id='SetRole'>角色设置</a><a href='/Admin/Users/UserProfilesEdit/" + a.UserId + "' id='Edit'>编辑</a><a href='javascript:;' onclick='DeleteShow(" + a.UserId + ")' id='Delete'>删除</a>"

                        }).Skip((pager.pageIndex) * pager.limit).Take(pager.limit).OrderByDescending(a => a.UserId).ToList().ToArray()
            };
            return Json(json, JsonRequestBehavior.AllowGet);
        }
         private string getRoleName(int UsId)
        {
            var gg = (from a in db.DB_UsersInRoles
                      join b in db.DB_Roles
                       on a.RoleId equals b.RoleId
                      group new { a, b } by new { a.UserId, b.RoleName } into kk
                      select new
                      {
                          userId = kk.Key.UserId,
                          roleName = kk.Key.RoleName
                      }).ToList();
            var getRoleNameStr = String.Join("", gg.Where(d => d.userId == UsId).Select(e => e.roleName).ToArray());
            return getRoleNameStr;
        }

         /// <summary>
         /// 删除数据操作
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
         [HttpPost]
         public JsonResult UserProfilesDelete(int id)
         {
             if (id > 0)
             {
                 var aList = db.DB_UserProfiles.Find(id);
                 db.DB_UserProfiles.Remove(aList);
                 db.SaveChanges();
                 return Json(1, JsonRequestBehavior.AllowGet);
             }
             else
             {
                 return Json(0, JsonRequestBehavior.AllowGet);
             }
         }
         /// <summary>
         /// 编辑数据操作
         /// </summary>
         ///  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ASP.NETPOST方式提交数据发布时间:2022-07-10
下一篇:
ASP.NETCore2.2十八.各种Filter的内部处理机制及执行顺序(转)发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap