コード例 #1
0
ファイル: ModuleController.cs プロジェクト: CBWJ/GlsunView
        public ActionResult Authority(int id)
        {
            ModuleAuth module = new ModuleAuth();

            module.ModuleID = id;
            using (var ctx = new GlsunViewEntities())
            {
                var theModule = ctx.Module.Find(id);
                if (theModule != null && (theModule.MParentID != 0 || theModule.MName == "拓扑管理"))
                {
                    module.Authorities    = ctx.Authority.ToList();
                    module.OwnAuthorityID = (from m in ctx.Module
                                             join ma in ctx.ModuleAuthority on m.ID equals ma.MID
                                             join a in ctx.Authority on ma.AID equals a.ID
                                             where m.ID == id
                                             select a.ID).ToList();
                }
                else
                {
                    module.Authorities    = new List <Authority>();
                    module.OwnAuthorityID = new List <int>();
                }
            }
            return(View(module));
        }
コード例 #2
0
ファイル: ClsUserRight.cs プロジェクト: chrgu000/DEMO
        public bool chkRight(UFSoft.U8.Framework.Login.UI.clsLogin login, string sMenuID)
        {
            bool b = false;

            try
            {
                CalledContext Context = new CalledContext();
                Context.subId = "FA";
                Context.token = login.userToken;
                ModuleAuth auth = new ModuleAuth(Context);
                if (!auth.TaskExec(sMenuID, -1))
                {
                    if (auth.ErrNumber != 0)
                    {
                        throw new Exception(auth.ErrDescript);
                    }
                    else
                    {
                        throw new Exception("出现无法预知的错误,无法申请功能");
                    }
                }
                else
                {
                    b = true;
                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.Message);
            }
            return(b);
        }
コード例 #3
0
ファイル: ModuleController.cs プロジェクト: CBWJ/GlsunView
        public ActionResult Authority(ModuleAuth moduleAuth)
        {
            var json = new JsonResult();

            try
            {
                using (var ctx = new GlsunViewEntities())
                {
                    var loginUser = (from u in ctx.User
                                     where u.ULoginName == HttpContext.User.Identity.Name
                                     select u).FirstOrDefault();
                    //删除未选中的
                    IEnumerable <Authority> unselected = null;
                    if (moduleAuth.OwnAuthorityID == null)
                    {
                        unselected = ctx.Authority.ToList();
                    }
                    else
                    {
                        unselected = ctx.Authority.Where(a => !moduleAuth.OwnAuthorityID.Contains(a.ID));
                    }
                    foreach (var e in unselected)
                    {
                        var maDelete = (from ma in ctx.ModuleAuthority
                                        where ma.AID == e.ID && ma.MID == moduleAuth.ModuleID
                                        select ma).FirstOrDefault();
                        if (maDelete != null)
                        {
                            ctx.ModuleAuthority.Remove(maDelete);
                        }
                    }
                    //添加选中的
                    if (moduleAuth.OwnAuthorityID != null)
                    {
                        foreach (var id in moduleAuth.OwnAuthorityID)
                        {
                            var maAdd = (from ma in ctx.ModuleAuthority
                                         where ma.AID == id && ma.MID == moduleAuth.ModuleID
                                         select ma).FirstOrDefault();
                            //不存在则添加
                            if (maAdd == null)
                            {
                                ModuleAuthority ma = new ModuleAuthority
                                {
                                    MID          = moduleAuth.ModuleID,
                                    AID          = id,
                                    CreatorID    = loginUser.ID,
                                    CreationTime = DateTime.Now
                                };
                                ctx.ModuleAuthority.Add(ma);
                            }
                        }
                    }
                    ctx.SaveChanges();
                }
                json.Data = new { Code = "", Data = moduleAuth, Message = "保存成功" };
            }
            catch (Exception ex)
            {
                json.Data = new { Code = "Exception", Data = moduleAuth, Message = ex.Message };
            }
            return(json);
        }