Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Web.Services;
- namespace NewStarterWebService
- {
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- public class NewStarter : WebService
- {
- [WebMethod]
- public void CreateNewUser(
- string firstName,
- string middleName,
- string lastName,
- string jobTitle,
- string department,
- string office,
- string role,
- string manager)
- {
- var newUser = new NewUser(firstName, middleName, lastName, jobTitle, department, office, role, manager);
- newUser.Create();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- namespace NewStarterWebService
- {
- public class NewUser
- {
- public readonly string FullName;
- public readonly string FirstName;
- public readonly string MiddleName;
- public readonly string LastName;
- public readonly string Department;
- public readonly string Office;
- public readonly string JobTitle;
- public readonly string Role;
- public readonly string Manager;
- public readonly string Email;
- public readonly string DotName;
- public readonly string HomeDirectory;
- public readonly string Initials;
- public readonly Dictionary<string, string> DefaultProperties;
- private const string Password = "Password99";
- public NewUser(
- string firstName,
- string middleName,
- string lastName,
- string jobTitle,
- string department,
- string office,
- string role,
- string manager)
- {
- Office = office;
- Department = department;
- FirstName = firstName.Trim();
- MiddleName = middleName.Trim();
- LastName = lastName.Trim();
- JobTitle = jobTitle.Trim();
- Role = role.Trim();
- Manager = Ad.GetManagerDistinguishedName(manager);
- FullName = $"{FirstName} {LastName}";
- Email = $"{FirstName}{LastName}@domain.com";
- DotName = $"{FirstName}.{LastName}";
- HomeDirectory = $@"\FileHome${DotName}";
- try
- {
- Initials = $"{FirstName[0]}{MiddleName[0]}{LastName[0]}";
- }
- catch (Exception ex) when (
- ex is ArgumentOutOfRangeException ||
- ex is NullReferenceException ||
- ex is ArgumentNullException)
- {
- Initials = $"{FirstName[0]}{LastName[0]}";
- }
- // Set the default properties for AD
- DefaultProperties = new Dictionary<string, string>
- {
- {"userprincipalname", Email},
- {"samaccountname", DotName },
- {"sn", LastName},
- {"givenname", FirstName },
- {"displayname", FullName },
- {"description", JobTitle },
- {"mail", Email },
- {"homedirectory", HomeDirectory },
- {"homedrive", "H:" },
- {"physicalDeliveryOfficeName", Office },
- {"Manager", Manager },
- {"Initials", Initials }
- };
- }
- public void Create()
- {
- Ad.CreateUser(this);
- Ps.AddExchangeUser(this);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement