예제 #1
0
        //
        // GET: /Home/
        public ActionResult Index()
        {
            Business.Platform.UsersRole buserRole = new Business.Platform.UsersRole();
            Business.Platform.Role      brole     = new Business.Platform.Role();
            var roles = buserRole.GetByUserID(Business.Platform.Users.CurrentUserID);

            ViewBag.RoleLength    = roles.Count;
            ViewBag.DefaultRoleID = string.Empty;
            ViewBag.RolesOptions  = string.Empty;
            if (roles.Count > 0)
            {
                var mainRole = roles.Find(p => p.IsDefault);
                ViewBag.defaultRoleID = mainRole != null?mainRole.RoleID.ToString() : roles.First().RoleID.ToString();

                List <Data.Model.Role> roleList = new List <Data.Model.Role>();
                foreach (var role in roles)
                {
                    var role1 = brole.Get(role.RoleID);
                    if (role1 == null)
                    {
                        continue;
                    }
                    roleList.Add(role1);
                }

                ViewBag.RolesOptions = brole.GetRoleOptions("", "", roleList);
            }

            var user = Business.Platform.Users.CurrentUser;

            ViewBag.UserName = user == null ? "" : user.Name;
            ViewBag.DateTime = Utility.DateTimeNew.Now.ToDateWeekString();

            return(View());
        }
예제 #2
0
        public ActionResult Tree()
        {
            string userid = Request.QueryString["id"];

            Business.Platform.Role brole = new Business.Platform.Role();
            var roles = new Business.Platform.UsersRole().GetByUserID(userid.ToGuid());
            List <Data.Model.Role> roleList = new List <Data.Model.Role>();

            foreach (var role in roles)
            {
                var role1 = brole.Get(role.RoleID);
                if (role1 == null)
                {
                    continue;
                }
                roleList.Add(role1);
            }

            ViewBag.RoleOptions = new Business.Platform.Role().GetRoleOptions(Request.QueryString["roleid"], "", roleList);

            return(View());
        }
예제 #3
0
        public ActionResult EditRole(FormCollection collection)
        {
            Business.Platform.Role brole = new Business.Platform.Role();
            Data.Model.Role        role  = null;
            string roleID = Request.QueryString["id"];
            Guid   roleGID;
            string name      = string.Empty;
            string useMember = string.Empty;
            string note      = string.Empty;

            if (roleID.IsGuid(out roleGID))
            {
                role = brole.Get(roleGID);
            }

            if (!Request.Form["Copy"].IsNullOrEmpty())
            {
                string tpl = Request.Form["ToTpl"];
                if (tpl.IsGuid())
                {
                    new Business.Platform.RoleApp().CopyRoleApp(roleGID, tpl.ToGuid());
                    Business.Platform.Log.Add("复制了模板应用", "源:" + roleID + "复制给:" + tpl, Business.Platform.Log.Types.角色应用);
                    ViewBag.Script = "alert('复制成功!');";
                }
            }

            if (!Request.Form["Save"].IsNullOrEmpty() && role != null)
            {
                Business.Platform.UsersRole busersRole = new Business.Platform.UsersRole();
                using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                {
                    name      = Request.Form["Name"];
                    useMember = Request.Form["UseMember"];
                    note      = Request.Form["Note"];

                    role.Name      = name.Trim();
                    role.Note      = note.IsNullOrEmpty() ? null : note.Trim();
                    role.UseMember = useMember.IsNullOrEmpty() ? null : useMember;
                    brole.Update(role);
                    busersRole.DeleteByRoleID(role.ID);
                    if (!useMember.IsNullOrEmpty())
                    {
                        busersRole.DeleteByRoleID(role.ID);
                        var users = new Business.Platform.Organize().GetAllUsers(useMember);
                        foreach (var user in users)
                        {
                            Data.Model.UsersRole ur = new Data.Model.UsersRole();
                            ur.IsDefault = true;
                            ur.MemberID  = user.ID;
                            ur.RoleID    = role.ID;
                            busersRole.Add(ur);
                        }
                    }
                    scope.Complete();
                }
                ViewBag.Script = "alert('保存成功!');parent.frames[0].location = 'Tree?appid=" + Request.QueryString["appid"] + "&roleid=" + roleID + "';";
            }

            if (!Request.Form["Delete"].IsNullOrEmpty())
            {
                using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                {
                    brole.Delete(roleGID);
                    new Business.Platform.RoleApp().DeleteByRoleID(roleGID);
                    new Business.Platform.UsersRole().DeleteByRoleID(roleGID);
                    scope.Complete();
                }
                Business.Platform.Log.Add("删除的角色其及相关数据", roleID, Business.Platform.Log.Types.角色应用);
                ViewBag.Script = "parent.frames[0].location = parent.frames[0].location;";
            }
            ViewBag.RoleOptions = brole.GetRoleOptions("", roleID);
            return(View(role));
        }