public Boolean CheckDuplicate(RoleRight roleRight,Boolean IsInsert)
 {
     Boolean Result = true;
     try
     {
         var c = _roleRightRepository.GetSingle(p => p.RoleRightsID == roleRight.RoleRightsID);
         if (!IsInsert)
         {
             if (c == null)
                 Result = true;
             else if (c.RoleRightsID == roleRight.RoleRightsID)
                 Result = true;
             else
                 Result = false;
         }
         else
         {
             if (c == null)
                 Result = true;
             else
                 Result = false;
         }
     }
     catch (Exception ex)
     {
         //bool false = BusinessLogicExceptionHandler.HandleException(ref ex);
         if (false)
         {
             throw ex;
         }
     }
     return Result;
 }
Пример #2
0
 public void AddRoleRight(RoleRight roleRight)
 {
     roleRight.LastModifiedDateUtc = DateTime.UtcNow;
     roleRight.CreatedDateUtc      = DateTime.UtcNow;
     roleRight.LastModifiedBy      = 1;
     _repository.Create(roleRight);
 }
Пример #3
0
        public JsonResult SaveSecurables(string role, List <SecurableViewModel> securableViewModel)
        {
            JsonResult       result         = new JsonResult();
            List <RoleRight> roleRightsList = new List <RoleRight>();

            foreach (var item in securableViewModel)
            {
                RoleRight roleRights = null;
                roleRights = RoleRightService.GetRoleRights <RoleRight>(rr => rr.SecurableID == item.Id && rr.RoleCode.ToLower() == role.ToLower() && rr.AccessRight > 0).FirstOrDefault();

                if (item.IsChecked)
                {
                    if (roleRights == null)
                    {
                        roleRights = new RoleRight();
                    }
                    roleRights.CompanyId   = USER_OBJECT.CompanyId;
                    roleRights.RoleCode    = role;
                    roleRights.SecurableID = item.Id;
                    roleRights.AccessRight = Convert.ToInt16(item.Access);

                    roleRightsList.Add(roleRights);
                }
            }
            RoleRightService.SaveRoleRights(roleRightsList);
            return(result);
        }
Пример #4
0
        public IHttpActionResult PutRoleRight(int id, RoleRight roleRight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != roleRight.RoleRightId)
            {
                return(BadRequest());
            }

            db.Entry(roleRight).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoleRightExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #5
0
        /// <summary>
        /// 提交处理
        /// </summary>
        /// <param name="RoletId">角色Id</param>
        /// <param name="Name">角色名</param>
        /// <param name="Remark">备注</param>
        /// <param name="Right">权利Id的数组</param>
        /// <returns></returns>
        public ActionResult  CreateEdit(string RoleId, string Name, string Remark, int[] Right)
        {
            Role role;

            EntitySet <RoleRight> rights = new EntitySet <RoleRight>();

            if (Right != null)
            {
                foreach (int code in Right)
                {
                    RoleRight rr = new RoleRight();
                    rr.RightCode = code;
                    rights.Add(rr);
                }
            }

            if (string.IsNullOrEmpty(RoleId))
            {
                role = new Role();
            }
            else
            {
                role = db.GetOneRole(int.Parse(RoleId));
            }
            db.DeleteAllOnSubmit(role.RoleRight);
            role.RoleRight = rights;
            role.Name      = Name;
            role.Remark    = Remark;
            db.Save(role);
            return(Json("OK"));
        }
Пример #6
0
 private void CheckRightData(RoleRight roleRight)
 {
     foreach (Right right in rightList)
     {
         if (right.RightID == roleRight.RightID)
         {
             right.Choose = true;
         }
     }
 }
