/// <summary> /// Creates a new "actor" on the system, these are usually end users, but /// maybe another application /// </summary> /// <param name="actor">The actor to create</param> /// <param name="cancellationToken"></param> /// <returns>The newly created Actor object from the Repository</returns> public async Task <Actor> CreateNewUserAsync(Actor actor, CancellationToken cancellationToken = default(CancellationToken)) { Actor createdActor = null; // Validate the Actor model ICollection <ValidationResult> validationResults = new List <ValidationResult>(); bool isValid = Validator.TryValidateObject(actor, new ValidationContext(actor), validationResults, true); if (isValid) { // Create the Actor string id = await repository.CreateNewUserAsync(actor, cancellationToken); // Get the new Actor back from the repository createdActor = await repository.GetActorByIdAsync(id, cancellationToken); } else { foreach (ValidationResult vr in validationResults) { throw new ArgumentNullException(((string[])vr.MemberNames)[0], vr.ErrorMessage); } } // Return the Created result return(createdActor); }