예제 #1
0
        protected override void ProcessRecord()
        {
            var user = new UserDto
            {
                UserName          = Username,
                Password          = Password,
                Name              = Name,
                Surname           = Surname,
                EmailAddress      = EmailAddress,
                RolesList         = RolesList,
                OrganizationUnits = OrganizationUnitIds?.Select(
                    id => new OrganizationUnitDto
                {
                    Id          = id,
                    DisplayName = id.ToString()     // The DisplayName cannot be null or empty string, but the actual value is irelevant
                }).ToList()
            };
            UserDtoType type;

            if (Enum.TryParse <UserDtoType>(Type, out type))
            {
                user.Type = type;
            }
            var dto = HandleHttpOperationException(() => Api.Users.Post(user));

            WriteObject(User.FromDto(dto));
        }
예제 #2
0
 protected override void ProcessRecord()
 {
     var user = new UserDto
     {
         UserName = Username,
         Password = Password,
         Name = Name,
         Surname = Surname,
         EmailAddress = EmailAddress,
         RolesList = RolesList,
         OrganizationUnits = OrganizationUnitIds?.Select(id => new OrganizationUnitDto { Id = id }).ToList()
     };
     UserDtoType type;
     if (Enum.TryParse<UserDtoType>(Type, out type))
     {
         user.Type = type;
     }
     var dto = HandleHttpOperationException(() => Api.Users.Post(user));
     WriteObject(User.FromDto(dto));
 }
        protected override void ProcessRecord()
        {
            if (Username.Contains('\\'))
            {
                var parts = Username.Split('\\');
                if (parts.Length != 2)
                {
                    throw new Exception($"The NT username {Username} can only contain one '\\' delimitator.");
                }

                if (string.IsNullOrWhiteSpace(Domain))
                {
                    Domain = parts[0];
                }

                if (0 != string.Compare(Domain, parts[0], true))
                {
                    throw new Exception($"The NT username {Username} must match the domain {Domain}.");
                }
            }

            var user = new UserDto
            {
                UserName          = Username,
                Password          = Password,
                Domain            = Domain,
                Name              = Name,
                Surname           = Surname,
                EmailAddress      = EmailAddress,
                RolesList         = RolesList ?? new List <string>(),
                OrganizationUnits = OrganizationUnitIds?.Select(
                    id => new OrganizationUnitDto
                {
                    Id          = id,
                    DisplayName = id.ToString()     // The DisplayName cannot be null or empty string, but the actual value is irelevant
                }).ToList()
            };
            var dto = HandleHttpOperationException(() => Api.Users.Post(user));

            WriteObject(User.FromDto(dto));
        }