Пример #7
0
 /// <summary>
 /// 系统角色权限
 /// </summary>
 private void InitSysRight()
 {
     foreach (var r in this.roleRights)
     {
         RoleRight roleRight = new RoleRight {
             moduleId = r.String("modulId"), code = r.String("code"), isProjectRight = false
         };
         this.sysRoleRights.Add(roleRight);
     }
     this.sysRoleRights = this.sysRoleRights.Distinct(new SysRoleRightComparer()).ToList();
 }
Пример #8
0
        public IHttpActionResult GetRoleRight(int id)
        {
            RoleRight roleRight = db.RoleRights.Find(id);

            if (roleRight == null)
            {
                return(NotFound());
            }

            return(Ok(roleRight));
        }
        public ActionResult AddRoleRight(RoleRight roleRight)
        {
            ViewBag.UserRoles = db.Departments;

            if (ModelState.IsValid)
            {
                db.RoleRights.Add(roleRight);
                db.SaveChanges();
                return(View());
            }
            return(View(roleRight));
        }
Пример #10
0
        public void RemoveroleRight(RoleRight roleRight, bool autoCommit = true)
        {
            if (roleRight.Id > 0)
            {
                RoleRightRepository.Remove(roleRight);
            }

            if (autoCommit)
            {
                RoleRightRepository.Commit();
            }
        }
Пример #11
0
        public IHttpActionResult PostRoleRight(RoleRight roleRight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RoleRights.Add(roleRight);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = roleRight.RoleRightId }, roleRight));
        }
Пример #12
0
        private ViewRight Map(RoleRight right)
        {
            if (right == null)
            {
                return(null);
            }

            return(new ViewRight
            {
                Id = right.Right.Id,
                Name = right.Right.Name
            });
        }
Пример #13
0
        public IHttpActionResult DeleteRoleRight(int id)
        {
            RoleRight roleRight = db.RoleRights.Find(id);

            if (roleRight == null)
            {
                return(NotFound());
            }

            db.RoleRights.Remove(roleRight);
            db.SaveChanges();

            return(Ok(roleRight));
        }
Пример #14
0
        public void SaveRoleRights(RoleRight roleRights, bool autoCommit = true)
        {
            if (roleRights.Id == 0)
            {
                RoleRightRepository.Insert(roleRights);
            }
            else
            {
                RoleRightRepository.Update(roleRights);
            }

            if (autoCommit == true)
            {
                RoleRightRepository.Commit();
            }
        }
Пример #15
0
        private static IList <RoleRight> GetRoleRightBySql(string sql, params SqlParameter[] parametsers)
        {
            IList <RoleRight> lists = new List <RoleRight>();
            DataTable         table = DBHelper.GetDataSet(sql, parametsers);

            foreach (DataRow row in table.Rows)
            {
                RoleRight roleRight = new RoleRight();
                roleRight.RoleRightId = Convert.ToInt32(row["RoleRightId"]);
                //外键对象
                roleRight.Role = RoleService.GetRoleById(Convert.ToInt32(row["roleId"]));

                roleRight.Node = SysFunService.GetSysFunById(Convert.ToInt32(row["NodeId"]));

                lists.Add(roleRight);
            }
            return(lists);
        }
Пример #16
0
        public void SetRole(List <UserViewDetail> lstuserviewdetail, int roleid)
        {
            _context.RoleRights.RemoveRange(_context.RoleRights.Where(x => x.RoleId == roleid));
            _context.SaveChanges();

            foreach (UserViewDetail item in lstuserviewdetail)
            {
                RoleRight rights = new RoleRight
                {
                    RightType = item.RightType,
                    RoleId    = item.RoleId,
                    ViewId    = item.ViewId
                };

                _context.RoleRights.Add(rights);
            }

            _context.SaveChanges();
        }
