Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Web.Services;
  3.  
  4. namespace NewStarterWebService
  5. {
  6. [WebService(Namespace = "http://tempuri.org/")]
  7. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  8. [System.ComponentModel.ToolboxItem(false)]
  9. public class NewStarter : WebService
  10. {
  11. [WebMethod]
  12. public void CreateNewUser(
  13. string firstName,
  14. string middleName,
  15. string lastName,
  16. string jobTitle,
  17. string department,
  18. string office,
  19. string role,
  20. string manager)
  21. {
  22. var newUser = new NewUser(firstName, middleName, lastName, jobTitle, department, office, role, manager);
  23. newUser.Create();
  24. }
  25. }
  26. }
  27.  
  28. using System;
  29. using System.Collections.Generic;
  30.  
  31. namespace NewStarterWebService
  32. {
  33. public class NewUser
  34. {
  35. public readonly string FullName;
  36. public readonly string FirstName;
  37. public readonly string MiddleName;
  38. public readonly string LastName;
  39. public readonly string Department;
  40. public readonly string Office;
  41. public readonly string JobTitle;
  42. public readonly string Role;
  43. public readonly string Manager;
  44. public readonly string Email;
  45. public readonly string DotName;
  46. public readonly string HomeDirectory;
  47. public readonly string Initials;
  48.  
  49. public readonly Dictionary<string, string> DefaultProperties;
  50. private const string Password = "Password99";
  51.  
  52. public NewUser(
  53. string firstName,
  54. string middleName,
  55. string lastName,
  56. string jobTitle,
  57. string department,
  58. string office,
  59. string role,
  60. string manager)
  61. {
  62. Office = office;
  63. Department = department;
  64. FirstName = firstName.Trim();
  65. MiddleName = middleName.Trim();
  66. LastName = lastName.Trim();
  67. JobTitle = jobTitle.Trim();
  68. Role = role.Trim();
  69.  
  70. Manager = Ad.GetManagerDistinguishedName(manager);
  71. FullName = $"{FirstName} {LastName}";
  72. Email = $"{FirstName}{LastName}@domain.com";
  73. DotName = $"{FirstName}.{LastName}";
  74. HomeDirectory = $@"\FileHome${DotName}";
  75. try
  76. {
  77. Initials = $"{FirstName[0]}{MiddleName[0]}{LastName[0]}";
  78. }
  79. catch (Exception ex) when (
  80. ex is ArgumentOutOfRangeException ||
  81. ex is NullReferenceException ||
  82. ex is ArgumentNullException)
  83. {
  84. Initials = $"{FirstName[0]}{LastName[0]}";
  85. }
  86.  
  87. // Set the default properties for AD
  88. DefaultProperties = new Dictionary<string, string>
  89. {
  90. {"userprincipalname", Email},
  91. {"samaccountname", DotName },
  92. {"sn", LastName},
  93. {"givenname", FirstName },
  94. {"displayname", FullName },
  95. {"description", JobTitle },
  96. {"mail", Email },
  97. {"homedirectory", HomeDirectory },
  98. {"homedrive", "H:" },
  99. {"physicalDeliveryOfficeName", Office },
  100. {"Manager", Manager },
  101. {"Initials", Initials }
  102. };
  103. }
  104.  
  105. public void Create()
  106. {
  107. Ad.CreateUser(this);
  108. Ps.AddExchangeUser(this);
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement