public static async Task <ApiResult> AddToMailList(string listName, CreateUserInput user) { ApiResult result = new ApiResult(); try { var xmlFile = GetXmlFile(new string("MailingUpdateList")); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFile); xmlDoc.SelectSingleNode(ParaNode + "/Domain") !.InnerText = MailDomain; xmlDoc.SelectSingleNode(ParaNode + "/ListName") !.InnerText = listName; //xmlDoc.SelectSingleNode(_paraNode + "/Details/Description")!.InnerText = description; //Cập nhật danh sách user ở đây var xmlNode = (XmlElement)xmlDoc.SelectSingleNode(ParaNode + "/Members"); //Add member XmlElement member1 = xmlDoc.CreateElement("Member"); member1.SetAttribute("action", "add"); member1.SetAttribute("id", user.Username + "@" + user.Domain); member1.SetAttribute("displayname", user.FullName); xmlNode.AppendChild(member1); result.Payload = await GetResponse(xmlDoc); result.Payload = xmlDoc; } catch (Exception e) { result.Errors.Add(new ApiErrorItem(ApiErrorCode.Generic, "Error: " + e.Message)); } return(result); }
public static async Task <ApiResult> CreateUserByUserName(string userName) { var result = new ApiResult(); var listNvs = UserService.GetNhanVienTheoUserName(userName); if (listNvs.Count > 1) { result.Errors.Add(new ApiErrorItem(ApiErrorCode.Generic, "Username bị trùng lặp, kiểm tra lại")); return(result); } //TẠO EMAIL var nv = listNvs.FirstOrDefault(); if (nv == null) { result.Errors.Add(new ApiErrorItem(ApiErrorCode.Generic, "Không tìm thấy nhân viên có username này.")); return(result); } string ten = UsernameGenerator.ConvertToUnSign(nv.Ten); string ho = UsernameGenerator.ConvertToUnSign(nv.Ho); var input = new CreateUserInput { Domain = "haiphatland.com.vn", Username = userName, FirstName = ten, LastName = ho, FullName = ho + " " + ten, Password = "******", AdminNotes = "Tạo từ tool, time: " + DateTime.Now.ToString("G"), MailList = "", Group = "" }; result.Payload = await MdaemonXmlApi.CreateUser(input); result.Errors.Add(new ApiErrorItem(ApiErrorCode.Generic, "Thành công.")); //Cập nhật lại Email cho nhân sự này UserService.UpdateEmailByUserName(userName); return(result); }
//public static List<CreateUserInput> CreateUserTheoMaNhanVien(string maNhanVien) //{ // var listUsers = listUserName.Trim().Replace(" ", string.Empty).Split(","); // var list = new List<CreateUserInput>(); // foreach (var userName in listUserName) // { // var user = new CreateUserInput() // { // Domain = MdaemonXmlApi.Domain, // Username = userName, // FirstName = "FirstName" + i, // LastName = "LastName" + i, // FullName = "FullName" + i, // Password = "******" + i, // AdminNotes = "Tạo bởi tool", // MailList = "*****@*****.**" // }; // list.Add(user); // } // return list; //} public static List <CreateUserInput> CreateUserDemo() { Random random = new Random(); int j = random.Next(20); var list = new List <CreateUserInput>(); for (int i = j; i < j + 3; i++) { var user = new CreateUserInput { Domain = MdaemonXmlApi.MailDomain, Username = "******" + i, FirstName = "FirstName" + i, LastName = "LastName" + i, FullName = "FullName" + i, Password = "******" + i, AdminNotes = "Tạo bởi tool", MailList = "*****@*****.**" }; list.Add(user); } return(list); }
public static async Task <ApiResult> CreateUser(CreateUserInput inputMail) { List <object> listObj = new List <object>(); XmlDocument doc = new XmlDocument(); XmlDeclaration xDeclare = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement documentRoot = doc.DocumentElement; doc.InsertBefore(xDeclare, documentRoot); XmlElement rootEl = (XmlElement)doc.AppendChild(doc.CreateElement("FIXML")); XmlElement child1 = (XmlElement)rootEl.AppendChild(doc.CreateElement("Header")); XmlElement child2 = (XmlElement)child1.AppendChild(doc.CreateElement("RequestHeader")); ApiResult result = new ApiResult(); var xmlFile = GetXmlFile(new string("CreateUser")); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFile); xmlDoc.SelectSingleNode(ParaNode + "/Domain") !.InnerText = inputMail.Domain; xmlDoc.SelectSingleNode(ParaNode + "/Mailbox") !.InnerText = inputMail.Username; var xmlNodeDetail = (XmlElement)xmlDoc.SelectSingleNode(ParaNode + "/Details") !; XmlElement password = xmlDoc.CreateElement("Password"); password.InnerText = inputMail.Password; xmlNodeDetail.AppendChild(password); XmlElement adminNotes = xmlDoc.CreateElement("AdminNotes"); adminNotes.InnerText = inputMail.AdminNotes; xmlNodeDetail.AppendChild(adminNotes); XmlElement firstName = xmlDoc.CreateElement("FirstName"); firstName.InnerText = inputMail.FirstName; xmlNodeDetail.AppendChild(firstName); XmlElement lastName = xmlDoc.CreateElement("LastName"); lastName.InnerText = inputMail.LastName; xmlNodeDetail.AppendChild(lastName); XmlElement fullName = xmlDoc.CreateElement("FullName"); fullName.InnerText = inputMail.FullName; xmlNodeDetail.AppendChild(fullName); listObj.Add(await GetResponse(xmlDoc)); //Add Mailing list; Mặc định add vào all @haiphatland.com.vn listObj.Add(await AddToMailList("all", inputMail)); //Add vào Mail list của Phòng Ban if (!string.IsNullOrEmpty(inputMail.MailList)) { listObj.Add(await AddToMailList(inputMail.MailList.Split("@")[0], inputMail)); } result.Payload = listObj; } catch (Exception e) { result.Errors.Add(new ApiErrorItem(ApiErrorCode.Generic, "Error: " + e.Message)); } return(result); }