Пример #17
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List <SysModule> modulelist = db.SysModule.Where(t => t.ParentID == -1 && t.IsRight == 1).OrderBy(t => t.ModuleOrder).ToList();
                List <object>    joinlist   = new List <object>();
                if (modulelist.Count > 0)
                {
                    foreach (SysModule module in modulelist)
                    {
                        string    rid       = "";
                        int       moduleid  = Convert.ToInt32(module.ID);
                        RoleRight roleright = db.RoleRight.FirstOrDefault(t => t.RoleID == RoleID && t.ModuleID == moduleid);
                        if (roleright != null)
                        {
                            rid = roleright.RoleID.ToString();
                        }
                        joinlist.Add(new
                        {
                            module.ID,
                            module.Name,
                            module.ModuleUrl,
                            module.ModuleIcon,
                            module.ParentID,
                            module.ModuleOrder,
                            module.IsRight,
                            module.ModuleButton,
                            rid
                        });
                    }
                }

                this.rpmodule.DataSource = joinlist;
                this.rpmodule.DataBind();

                Role model = db.Role.FirstOrDefault(t => t.ID == RoleID);
                if (model != null)
                {
                    this.lblrolename.Text = model.Name;
                }
            }
        }
Пример #18
0
        void Btn_Ok_Click(object sender, EventArgs e)
        {
            try
            {
                /* 清空原有数据 */
                new RoleRightDao().DeleteWithRoleId(RoleId);
                string StrRightID = null;
                /* 新增新的数据 */
                var chooseRow = rightList.FindAll(m => m.Choose == true);
                //foreach (Right rig in rightList)
                //{
                //    if (rig.Choose)
                //    {
                //    }
                //}
                StrRightID = string.Join(",", chooseRow.Select(n => n.RightID));

                RoleRight ri = new RoleRight();
                ri.ModifierID = Program.CurrentEmployee.EmployeeID;
                ri.ModifyTime = DateTime.Now;
                ri.StrRightID = StrRightID;
                ri.RoleID     = RoleId;
                if (StrRightID == null)
                {
                    return;
                }
                bool results = new RoleRightDao().AddList(ri);
                if (results)
                {
                    MsgBox.ShowInfo("权限设置成功", "提示");
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
        }
Пример #19
0
 /// <summary>
 /// 项目角色权限
 /// </summary>
 private void InitProjectRoleRight()
 {
     //获取项目角色
     GetSysProjectRight();                                                   //系统设置的项目权限
     GetInitProjectRight();                                                  //内置项目权限
     foreach (var dataScope in this.scopeList.Distinct(new ScopeComparer())) //所有拥有权限的区域
     {
         var tempRoleRights = this.roleRights.Where(s => s.Int("roleId") == dataScope.Int("roleId"));
         foreach (var temp in tempRoleRights)
         {
             RoleRight roleRight = new RoleRight
             {
                 code           = temp.String("code"),
                 isProjectRight = true,
                 areaRoleType   = dataScope.String("dataTableName"),
                 dataId         = dataScope.String("dataId")
             };
             this.projectRights.Add(roleRight);
         }
     }
 }
Пример #20
0
 /// <summary>
 /// 二级模块绑定
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void rpnextModule_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
     {
         HiddenField      hfModuleID   = (HiddenField)e.Item.FindControl("hfsid");
         Repeater         rpnextModule = (Repeater)e.Item.FindControl("rplastModule");
         int              moduleid     = Convert.ToInt32(hfModuleID.Value.ToString());
         List <SysModule> modulelist   = db.SysModule.Where(t => t.ParentID == moduleid && t.IsRight == 1).OrderBy(t => t.ModuleOrder).ToList();
         List <object>    joinlist     = new List <object>();
         if (modulelist.Count > 0)
         {
             foreach (SysModule module in modulelist)
             {
                 string    rid       = "";
                 int       mid       = Convert.ToInt32(module.ID);
                 RoleRight roleright = db.RoleRight.FirstOrDefault(t => t.RoleID == RoleID && t.ModuleID == mid);
                 if (roleright != null)
                 {
                     rid = roleright.RoleID.ToString();
                 }
                 joinlist.Add(new
                 {
                     module.ID,
                     module.Name,
                     module.ModuleUrl,
                     module.ModuleIcon,
                     module.ParentID,
                     module.ModuleOrder,
                     module.IsRight,
                     module.ModuleButton,
                     rid
                 });
             }
         }
         rpnextModule.DataSource = joinlist;
         rpnextModule.DataBind();
         CheckBox chk_fid = (CheckBox)e.Item.FindControl("chk_fid");
     }
 }
Пример #21
0
        protected void rpbuttonModule_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                HiddenField  hfModuleID = (HiddenField)e.Item.FindControl("hftid");
                CheckBox     chk_fid    = (CheckBox)e.Item.FindControl("chk_tid");
                CheckBoxList chklModule = (CheckBoxList)e.Item.FindControl("chkl_tid");

                int              module     = Convert.ToInt32(hfModuleID.Value);
                SysModule        smodule    = db.SysModule.FirstOrDefault(t => t.ID == module);
                List <SysButton> buttonlist = db.SysButton.Where(t => smodule.ModuleButton.Contains(t.ID.ToString())).ToList();
                chklModule.DataTextField  = "Name";
                chklModule.DataValueField = "ID";
                chklModule.DataSource     = buttonlist;
                chklModule.DataBind();

                RoleRight rightlist = db.RoleRight.FirstOrDefault(t => t.RoleID == RoleID && t.ModuleID == module);
                if (rightlist != null)
                {
                    string[] buttons = rightlist.Buttons.ToString().Split(',');
                    foreach (SysButton button in buttonlist)
                    {
                        for (int i = 0; i < buttons.Length; i++)
                        {
                            if (button.ID.ToString() == buttons[i].ToString() || RoleID == 1)
                            {
                                chklModule.Items[i].Selected = true;
                                //break;
                            }
                        }
                    }
                }

                if (RoleID == 1)
                {
                    chk_fid.Checked = true;
                }
            }
        }
