Beispiel #1
0
        public void Delete(int id)
        {
            SysRightInfo entity = this.GetEntity(id);

            db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
        }
Beispiel #2
0
        public SysRightInfo Add(SysRightInfo entity)
        {
            var model = db.SysRightInfos.Add(entity);

            db.SaveChanges();
            return(model);
        }
Beispiel #3
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public bool DeleteEntity(int id)
        {
            SysRightInfo model = new SysRightInfo()
            {
                Id = id
            };

            db.SysRightInfos.Attach(model);
            db.SysRightInfos.Remove(model);
            return(db.SaveChanges() > 0);
        }
Beispiel #4
0
 public override void OnAuthorization(AuthorizationContext filterContext)
 {
     if (Startup.GetUserInfo() != null)
     {
         List <SysRightInfo> list = Startup.GetUserRightInfoList(false);
         var    areas             = filterContext.RouteData.DataTokens["area"];
         string filePath          = "";
         if (areas == "" || areas == null)
         {
             filePath = "~/" + filterContext.RouteData.GetRequiredString("controller") + "/" +
                        filterContext.RouteData.GetRequiredString("action");
         }
         else
         {
             filePath = "~/" + areas + "/" + filterContext.RouteData.GetRequiredString("controller") + "/" + filterContext.RouteData.GetRequiredString("action");
         }
         if (list.Find(o => o.FilePath.ToUpper() == filePath.ToUpper()) == null)
         {
             CallContext.SetData("access_result", "401");//无访问权限
         }
         else
         {
             CallContext.SetData("access_result", "200");//允许访问
             #region 设置当前选中第一级菜单
             if (filterContext.RequestContext.HttpContext.Request.QueryString["mid"] != null)
             {
                 int id = 0;
                 if (int.TryParse(filterContext.RequestContext.HttpContext.Request.QueryString["mid"], out id))
                 {
                     SysRightInfo menu = list.Find(o => o.Id == id);
                     if (menu != null)
                     {
                         Startup.CurrentSelectMenu = menu;
                     }
                 }
             }
             #endregion
         }
     }
     else
     {
         CallContext.SetData("access_result", "402"); //未登录
     }
     base.OnAuthorization(filterContext);
 }
Beispiel #5
0
        /// <summary>
        /// 修改该权限及其子权限的状态
        /// </summary>
        /// <param name="id">权限id</param>
        /// <param name="state">要修改成的状态</param>
        public int ChangeState(int id, DataStateEnum state)
        {
            var model = GetEntity(id);

            if (model != null)
            {
                model.DataState = state;
            }

            var list = GetRightsOfOneRight(id);

            foreach (var r in list)
            {
                SysRightInfo m = new SysRightInfo()
                {
                    Id = Convert.ToInt32(id), DataState = state
                };
                var entry = db.Entry(m);
                entry.State = EntityState.Unchanged;
                entry.Property("DataState").IsModified = true;
            }

            return(db.SaveChanges());
        }
Beispiel #6
0
 public void Delete(SysRightInfo entity)
 {
     db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
     db.SaveChanges();
 }
Beispiel #7
0
 public void Update(SysRightInfo entity)
 {
     db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
        // 新增权限
        public JsonResult AddRight()
        {
            var rightName = Request.Form["rightName"];

            if (string.IsNullOrEmpty(rightName))
            {
                return(new JsonResult()
                {
                    Data = new { code = 0, msg = "请填写权限名称" }
                });
            }
            var rightPath = Request.Form["rightPath"];
            //if (string.IsNullOrEmpty(rightPath))
            //{
            //    return new JsonResult() { Data = new { code = 0, msg = "请填写权限路径" } };
            //}
            var id = Request.Form["id"];

            if (string.IsNullOrEmpty(id))
            {
                return(new JsonResult()
                {
                    Data = new { code = 0, msg = "参数错误" }
                });
            }
            var rightTypeStr = Request.Form["rightType"];
            int rightType    = 0;

            if (string.IsNullOrEmpty(rightTypeStr))
            {
                return(new JsonResult()
                {
                    Data = new { code = 0, msg = "请选择权限类型" }
                });
            }
            if (!int.TryParse(rightTypeStr, out rightType))
            {
                return(new JsonResult()
                {
                    Data = new { code = 0, msg = "参数错误" }
                });
            }
            var chongfu = Request.Form["chongfu"] == "1";

            if (!chongfu)
            {
                if (string.IsNullOrEmpty(rightPath))
                {
                    var l = RightInfoMan.GetEntityList(c => c.FilePath == rightPath.Trim()).ToList();
                    if (l.Count > 0)
                    {
                        if (!int.TryParse(rightTypeStr, out rightType))
                        {
                            return(new JsonResult()
                            {
                                Data = new { code = 0, msg = "已有该权限路径" }
                            });
                        }
                    }
                }
            }

            var rightid   = Convert.ToInt32(id);
            var rightDesc = Request.Form["rightDesc"];
            // bool showMenu = Request.Form["showMenu"] == "1";
            //  var showMenu = false;
            var          commonRight = Request.Form["commonRight"] == "1";
            var          pathPic     = Request.Form["pathPic"];
            var          pathPic2    = Request.Form["pathPic2"];
            SysRightInfo right       = new SysRightInfo()
            {
                DataState = DataStateEnum.正常, FilePath = rightPath, Description = rightDesc, ParentId = rightid, RightName = rightName, RightType = rightType, PicPath = pathPic, IsPublic = commonRight, Id = RightInfoMan.GetMaxIdModel().Id + 1, SortId = RightInfoMan.GetMaxSortIdModel().SortId + 1, PicPathChange = pathPic2
            };
            var model = RightInfoMan.Add(right);

            return(new JsonResult()
            {
                Data = new { code = 1, msg = "新增成功", id = model.Id }
            });
        }