public Models.ldap_cn deToModel(DirectoryEntry dei, Dictionary<string, string> ldapParameters) { string type = ""; if (dei.Properties[ldapParameters["TypeAttribute"]].Value != null) { if (dei.Properties[ldapParameters["TypeAttribute"]].Contains(ldapParameters["UserFilter"])) { type = "user"; } else if (dei.Properties[ldapParameters["TypeAttribute"]].Contains(ldapParameters["GroupFilter"])) { type = "group"; } } string account = ""; if (dei.Properties[ldapParameters["UserAccountAttribute"]].Value != null) { account = dei.Properties[ldapParameters["UserAccountAttribute"]][0].ToString(); } string name = ""; if (dei.Properties[ldapParameters["UserNameAttribute"]].Value != null) { name = dei.Properties[ldapParameters["UserNameAttribute"]][0].ToString(); } else { name = account; } string email = ""; if (dei.Properties[ldapParameters["UserEmailAttribute"]].Value != null) { email = dei.Properties[ldapParameters["UserEmailAttribute"]][0].ToString(); } string path = ""; if (dei.Properties[ldapParameters["UserPath"]].Value != null) { path = dei.Properties[ldapParameters["UserPath"]][0].ToString(); } Models.ldap_cn model_ldap_cn = new Models.ldap_cn(); model_ldap_cn.TYPE = type; model_ldap_cn.ACCOUNT = account; model_ldap_cn.EMAIL = email; model_ldap_cn.NAME = name; model_ldap_cn.PATH = path; return model_ldap_cn; }
public bool AddList(Models.m_announcement model_m_announcement) { ArrayList toList = new ArrayList(); var items = model_m_announcement.DEPARTMENT.Split(new string[] {";#;"}, StringSplitOptions.None); foreach(string item in items) { var attrs = item.Split(new string[] { "%;" }, StringSplitOptions.None); if (attrs.Count() == 4) { string type = attrs[0].Substring(5); string path = attrs[3].Substring(5); string name = attrs[2].Substring(5); string account = model_z_parameter.VALUE + "\\" + attrs[1].Substring(8); if (type == "user" && !toList.Contains(account)) { toList.Add(account); } else if(type == "group") { Models.ldap_cn model = new Models.ldap_cn(); model.TYPE = type; model.PATH = path; model.NAME = name; model.EMAIL = ""; model.ACCOUNT = account; addGroupList(model, toList); } } } DAL.m_announcement_user dal_m_announcement_user = new DAL.m_announcement_user(); dal_m_announcement_user.Delete(model_m_announcement.ID); foreach (string toItem in toList) { if (toItem.Trim() != "") { Models.m_announcement_user model_m_announcement_user = new Models.m_announcement_user(); model_m_announcement_user.ANNOUNCEMENT_ID = model_m_announcement.ID; model_m_announcement_user.USER_ACCOUNT = toItem.Trim(); model_m_announcement_user.STATUS = ""; dal_m_announcement_user.Add(model_m_announcement_user); } } return true; }