protected override void ProcessRecord() { var addableUser = new UpdatableUserObject() { UserName = UserName, FamilyName = FamilyName, GivenName = GivenName, EMail = EMail, Language = Language, Role = Role, MaxSpace = MaxSpace }; try { var request = UserRequestFactory.CreateAddUserRequest(addableUser); if (ShouldProcess("Add user")) { WriteObject(RequestHandler.ExecuteAndUnpack <UserObject>(request)); } } catch (ReportableException e) { WriteError(e.ErrorRecord); } }
public static ObjectRequest CreateAddUserRequest(UpdatableUserObject data) { var request = CreateUserObjectRequest("Add User", Method.POST); var updates = BuildJsonUpdateDict(data); request.Data = updates; return(request); }
public static ObjectRequest CreateEditUserRequest(long id, UpdatableUserObject data) { var request = CreateUserObjectRequest("Edit User", Method.PUT); var updates = BuildJsonUpdateDict(data); updates["id"] = id; request.Data = updates; request.ObjectId = id; return(request); }
private static Dictionary <string, object> BuildJsonUpdateDict(UpdatableUserObject userObject) { var updates = new Dictionary <string, object>(); var type = userObject.GetType(); foreach (var pair in JsonUpdatePropertyMap) { object value = type.GetProperty(pair.Key).GetValue(userObject, null); if (value != null) { updates[pair.Value] = value; } } return(updates); }