public JsonResult EnableGroupExchange()
        {
            string msg       = "";                                         //Log日志要记录的用户名
            string groupname = Request.Form["groupname"].Trim().ToString();
            string domain    = Request.Form["domain"].Trim().ToString();

            Groups ad_group = HttpContext.Application["ad_group"] as Groups;

            List <GroupsDTO> col = ad_group.SearchAllGroupsDTO(groupname, domain);
            GroupsDTO        gd  = col.ElementAt(0);

            if (gd.GroupScope != GroupScope.Universal)
            {
                gd.GroupScope = GroupScope.Universal;
            }
            bool result = ad_group.UpdateGroupsDTO(gd, ref msg);

            if (result)
            {
                ExchangeDistributionGroupDTO EDG = new ExchangeDistributionGroupDTO(gd);

                if (EDG.EnableDistributionGroup(ref msg))
                {
                    gd.ExchangeEnabled = true;
                    EDG = new ExchangeDistributionGroupDTO(gd);
                    msg = "1";
                }
                else
                {
                    msg = "0";
                }
            }
            else
            {
                msg = "0";
            }

            return(Json(new JsonData(msg)));
        }
        public JsonResult Create()
        {
            string msg      = "";
            string Operator = "";

            if (Session["username"].ToString() != null)
            {
                Operator = Session["username"].ToString();
            }
            string    OuPath         = Request.Form["OuPath"].Trim().ToString();                                                        //Log日志要记录的用户名
            string    groupname      = Request.Form["groupname"].Trim().ToString();
            string    domain         = Request.Form["domain"].Trim().ToString();
            string    grouptype      = Request.Form["grouptype"].Trim().ToString();
            string    groupscope     = Request.Form["groupscope"].Trim().ToString();
            string    EnableExchange = Request.Form["EnableExchange"].Trim().ToString();
            Groups    ad_group       = HttpContext.Application["ad_group"] as Groups;
            GroupsDTO gd             = new GroupsDTO();

            gd.BelongsOUPath  = OuPath;
            gd.SamAccountName = groupname;
            if (grouptype.Equals("Security"))
            {
                gd.isSecurityGroup = true;
            }
            if (groupscope.Equals("DomainLocale"))
            {
                gd.GroupScope = GroupScope.Local;
            }
            else if (groupscope.Equals("Gloable"))
            {
                gd.GroupScope = GroupScope.Global;
            }
            else
            {
                gd.GroupScope = GroupScope.Universal;
            }

            string message;

            if (ad_group.CreateUserGroup(gd))
            {
                if (EnableExchange.Equals("true"))
                {
                    List <GroupsDTO>             col = ad_group.SearchAllGroupsDTO(groupname, domain);
                    GroupsDTO                    gd2 = col.ElementAt(0);
                    ExchangeDistributionGroupDTO EDG = new ExchangeDistributionGroupDTO(gd2);

                    if (EDG.EnableDistributionGroup(ref msg))
                    {
                        gd2.ExchangeEnabled = true;
                        EDG = new ExchangeDistributionGroupDTO(gd2);
                    }
                    else
                    {
                        msg = "error";
                    }
                }
                message = "Group:<span style =\"color:green\">" + groupname + "</span> create successful";
                LogHelper.WriteLog(typeof(GroupsManagementController), Operator, "Create%Group%named%" + groupname, true);
                XmlDocument doc = new XmlDocument();
                doc.Load(Server.MapPath("~/GroupDetail.xml"));
                XmlNode    rootnode = doc.SelectSingleNode("ADGroupDetail");
                XmlElement xe1      = doc.CreateElement("user");
                xe1.SetAttribute("Name", groupname);
                XmlElement xesub1 = doc.CreateElement("CreateBy");
                xesub1.InnerText = Operator;
                xe1.AppendChild(xesub1);
                XmlElement xesub2 = doc.CreateElement("CreateTime");
                xesub2.InnerText = DateTime.Today.ToString("yyyyMMdd");
                xe1.AppendChild(xesub2);
                rootnode.AppendChild(xe1);
                doc.Save(Server.MapPath("~/GroupDetail.xml"));
            }
            else
            {
                message = "Name for group <span style =\"color:green\">" + groupname + "</span>creation failed,It could be that the group already exists";
                LogHelper.WriteLog(typeof(GroupsManagementController), Operator, "Create%Group%named%" + groupname, false);
            }
            return(Json(new JsonData(message)));
        }