/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (ImageReference == null) { throw new ValidationException(ValidationRules.CannotBeNull, "ImageReference"); } if (Sku == null) { throw new ValidationException(ValidationRules.CannotBeNull, "Sku"); } if (AdminUser == null) { throw new ValidationException(ValidationRules.CannotBeNull, "AdminUser"); } if (Sku != null) { Sku.Validate(); } if (AdminUser != null) { AdminUser.Validate(); } if (NonAdminUser != null) { NonAdminUser.Validate(); } }
public async Task <IActionResult> CreateUserAsync([FromBody] AdminUser user) { this.Logger.LogDebug("Creating a user"); // Input sanity checking user = Ensure.IsNotNull(() => user); user.Validate(); // Use service to add to repository var userFromService = await this.userService.CreateAsync(user, this.GetUserEmailFromContext()); return(this.CreatedAtAction("Create", userFromService)); }
/// <inheritdoc/> public async Task <AdminUser> CreateAsync(AdminUser user, string callingUserEmail) { await this.EnsureCallingUserPermissionsAsync(callingUserEmail); this.Logger.LogDebug("Creating a user in the repository"); // input sanity checking user = Ensure.IsNotNull(() => user); user.Validate(); // Create in repository var userFromRepository = await this.userRepository.CreateUserAsync(user); // Sanity check output userFromRepository = Ensure.IsNotNull(() => userFromRepository); userFromRepository.Validate(); this.Logger.LogTrace($"Create user with id {user.Id} and email {user.Email} in the repository"); return(userFromRepository); }