Beispiel #1
0
        public bool ChangeStaticGroupInfo(Guid transactionid, AdminInfo admin, GroupInfo group, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        message  = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"AdminID:{admin.UserID}";
            paramstr += $"||AdminAccount:{admin.UserAccount}";
            paramstr += $"||GroupID:{group.GroupID}";
            for (int i = 0; i < group.Admins.Count; i++)
            {
                paramstr += $"||UserID:{group.Admins[i].UserID}";
            }

            string funname = "ChangeStaticGroupInfo";

            try
            {
                do
                {
                    GroupInfo oldgroup = new GroupInfo();
                    oldgroup.GroupID = group.GroupID;
                    if (!GetStaticGroupInfo(transactionid, admin, ref oldgroup, out error))
                    {
                        LoggerHelper.Error("StaticGroupManager调用GetStaticGroupInfo异常", paramstr, error.Info, transactionid);
                        result = false;
                        break;
                    }

                    group.DisplayName = oldgroup.DisplayName;
                    group.Account     = oldgroup.Account;
                    group.Description = oldgroup.Description;

                    GroupProvider groupProvider = new GroupProvider();
                    groupProvider.ClearGroupManagedBy(transactionid, group, out error);

                    //判断管理员有效性
                    DirectoryEntry entry           = new DirectoryEntry();
                    List <Guid>    newgroupuserids = new List <Guid>();
                    CommonProvider commonProvider  = new CommonProvider();
                    if (group.Admins.Count > 0)
                    {
                        for (int i = 0; i < group.Admins.Count; i++)
                        {
                            if (!commonProvider.GetADEntryByGuid(group.Admins[i].UserID, out entry, out message))
                            {
                                continue;
                            }

                            group.Admins[i].DisplayName = entry.Properties["cn"].Value == null ? "" : Convert.ToString(entry.Properties["cn"].Value);
                            group.Admins[i].UserAccount = entry.Properties["userPrincipalName"].Value == null ? "" : Convert.ToString(entry.Properties["userPrincipalName"].Value);
                            group.AdminsName           += group.Admins[i].DisplayName + "(" + group.Admins[i].UserAccount + "),";
                            newgroupuserids.Add(group.Admins[i].UserID);

                            if (!groupProvider.AddGroupManagedBy(transactionid, group.GroupID, group.Admins[i].UserID, out error))
                            {
                                continue;
                            }
                        }
                    }
                    group.AdminsName = string.IsNullOrEmpty(group.AdminsName) ? string.Empty : group.AdminsName.Remove(group.AdminsName.LastIndexOf(','), 1);

                    //Set Group Exchange
                    //if (!ExchangeProvider.SetDistributionGroupManagedBy(group.GroupID.ToString(), new List<Guid>(), newgroupuserids, ref message))
                    //{
                    //    error.Code = ErrorCode.Exception;
                    //    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                    //    LoggerHelper.Error("StaticGroupManager调用ChangeStaticGroupInfo异常", paramstr, message, transactionid);
                    //    strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                    //    result = false;
                    //}
                    error.Code = ErrorCode.None;
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info);

                    #region 操作日志
                    LogInfo operateLog = new LogInfo();
                    operateLog.AdminID       = admin.UserID;
                    operateLog.AdminAccount  = admin.UserAccount;
                    operateLog.RoleID        = admin.RoleID;
                    operateLog.ClientIP      = _clientip;
                    operateLog.OperateResult = true;
                    operateLog.OperateType   = "修改静态通讯组成员管理员";
                    operateLog.OperateLog    = $"{admin.UserAccount}于{DateTime.Now}修改静态通讯组成员管理员。" +
                                               $"组名称:{group.DisplayName};" +
                                               $"现成员管理员:{group.AdminsName}";
                    LogManager.AddOperateLog(transactionid, operateLog);
                    #endregion

                    result = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("MailAuditManager调用ModifySensitiveMail异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }