public JsonResult GetRightInModule(string module, int UserID) { if (!UserID.Equals("")) { Rights rights = new Rights(); rights.Accept = new List <GetUserFunction_Result>(); rights.Deny = new List <GetUserFunction_Result>(); if (UserID == 1) { var rightAccept = db.Database.SqlQuery <GetUserFunction_Result>("Account.GetUserAcceptByModuleAndUID {0}, {1}", module, UserID).ToList(); foreach (var r in rightAccept) { rights.Accept.Add(new GetUserFunction_Result() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } var rightDeny = db.Database.SqlQuery <GetUserFunction_Result>("Account.GetUserDenyByModuleAndUID {0} {1}", module, UserID).ToList(); foreach (var r in rightDeny) { rights.Deny.Add(new GetUserFunction_Result() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } } else { var rightAccept = db.Database.SqlQuery <GetUserFunction_Result>("Account.GetUserAcceptByModuleAndUID {0}, {1}", module, UserID).ToList(); foreach (var r in rightAccept) { rights.Accept.Add(new GetUserFunction_Result() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } var rightDeny = db.Database.SqlQuery <GetUserFunction_Result>("Account.GetUserDenyByModuleAndUID {0}, {1}", module, UserID).ToList(); foreach (var r in rightDeny) { rights.Deny.Add(new GetUserFunction_Result() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } } return(Json(rights, JsonRequestBehavior.AllowGet)); } else { RightsWhenCreate rights = new RightsWhenCreate(); rights.Accept = new List <GetUserFunction_Result>(); rights.Deny = new List <GetUserFunction_Result>(); var rightDeny = db.Database.SqlQuery <GetUserFunction_Result>("Account.GetFunctionsByModule {0}", module).ToList(); foreach (var r in rightDeny) { rights.Deny.Add(new GetUserFunction_Result() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } return(Json(rights, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetRightInModule(string module, int UserID) { if (!UserID.Equals("")) { Rights rights = new Rights(); rights.Accept = new List <FunctionRight>(); rights.Deny = new List <FunctionRight>(); if (UserID == 1) { var rightAccept = db.Database.SqlQuery <FunctionRight>("select a.ID,a.[Right],a.GroupID from Account_Right a,Account_Right_Detail ar where a.ID=ar.RightID and a.ModuleID='" + module + "' and ar.AccountID='" + UserID + "' order by a.GroupID asc").ToList <FunctionRight>(); foreach (var r in rightAccept) { rights.Accept.Add(new FunctionRight() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } var rightDeny = db.Database.SqlQuery <FunctionRight>("select distinct a.ID,a.[Right],a.GroupID from Account_Right a,Account_Right_Detail ar where a.ModuleID='" + module + "' and a.ID not in (select a.RightID from Account_Right_Detail a where a.AccountID='" + UserID + "') order by a.GroupID asc").ToList <FunctionRight>(); foreach (var r in rightDeny) { rights.Deny.Add(new FunctionRight() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } } else { var rightAccept = db.Database.SqlQuery <FunctionRight>("select a.ID,a.[Right],a.GroupID from Account_Right a,Account_Right_Detail ar where a.ID=ar.RightID and a.ModuleID='" + module + "' and ar.AccountID='" + UserID + "' order by a.GroupID asc").ToList <FunctionRight>(); foreach (var r in rightAccept) { rights.Accept.Add(new FunctionRight() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } var rightDeny = db.Database.SqlQuery <FunctionRight>("select distinct a.ID,a.[Right],a.GroupID from Account_Right a,Account_Right_Detail ar where a.ModuleID='" + module + "' and a.ID not in (select a.RightID from Account_Right_Detail a where a.AccountID='" + UserID + "') order by a.GroupID asc").ToList <FunctionRight>(); foreach (var r in rightDeny) { rights.Deny.Add(new FunctionRight() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } } return(Json(rights, JsonRequestBehavior.AllowGet)); } else { RightsWhenCreate rights = new RightsWhenCreate(); rights.Accept = new List <FunctionRight>(); rights.Deny = new List <FunctionRight>(); var rightDeny = db.Database.SqlQuery <FunctionRight>("select a.ID,a.[Right],a.GroupID from Account_Right a where a.ModuleID='" + module + "' order by a.GroupID asc").ToList <FunctionRight>(); foreach (var r in rightDeny) { rights.Deny.Add(new FunctionRight() { ID = r.ID, Right = r.Right, GroupID = r.GroupID }); } return(Json(rights, JsonRequestBehavior.AllowGet)); } }