/// <summary>
        /// 通过条件查询
        /// </summary>
        /// <param name="WhereString">查询条件</param>
        /// <returns>SysRolePermission实体类对象</returns>
        public List <SysRolePermission> SelectByWhere(string WhereString)
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@where", WhereString)
            };
            List <SysRolePermission> list  = new List <SysRolePermission>();
            SysRolePermission        model = null;

            using (SqlDataReader dr = DBHelper.RunProcedure("SysRolePermission_SelectByWhere", param))
            {
                while (dr.Read())
                {
                    model = new SysRolePermission();
                    model.PermissionId = Convert.ToInt32(dr["PermissionId"]);
                    model.RoleId       = Convert.ToInt32(dr["RoleId"]);
                    if (DBNull.Value != dr["PageCode"])
                    {
                        model.PageCode = dr["PageCode"].ToString();
                    }
                    model.IsDelete = Convert.ToBoolean(dr["IsDelete"]);
                    if (DBNull.Value != dr["PageValue"])
                    {
                        model.PageValue = Convert.ToInt32(dr["PageValue"]);
                    }
                    list.Add(model);
                }
            }
            return(list);
        }
        /// <summary>
        /// 查看全部
        /// </summary>
        /// <returns>list集合</returns>
        public List <SysRolePermission> SelectAll()
        {
            List <SysRolePermission> list  = new List <SysRolePermission>();
            SysRolePermission        model = null;

            using (SqlDataReader dr = DBHelper.RunProcedure("SysRolePermission_SelectAll", null))
            {
                while (dr.Read())
                {
                    model = new SysRolePermission();
                    model.PermissionId = Convert.ToInt32(dr["PermissionId"]);
                    model.RoleId       = Convert.ToInt32(dr["RoleId"]);
                    if (DBNull.Value != dr["PageCode"])
                    {
                        model.PageCode = dr["PageCode"].ToString();
                    }
                    model.IsDelete = Convert.ToBoolean(dr["IsDelete"]);
                    if (DBNull.Value != dr["PageValue"])
                    {
                        model.PageValue = Convert.ToInt32(dr["PageValue"]);
                    }
                    list.Add(model);
                }
            }
            return(list);
        }
        /// <summary>
        /// 通过Id查询
        /// </summary>
        /// <param name="Id">主键Id</param>
        /// <returns>SysRolePermission实体类对象</returns>
        public SysRolePermission SelectById(int Id)
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@PermissionId", Id)
            };
            SysRolePermission model = new SysRolePermission();

            using (SqlDataReader dr = DBHelper.RunProcedure("SysRolePermission_SelectById", param))
            {
                if (dr.Read())
                {
                    model.PermissionId = Convert.ToInt32(dr["PermissionId"]);
                    model.RoleId       = Convert.ToInt32(dr["RoleId"]);
                    if (DBNull.Value != dr["PageCode"])
                    {
                        model.PageCode = dr["PageCode"].ToString();
                    }
                    model.IsDelete = Convert.ToBoolean(dr["IsDelete"]);
                    if (DBNull.Value != dr["PageValue"])
                    {
                        model.PageValue = Convert.ToInt32(dr["PageValue"]);
                    }
                }
            }
            return(model);
        }
        public HttpResponseMessage Post([FromBody] SysRolePermission sysRolePermissionInfo)
        {
            return(ActionWarpper.Process(sysRolePermissionInfo, OperationCodes.ASYSRLPMS, () =>
            {
                var repo = RepositoryManager.GetRepository <ISysRolePermissionRepository>();
                repo.Insert(sysRolePermissionInfo);

                return Request.CreateResponse(HttpStatusCode.OK, sysRolePermissionInfo);
            }, this));
        }
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="SysRolePermission">SysRolePermission实体对象</param>
 /// <returns>bool值,判断是否操作成功</returns>
 public bool Add(SysRolePermission model)
 {
     SqlParameter[] param = new SqlParameter[]
     {
         new SqlParameter("@RoleId", model.RoleId),
         new SqlParameter("@PageCode", model.PageCode),
         new SqlParameter("@IsDelete", model.IsDelete),
         new SqlParameter("@PageValue", model.PageValue)
     };
     return(DBHelper.ExecuteNonQuery("SysRolePermission_Add", param));
 }
        public HttpResponseMessage Put(int id, [FromBody] SysRolePermission sysRolePermissionInfo)
        {
            return(ActionWarpper.Process(sysRolePermissionInfo, OperationCodes.MSYSRLPMS, () =>
            {
                sysRolePermissionInfo.SysRolePermissionID = id;
                var repo = RepositoryManager.GetRepository <ISysRolePermissionRepository>();
                repo.Update(sysRolePermissionInfo);

                return Request.CreateResponse(HttpStatusCode.OK);
            }, this));
        }
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="SysRolePermission">SysRolePermission实体对象</param>
 /// <returns>int值,返回自增ID</returns>
 public int AddReturnId(SysRolePermission model)
 {
     SqlParameter[] param = new SqlParameter[]
     {
         new SqlParameter("@RoleId", model.RoleId),
         new SqlParameter("@PageCode", model.PageCode),
         new SqlParameter("@IsDelete", model.IsDelete),
         new SqlParameter("@PageValue", model.PageValue)
     };
     return(Convert.ToInt32(DBHelper.ExecuteScalar("SysRolePermission_AddReturnId", param)));
 }