Пример #22
0
        public IActionResult GetRoleRights(long roleId)
        {
            List <RoleRightsViewModel> roleRightsAC = new List <RoleRightsViewModel>();
            List <Link> mstLinkList = _dbContext.Link.Where(x => x.IsActive == true && x.ModuleId != 1).Include(x => x.Module).OrderBy(x => x.ViewIndex).ToList();

            foreach (var link in mstLinkList)
            {
                RoleRightsViewModel roleRights    = new RoleRightsViewModel();
                RoleRight           mstRoleRights = _dbContext.RoleRight.FirstOrDefault(x => x.RoleId == roleId && x.LinkId == link.LinkId);
                if (mstRoleRights != null)
                {
                    roleRights = _mapper.Map <RoleRightsViewModel>(mstRoleRights);
                }
                roleRights.LinkId     = link.LinkId;
                roleRights.RoleId     = roleId;
                roleRights.ModuleName = link.Module.ModuleName;
                roleRights.Title      = link.Title;
                roleRightsAC.Add(roleRights);
            }

            return(Ok(roleRightsAC));
        }
Пример #23
0
 public void UpdateRole(Role role)
 {
     foreach (RoleRight item in role.RoleRights)
     {
         item.Right = null;
         if (item.RoleID > 0)
         {
             RoleRightRepository.Update(item.RoleRightID, item);
         }
         else if (item.RoleID < 0)
         {
             item.RoleID = role.RoleID;
             RoleRightRepository.Add(item);
         }
         else if (item.RoleRightID > 0)
         {
             RoleRight roleRight = RoleRightRepository.GetById(item.RoleRightID);
             RoleRightRepository.Delete(roleRight);
         }
     }
     role.RoleRights = null;
     RoleRepository.Update(role.RoleID, role);
 }
