Exemplo n.º 1
0
        /// <summary>
        /// 保存角色-用户
        /// </summary>
        public void SaveUserRoleFun()
        {
            try
            {
                Guid RoleID = Guid.Empty;
                if (!string.IsNullOrEmpty(Request["RoleID"]))
                {
                    RoleID = Guid.Parse(Request["RoleID"]);
                }
                string UserIDs = Request["UserIDs"];

                using (ProxyBE p = new ProxyBE())
                {
                    List <Guid> roleIDs = new List <Guid>();
                    if (!string.IsNullOrEmpty(UserIDs))
                    {
                        string[] roles = UserIDs.Split(',');
                        foreach (var item in roles)
                        {
                            roleIDs.Add(new Guid(item));
                        }
                    }

                    var user = p.Client.GetPartnerRole(SenderUser, RoleID);
                    if (user == null)
                    {
                        return;
                    }
                    SavePartnerRoleArgs args = new SavePartnerRoleArgs();
                    args.UserIDs     = roleIDs;
                    args.PartnerRole = user;
                    p.Client.SavePartnerRole(SenderUser, args);
                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存角色权限
        /// </summary>
        public void SaveRoleMenuFun()
        {
            try
            {
                Guid RoleID = Guid.Empty;
                if (!string.IsNullOrEmpty(Request["RoleID"]))
                {
                    RoleID = Guid.Parse(Request["RoleID"]);
                }
                string PrivilegeItemS = Request["PrivilegeItemS"];
                using (ProxyBE p = new ProxyBE())
                {
                    List <Guid> PrivilegeItemIDS = new List <Guid>();
                    if (!string.IsNullOrEmpty(PrivilegeItemS))
                    {
                        string[] ItemS = PrivilegeItemS.Split(',');
                        foreach (var item in ItemS)
                        {
                            PrivilegeItemIDS.Add(new Guid(item));
                        }
                    }

                    var pRole = p.Client.GetPartnerRole(SenderUser, RoleID);
                    if (pRole == null)
                    {
                        return;
                    }
                    SavePartnerRoleArgs args = new SavePartnerRoleArgs();

                    args.PartnerRole      = pRole;
                    args.PrivilegeItemIDs = PrivilegeItemIDS;
                    p.Client.SavePartnerRole(SenderUser, args);
                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 保存角色信息
 /// </summary>
 public void SaveRoleInfo()
 {
     try
     {
         Guid RoleID = Guid.Empty;
         if (!string.IsNullOrEmpty(Request["RoleID"]))
         {
             RoleID = new Guid(Request["RoleID"]);
         }
         using (ProxyBE p = new ProxyBE())
         {
             PartnerRole role = p.Client.GetPartnerRole(SenderUser, RoleID);
             if (role == null)
             {
                 role        = new PartnerRole();
                 role.RoleID = prParm.RoleID;
             }
             role.GroupID    = prParm.GroupID;
             role.RoleName   = prParm.RoleName;
             role.IsDisabled = prParm.IsDisabled;
             role.IsLocked   = prParm.IsLocked;
             bool flag = p.Client.PartnerRoleIsDuplicated(SenderUser, role);
             if (flag)
             {
                 throw new Exception("当前组已存在该角色");
             }
             SavePartnerRoleArgs args = new SavePartnerRoleArgs();
             args.PartnerRole = role;
             p.Client.SavePartnerRole(SenderUser, args);
             WriteSuccess();
         }
     }
     catch (Exception ex)
     {
         WriteError(ex.Message, ex);
     }
 }
Exemplo n.º 4
0
        public void SavePartnerManagerUser()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    #region  PartnerUser
                    PartnerUser partnerUser = p.Client.GetPartnerUser(SenderUser, parm.UserID);
                    if (partnerUser != null)
                    {
                        partnerUser.UserCode = parm.UserCode.Trim();
                        bool flag = p.Client.PartnerUserIsDuplicated(SenderUser, partnerUser);
                        if (flag)
                        {
                            throw new Exception("该账号已经存在,请重新输入。");
                        }
                        partnerUser.PartnerID       = parm.PartnerID;
                        partnerUser.UserName        = parm.UserName.Trim();
                        partnerUser.Sex             = "";
                        partnerUser.Position        = "";
                        partnerUser.IsSystem        = true;
                        partnerUser.Email           = "";
                        partnerUser.Description     = parm.Description.Trim();
                        partnerUser.Mobile          = parm.Mobile.Trim();
                        partnerUser.LoginErrorCount = 0;
                        partnerUser.IsDisabled      = Convert.ToBoolean(parm.IsDisabled);
                        partnerUser.IsLocked        = parm.IsLocked;
                        partnerUser.IsAxamine       = true;
                        partnerUser.IsFinishInfo    = true;
                        partnerUser.MemberClass     = parm.MemberClass;
                        string strDate = Request["EndDate"];
                        partnerUser.EndDate = Convert.ToDateTime(Request["EndDate"]);
                    }
                    SavePartnerUserArgs args = new SavePartnerUserArgs();
                    args.PartnerUser = partnerUser;
                    p.Client.SavePartnerUser(SenderUser, args);
                    #endregion

                    #region  PartnerUserGroup
                    PartnerUserGroup           UserGroup     = null;
                    SearchPartnerUserGroupArgs UserGroupArgs = new SearchPartnerUserGroupArgs();
                    UserGroupArgs.PartnerID = partnerUser.PartnerID;
                    UserGroupArgs.GroupName = "默认组";
                    Guid         GroupID = Guid.Empty;
                    SearchResult sr      = p.Client.SearchPartnerUserGroup(SenderUser, UserGroupArgs);
                    if (sr.Total > 0)
                    {
                        foreach (DataRow item in sr.DataSet.Tables[0].Rows)
                        {
                            GroupID = Guid.Parse(item["GroupID"].ToString());
                        }
                        UserGroup = p.Client.GetPartnerUserGroup(SenderUser, GroupID);
                    }
                    if (GroupID == Guid.Empty)
                    {
                        UserGroup           = new PartnerUserGroup();
                        UserGroup.GroupID   = Guid.NewGuid();
                        UserGroup.GroupName = "默认组";
                        UserGroup.IsSystem  = true;
                        UserGroup.PartnerID = partnerUser.PartnerID;
                        SavePartnerUserGroupArgs GroupArgs = new SavePartnerUserGroupArgs();
                        GroupArgs.PartnerUserGroup = UserGroup;
                        p.Client.SavePartnerUserGroup(SenderUser, GroupArgs);
                    }
                    #endregion

                    #region  PartnerRole
                    string      PrivilegeItemS   = Request["PrivilegeItemS"];
                    List <Guid> PrivilegeItemIDS = new List <Guid>();
                    if (!string.IsNullOrEmpty(PrivilegeItemS))
                    {
                        string[] ItemS = PrivilegeItemS.Split(',');
                        foreach (var item in ItemS)
                        {
                            PrivilegeItemIDS.Add(new Guid(item));
                        }
                    }
                    PartnerRole partnerRole = p.Client.GetPartnerRoleByName(SenderUser, UserGroup.GroupID, "root");
                    if (partnerRole == null)
                    {
                        partnerRole          = new PartnerRole();
                        partnerRole.GroupID  = UserGroup.GroupID;
                        partnerRole.IsSystem = true;
                        partnerRole.RoleID   = Guid.NewGuid();
                        partnerRole.RoleName = "root";
                    }
                    SavePartnerRoleArgs roleArgs = new SavePartnerRoleArgs();
                    roleArgs.PartnerRole      = partnerRole;
                    roleArgs.PrivilegeItemIDs = PrivilegeItemIDS;
                    p.Client.SavePartnerRole(SenderUser, roleArgs);
                    #endregion

                    #region PartnerUser2Role
                    PartnerUser2Role PartnerUser2Role = new PartnerUser2Role();
                    PartnerUser2Role.UserID = partnerUser.UserID;
                    PartnerUser2Role.RoleID = partnerRole.RoleID;

                    SavePartnerUser2RoleArgs sargs = new SavePartnerUser2RoleArgs();
                    sargs.PartnerUser2Role = PartnerUser2Role;
                    p.Client.SavePartnerUser2Role(SenderUser, sargs);
                    #endregion

                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 5
0
        public void SavePartnerRole(Sender sender, SavePartnerRoleArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(args.PartnerRole.RoleName))
                {
                    throw new Exception(string.Format("角色名称:{0}命名无效,可能存在特殊字符。", args.PartnerRole.RoleName));
                }

                if (PartnerRoleIsDuplicated(sender, args.PartnerRole))
                {
                    throw new Exception(string.Format("角色名称:{0}已存在,请重新输入。", args.PartnerRole.RoleName));
                }

                using (ObjectProxy op = new ObjectProxy(true))
                {
                    PartnerRole role = new PartnerRole();
                    role.RoleID = args.PartnerRole.RoleID;
                    if (op.LoadPartnerRoleByRoleID(role) == 0)
                    {
                        role = null;
                    }

                    if (role == null)
                    {
                        args.PartnerRole.Created    = DateTime.Now;
                        args.PartnerRole.CreatedBy  = sender.UserCode + "." + sender.UserName;
                        args.PartnerRole.Modified   = args.PartnerRole.Created;
                        args.PartnerRole.ModifiedBy = args.PartnerRole.CreatedBy;
                        op.InsertPartnerRole(args.PartnerRole);
                    }
                    else
                    {
                        args.PartnerRole.Modified   = DateTime.Now;
                        args.PartnerRole.ModifiedBy = sender.UserCode + "." + sender.UserName;
                        op.UpdatePartnerRoleByRoleID(args.PartnerRole);
                    }
                    if (args.UserIDs != null)
                    {
                        op.DeletePartnerUser2RolesByRoleID(args.PartnerRole.RoleID);
                        foreach (Guid userID in args.UserIDs)
                        {
                            PartnerUser2Role ug = new PartnerUser2Role();
                            ug.UserID = userID;
                            ug.RoleID = args.PartnerRole.RoleID;
                            op.InsertPartnerUser2Role(ug);
                        }
                    }

                    if (args.PrivilegeItemIDs != null)
                    {
                        op.DeletePartnerRole2PrivilegeItemsByRoleID(args.PartnerRole.RoleID);
                        foreach (Guid privilege in args.PrivilegeItemIDs)
                        {
                            PartnerRole2PrivilegeItem rp = new PartnerRole2PrivilegeItem();
                            rp.RoleID          = args.PartnerRole.RoleID;
                            rp.PrivilegeItemID = privilege;
                            op.InsertPartnerRole2PrivilegeItem(rp);
                        }
                    }
                    op.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                throw ex;
            }
        }