Пример #8
0
        public ActionResult SetData()
        {
            int     roleId = Request.Form["role_id"].ParseInt();
            SysRole ob     = uow.Role.Get(roleId);

            if (ob.RoleId <= 0)
            {
                ob.CreatedBy   = CurrentUID;
                ob.CreatedDate = CurrentDateTime;
            }
            ob.SiteId          = SITE_ID;
            ob.RoleName        = Request.Form["role_name"];
            ob.RoleDescription = Request.Form["role_description"];
            ob.UpdatedBy       = CurrentUID;
            ob.UpdatedDate     = CurrentDateTime;
            try
            {
                if (!ob.ValidateModel(out string errMsg))
                {
                    throw new Exception(errMsg);
                }

                if (!ob.FlagSystem)
                {
                    ob.FlagActive = Request.Form["flag_active"].ParseBoolean();
                    List <SysMenu> menus = uow.System.GetMenuBySiteId(ob.SiteId, 0);

                    foreach (SysMenu menu in menus)
                    {
                        foreach (SysMenuPermission permission in menu.SysMenuPermission)
                        {
                            SysRolePermission rolePermission = uow.Role.GetPermission(ob.RoleId, menu.MenuId, permission.PermissionId);
                            rolePermission.SysRole        = ob;
                            rolePermission.PermissionFlag = Request.Form[string.Format("permission-{0}-{1}", menu.MenuId, permission.PermissionId)].ParseBoolean();
                            uow.Role.SetPermission(rolePermission);
                        }
                    }
                }

                uow.Role.Set(ob);
                uow.SaveChanges();

                return(RedirectToAction("Index", new { area = "", controller = "Role", msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage();
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
Пример #9
0
 public void SetPermission(SysRolePermission ob)
 {
     if (db.SysRolePermission.Where(x =>
                                    x.RoleId == ob.RoleId &&
                                    x.MenuId == ob.MenuId &&
                                    x.PermissionId == ob.PermissionId).Count() <= 0)
     {
         db.SysRolePermission.Add(ob);
     }
     else
     {
         db.Entry(ob).State = EntityState.Modified;
     }
 }
Пример #10
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="entity"></param>
        /// <param name="pIds"></param>
        /// <returns></returns>
        public StateCode Save(long user_id, SysRole entity, string pIds)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                try
                {
                    long[] permissionIds = StringHelper.StringToLongArray(pIds);

                    s.StartTransaction();

                    if (entity.id == 0)
                    {
                        entity.created_date    = DateTime.Now;
                        entity.created_user_id = user_id;
                        s.Insert <SysRole>(entity);
                    }
                    else
                    {
                        entity.updated_date    = DateTime.Now;
                        entity.updated_user_id = user_id;
                        s.Update <SysRole>(entity);
                    }

                    //角色权限处理
                    s.ExcuteUpdate("delete tb_sys_role_permission where role_id = @0", entity.id);
                    for (int i = 0; i < permissionIds.Length; i++)
                    {
                        int exist = s.Exist <SysPermission>("where id = @0", permissionIds[i]);
                        if (exist > 0)
                        {
                            SysRolePermission rp = new SysRolePermission();
                            rp.role_id       = entity.id;
                            rp.permission_id = permissionIds[i];
                            s.Insert <SysRolePermission>(rp);
                        }
                    }
                    s.Commit();
                    return(StateCode.State_200);
                }
                catch
                {
                    s.RollBack();
                    return(StateCode.State_500);
                }
            }
        }
Пример #11
0
        /// <summary>
        /// 数据访问通过条件查询并分页排序
        /// </summary>
        /// <param name="WhereString">查询条件</param>
        /// <param name="PageIndex">当前页码</param>
        /// <param name="PageSize">页大小(每页显示多少条数据)</param>
        /// <param name="OrderString">排序条件(排序条件为必须参数)</param>
        /// <returns>SysRolePermission实体类对象</returns>
        public List <SysRolePermission> SelectByWhereAndPage(string WhereString, int PageIndex, int PageSize, string OrderString, out int TotalCount)
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@where", WhereString),
                new SqlParameter("@pageIndex", PageIndex),
                new SqlParameter("@pageSize", PageSize),
                new SqlParameter("@orderString", OrderString),
                new SqlParameter("@TotalCount", ParameterDirection.Output)
            };
            List <SysRolePermission> list  = new List <SysRolePermission>();
            SysRolePermission        model = null;

            using (SqlDataReader dr = DBHelper.RunProcedure("SysRolePermission_SelectByWhereAndPage", param))
            {
                while (dr.Read())
                {
                    model = new SysRolePermission();
                    model.PermissionId = Convert.ToInt32(dr["PermissionId"]);
                    model.RoleId       = Convert.ToInt32(dr["RoleId"]);
                    if (DBNull.Value != dr["PageCode"])
                    {
                        model.PageCode = dr["PageCode"].ToString();
                    }
                    model.IsDelete = Convert.ToBoolean(dr["IsDelete"]);
                    if (DBNull.Value != dr["PageValue"])
                    {
                        model.PageValue = Convert.ToInt32(dr["PageValue"]);
                    }
                    list.Add(model);
                }
                if (dr.NextResult() && dr.Read())
                {
                    TotalCount = Convert.ToInt32(dr["TotalCount"]);
                }
                else
                {
                    TotalCount = 0;
                }
            }
            return(list);
        }
Пример #12
0
        public List <SysRolePermission> GetPermissionsFromUI()
        {
            var result = new List <SysRolePermission>();

            var nodes = new List <TriStateTreeViewNode>();

            TreeViewSource.ForEach(x => nodes.AddRange(x.ConvertToList()));

            var allElements = SysPermissionProvider.GetInstance().AllSysModuleElements;
            var elements    = nodes.FindAll(x => x.NodeType == ElementNodeType && x.IsChecked == true);

            foreach (var element in elements)
            {
                var permission = new SysRolePermission()
                {
                    RoleID      = RoleID,
                    ElementInfo = allElements.FirstOrDefault(x => x.ElementID == element.ID),
                };
                result.Add(permission);
            }

            var allModules = SysPermissionProvider.GetInstance().AllSysModules;
            var modules    = nodes.FindAll(x => x.NodeType == ModuleNodeType && x.IsChecked == true);

            foreach (var module in modules)
            {
                var permission = new SysRolePermission()
                {
                    RoleID     = RoleID,
                    ModuleInfo = allModules.FirstOrDefault(x => x.ModuleID == module.ID),
                };
                result.Add(permission);
            }

            return(result);
        }
Пример #13
0
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="SysRolePermission">SysRolePermission实体对象</param>
 /// <returns>bool值,判断是否操作成功</returns>
 public bool Add(SysRolePermission model)
 {
     return(dal.Add(model));
 }
Пример #14
0
 public int Add(SysRolePermission model)
 {
     return(this._rolePermissionRepository.Insert(model));
 }
Пример #15
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="SysRolePermission">SysRolePermission实体对象</param>
 /// <returns>bool值,判断是否操作成功</returns>
 public bool Change(SysRolePermission model)
 {
     return(dal.Change(model));
 }
Пример #16
0
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="SysRolePermission">SysRolePermission实体对象</param>
 /// <returns>int值,返回自增ID</returns>
 public int AddReturnId(SysRolePermission model)
 {
     return(dal.AddReturnId(model));
 }
Пример #17
0
        public ActionResult SetData()
        {
            int     roleId = Request.Form["role_id"].ParseInt();
            SysRole ob     = uow.Modules.Role.Get(roleId);

            List <SysRolePermission> result = new List <SysRolePermission>();

            if (ob.RoleId <= 0)
            {
                ob.CreatedBy   = CurrentUID;
                ob.CreatedDate = CurrentDate;
            }
            ob.SiteId          = SiteId;
            ob.RoleName        = Request.Form["role_name"];
            ob.RoleDescription = Request.Form["role_description"];
            ob.UpdatedBy       = CurrentUID;
            ob.UpdatedDate     = CurrentDate;
            try
            {
                if (!ob.IsValid(out string errMsg))
                {
                    throw new Exception(errMsg);
                }

                if (!ob.FlagSystem)
                {
                    MenuLayoutModel md = new MenuLayoutModel();
                    ob.FlagActive = Request.Form["flag_active"].ParseBoolean();


                    List <SysMenu> menus = uow.Modules.System.GetMenuBase(ob.SiteId);


                    md.Menus = new List <MenuModel>();
                    foreach (SysMenu menu in menus)
                    {
                        md.Menus.Add(ConvertToMenuModel(menu));
                    }

                    int permissionId = 1;
                    SysRolePermission rolePermission = null;
                    foreach (MenuModel menu in md.Menus)
                    {
                        rolePermission                = new SysRolePermission();
                        rolePermission.RoleId         = ob.RoleId;
                        rolePermission.MenuId         = menu.MenuId;
                        rolePermission.PermissionId   = 1;
                        rolePermission.PermissionFlag = Request.Form[string.Format("permission-{0}-{1}", menu.MenuId, rolePermission.PermissionId)].ParseBoolean();
                        result.Add(rolePermission);

                        foreach (MenuModel permission in menu.SubMenus)
                        {
                            for (permissionId = 1; permissionId <= 3; permissionId++)
                            {
                                rolePermission                = new SysRolePermission();
                                rolePermission.RoleId         = ob.RoleId;
                                rolePermission.MenuId         = permission.MenuId;
                                rolePermission.PermissionId   = permissionId;
                                rolePermission.PermissionFlag = Request.Form[string.Format("permission-{0}-{1}", permission.MenuId, permissionId)].ParseBoolean();

                                result.Add(rolePermission);
                            }
                            //   uow.Modules.RolePermission.Set(rolePermission);
                        }
                    }
                }
                uow.Modules.RolePermission.Add(result);
                uow.Modules.Role.Set(ob);
                uow.SaveChanges();

                return(RedirectToAction("Index", new { area = "", controller = "Role", msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage();
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
Пример #18
0
 public bool Update(SysRolePermission model)
 {
     return(this._rolePermissionRepository.Update(model));
 }