Пример #24
0
 public bool UpdateRoleRight(bool isRight, string rightName, int roleId)
 {
     if (isRight)
     {
         RoleRight roleRight = _myDbContext.RoleRight.FirstOrDefault(c => c.RoleId == roleId && c.RightName.Equals(rightName));
         if (roleRight == null)
         {
             _myDbContext.RoleRight.Add(new RoleRight()
             {
                 RightName = rightName, RoleId = roleId
             });
         }
     }
     else
     {
         RoleRight roleRight = _myDbContext.RoleRight.FirstOrDefault(c => c.RoleId == roleId && c.RightName.Equals(rightName));
         if (roleRight != null)
         {
             _myDbContext.RoleRight.Remove(roleRight);
         }
     }
     _myDbContext.SaveChanges();
     return(true);
 }
Пример #25
0
 public void DeleteRoleRight(RoleRight roleRight)
 {
     _repository.Delete(roleRight);
 }
Пример #26
0
        protected void btn_Sumbit_Click(object sender, EventArgs e)
        {
            CheckBox     chkfid;
            HiddenField  hffid;
            CheckBox     chksid;
            HiddenField  hfsid;
            CheckBoxList chkl_sbtnids;
            CheckBox     chktid;
            HiddenField  hftid;
            CheckBoxList chkl_tbtnids;
            Repeater     rpsid;
            Repeater     rptid;

            string sids    = "";
            string sbtnids = "";

            for (int i = 0; i < this.rpmodule.Items.Count; i++)
            {
                chkfid = (CheckBox)rpmodule.Items[i].FindControl("chk_fid");
                hffid  = (HiddenField)rpmodule.Items[i].FindControl("hffid");
                rpsid  = (Repeater)rpmodule.Items[i].FindControl("rpnextModule");
                if (chkfid.Checked)
                {
                    sids    += hffid.Value + "|";
                    sbtnids += "-2" + "|";
                }
                if (rpsid != null && rpsid.Items.Count != 0)
                {
                    for (int j = 0; j < rpsid.Items.Count; j++)
                    {
                        rptid        = (Repeater)rpsid.Items[j].FindControl("rplastModule");
                        chksid       = (CheckBox)rpsid.Items[j].FindControl("chk_fid");
                        hfsid        = (HiddenField)rpsid.Items[j].FindControl("hfsid");
                        chkl_sbtnids = (CheckBoxList)rpsid.Items[j].FindControl("chkl_tid");
                        if (chksid != null && chksid.Checked)
                        {
                            sids += hfsid.Value + "|";
                            if (chkl_sbtnids != null && chkl_sbtnids.Items.Count > 0)
                            {
                                sbtnids += GetChecked(chkl_sbtnids) + "|";
                            }
                            else
                            {
                                sbtnids += "-2" + "|";
                            }
                        }

                        if (rptid != null && rptid.Items.Count != 0)
                        {
                            for (int k = 0; k < rptid.Items.Count; k++)
                            {
                                chktid       = (CheckBox)rptid.Items[k].FindControl("chk_tid");
                                hftid        = (HiddenField)rptid.Items[k].FindControl("hftid");
                                chkl_tbtnids = (CheckBoxList)rptid.Items[k].FindControl("chkl_tid");
                                if (chktid != null && chktid.Checked)
                                {
                                    sids += hftid.Value + "|";
                                    if (chkl_tbtnids != null && chkl_tbtnids.Items.Count > 0)
                                    {
                                        sbtnids += GetChecked(chkl_tbtnids) + "|";
                                    }
                                    else
                                    {
                                        sbtnids += "-2" + "|";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (sids != "")
            {
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        try
                        {
                            List <RoleRight> rolerightList = db.RoleRight.Where(t => t.RoleID == RoleID).ToList();
                            if (rolerightList.Count > 0)
                            {
                                db.RoleRight.RemoveRange(rolerightList);
                            }

                            string[] moduleids = sids.ToString().TrimEnd('|').Split('|');
                            string[] btnids    = sbtnids.ToString().TrimEnd('|').Split('|');
                            for (int i = 0; i < moduleids.Length; i++)
                            {
                                RoleRight model = new RoleRight();
                                model.RoleID   = RoleID;
                                model.ModuleID = Convert.ToInt32(moduleids[i].ToString());
                                for (int j = 0; j < btnids.Length; j++)
                                {
                                    if (i == j)
                                    {
                                        model.Buttons = btnids[j].ToString();
                                        db.RoleRight.Add(model);
                                        db.SaveChanges();
                                        break;
                                    }
                                }
                            }
                            ShowMessage();
                            new SysLogDAO().AddLog(LogType.操作日志_添加, "成功添加权限设置信息", UserID);
                            ts.Complete();
                        }
                        catch
                        {
                            ShowMessage("提交失败");
                            ts.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message);
                    new SysLogDAO().AddLog(LogType.系统日志, ex.Message, UserID);
                    return;
                }
            }
            else
            {
                ShowMessage("请选择要设置的权限");
                return;
            }
        }
Пример #27
0
        /// <summary>
        /// 更新角色的相关权限
        /// </summary>
        /// <returns></returns>
        public JsonResult SetRoleRight2(RoleRightList data)
        {
            try
            {
                if (data == null)
                {
                    throw new Exception("提供的更新列表不存在。");
                }

                UserDbContext udb = new UserDbContext("ConnStr1");

                List <RoleRight> list = udb.GetRoleRights(data.RoleID);

                //如果旧的在新的不存在,则删除
                foreach (RoleRight rr in list)
                {
                    bool flag = false;
                    int  i    = 0;
                    for (i = 0; i < data.RightIDList.Count; i++)
                    {
                        if (rr.RightID == data.RightIDList[i])
                        {
                            flag = true;
                            break;
                        }
                    }
                    //如果不存在,则删除
                    if (flag == false)
                    {
                        udb.DeleteRoleRight(rr);
                    }
                }
                //保存数据库变更
                udb.SaveChanges();

                //如果新的在旧的不存在,则新增
                foreach (string str in data.RightIDList)
                {
                    bool flag = false;
                    int  i    = 0;
                    for (i = 0; i < list.Count; i++)
                    {
                        if (str == list[i].RightID)
                        {
                            flag = true;
                            break;
                        }
                    }
                    //如果不存在,则新增
                    if (flag == false)
                    {
                        RoleRight rr = new RoleRight();
                        rr.RoleID  = data.RoleID;
                        rr.RightID = str;
                        udb.AddRoleRight(rr);
                    }
                }
                //保存数据库变更
                udb.SaveChanges();

                return(Json(data, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                if (ex.Message != null)
                {
                }

                throw;
            }
        }
Пример #28
0
 public void CreateRoleRight(RoleRight RoleRight)
 {
     RoleRightRepository.Add(RoleRight);
 }
Пример #29
0
    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string strModuleName = txtModuleName.Text.Trim();
            if (strModuleName == string.Empty)
            {
                return;
            }

            string strModuleLevel = Request.QueryString["mlevel"].ToString();
            string strModuleName1 = Request.QueryString["mname"].ToString();

            string strPid = string.Empty;
            string strModuleId = Request.QueryString["mnid"].ToString();

            //string strSql = " Select * from CMS_SYS_MENU Where Menu_Level=" + strModuleLevel + " and Menu_Name='" + strModuleName1 + "'";
            //DataTable dt = DbHelperSQL.Query(strSql).Tables[0];

            //DataTable dt = rightDA.getMenuByLevelAndName(strModuleLevel, strModuleName1).Tables[0];
            Hashtable hsNew = new Hashtable();
            hsNew.Add("rblPageSet", "1");
            //if (dt != null)
            //{
            //    if (dt.Rows.Count > 0)
            //    {
            //        strModuleId = dt.Rows[0]["Menu_ID"].ToString();
            //    }
            //}

            if (strModuleId == string.Empty)
            {
                return;
            }

            //strSql = "Delete From CMS_SYS_PERMISSION Where Module_ID=" + strModuleId;
            try
            {
                //DbHelperSQL.ExecuteSql(strSql);

                rightDA.deletePermissionByModuleID(strModuleId);
            }
            catch { return; }

            //先取用户
            //if ( this.txtUserAccount.Value.Trim() != string.Empty)
            //{
            //    string[] strUsers = this.txtUserAccount.Value.Split(',');

            //    for (int k = 0; k < strUsers.Length; k++)
            //    {
            //        Right_User right_User = new Right_User(strUsers[k], strModuleId, strPid, UserSession.Current.UserAccount);
            //        Hashtable hsOld = new Hashtable();
            //        hsOld.Add("rblPageSet", right_User.GetModuleOrPageRight());

            //        right_User.NewRight = hsNew;
            //        right_User.OldRight = hsOld;
            //        right_User.SetNewRight();
            //    }
            //}

            //Response.Write(listBoxTo1.Items.Count);
            //取部门
            //if (listBoxTo1.Items.Count != 0)
            //{
            //    for (int g = 0; g < listBoxTo1.Items.Count; g++)
            //    {
            //        if (listBoxTo1.Items[g].Value.Trim() != string.Empty)
            //        {
            //            Right_Group right_Group = new Right_Group(listBoxTo1.Items[g].Value, strModuleId, strPid, UserSession.Current.LoginAccount);
            //            Hashtable hsOld1 = new Hashtable();
            //            hsOld1.Add("rblPageSet", right_Group.GetModuleOrPageRight());

            //            right_Group.NewRight = hsNew;
            //            right_Group.OldRight = hsOld1;
            //            right_Group.SetNewRight();
            //        }
            //    }

            //}

            //保存角色列表
            if (listBoxTo2.Items.Count != 0)
            {
                for (int z = 0; z < listBoxTo2.Items.Count; z++)
                {
                    if (listBoxTo2.Items[z].Value.Trim() != string.Empty)
                    {
                        RoleRight right_Role = new RoleRight(listBoxTo2.Items[z].Value, strModuleId, strPid, UserSession.Current.UserAccount);

                        Hashtable hsOld2 = new Hashtable();
                        hsOld2.Add("rblPageSet", right_Role.GetModuleOrPageRight());
                        right_Role.NewRight = hsNew;
                        right_Role.OldRight = hsOld2;
                        right_Role.SetNewRight();
                    }
                }
            }

            //保存用户列表
            if (listBoxTo3.Items.Count != 0)
            {
                for (int k = 0; k < listBoxTo3.Items.Count; k++)
                {
                    Right_User right_User = new Right_User(listBoxTo3.Items[k].Value, strModuleId, strPid, UserSession.Current.UserAccount);
                    Hashtable hsOld = new Hashtable();
                    hsOld.Add("rblPageSet", right_User.GetModuleOrPageRight());

                    right_User.NewRight = hsNew;
                    right_User.OldRight = hsOld;
                    right_User.SetNewRight();
                }
            }

        //PromptSuccess
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('" + PromptSuccess + "');", true);
        }
        catch
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('" + PromptSuccess + "');", true);
        }
    }
        //public List<usp_RoleRights_Result> GetRoleRightList(int RoleID)
        //{
        //    List<usp_RoleRights_Result> list=null;
        //    try
        //    {
        //        list = new List<usp_RoleRights_Result>();
        //        using (var context = new Cubicle_EntityEntities())
        //        {
        //            list = context.usp_RoleRights(RoleID).ToList<usp_RoleRights_Result>();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        //bool false = BusinessLogicExceptionHandler.HandleException(ref ex);
        //        if (false)
        //        {
        //            throw ex;
        //        }
        //    }
        //    return list;
        //}
        public Boolean SaveRoleRights(int RoleID, List<RoleRight> roleRight, string profileCode)
        {
            Boolean res = false;
            //using (TransactionScope ts = new TransactionScope())
            // {

            try
            {
                List<RoleRight> lstNew = new List<RoleRight>();
                List<int> lstModuleID = new List<int>();
                List<RoleRight> lstR = GetAllRoleRights().Where(p => p.RoleID == RoleID).ToList<RoleRight>();

                foreach (var obj in roleRight)
                {
                    RoleRight r = (from q in lstR where q.RoleID == obj.RoleID && q.ModuleID == obj.ModuleID select q).FirstOrDefault();
                    if (r != null)
                    {
                        lstModuleID.Add(r.ModuleID);
                        if (profileCode == "FR")
                        {
                            r.ViewFreeAccess = obj.ViewFreeAccess;
                            r.EditFreeAccess = obj.EditFreeAccess;
                        }
                        else if (profileCode == "SL")
                        {
                            r.ViewSilverAccess = obj.ViewSilverAccess;
                            r.EditSilverAccess = obj.EditSilverAccess;
                        }
                        else if (profileCode == "GL")
                        {
                            r.ViewGoldAccess = obj.ViewGoldAccess;
                            r.EditGoldAccess = obj.EditGoldAccess;
                        }
                        else if (profileCode == "PL")
                        {
                            r.ViewPlatinumAccess = obj.ViewPlatinumAccess;
                            r.EditPlatinumAccess = obj.EditPlatinumAccess;
                        }
                        else if (profileCode == "URM")
                        {
                            r.EditURMAccess = obj.EditURMAccess;
                            r.ViewURMAccess = obj.ViewURMAccess;
                        }
                        else
                        {
                            r.ViewAccess = obj.ViewAccess;
                            r.EditAccess = obj.EditAccess;
                        }

                        r.EntityState = DomainModelLibrary.EntityState.Modified;
                        // UpdateRoleRight(r);
                        lstNew.Add(r);
                    }
                    else
                    {
                        obj.EntityState = DomainModelLibrary.EntityState.Added;
                        //AddRoleRight(obj);
                        lstNew.Add(obj);
                    }
                }

                List<RoleRight> lstremoved = lstR.Where(a => !lstModuleID.Contains(a.ModuleID)).ToList<RoleRight>();
                foreach (var r in lstremoved)
                {

                    if (profileCode == "FR")
                    {
                        r.ViewFreeAccess = 0;
                        r.EditFreeAccess = 0;
                    }
                    else if (profileCode == "SL")
                    {
                        r.ViewSilverAccess = 0;
                        r.EditSilverAccess = 0;
                    }
                    else if (profileCode == "GL")
                    {
                        r.ViewGoldAccess = 0;
                        r.EditGoldAccess = 0;
                    }
                    else if (profileCode == "PL")
                    {
                        r.ViewPlatinumAccess = 0;
                        r.EditPlatinumAccess = 0;
                    }
                    else if (profileCode == "URM")
                    {
                        r.ViewURMAccess = 0;
                        r.EditURMAccess = 0;
                    }
                    else
                    {
                        r.ViewAccess = 0;
                        r.EditAccess = 0;
                    }

                    r.EntityState = DomainModelLibrary.EntityState.Modified;
                    // UpdateRoleRight(r);
                    lstNew.Add(r);
                }

                // ts.Complete();
                AddRoleRight(lstNew.ToArray());

                res = true;
            }

            catch (Exception ex)
            {
                //    ts.Dispose();
                res = false;
               // bool false = UserInterfaceExceptionHandler.HandleException(ref ex);
                throw ex;
            }

            return res;
            //}
        }
Пример #31
0
 public void EditRoleRight(RoleRight roleRight)
 {
     roleRight.LastModifiedDateUtc = DateTime.UtcNow;
     roleRight.LastModifiedBy      = 1;
     _repository.Update(roleRight);
 }