예제 #1
0
        /// <summary>
        /// This Will attempt to add an <see cref="AppUser"/> by calling an instance of <see cref="IAppUserRepository"/>
        /// </summary>
        /// <param name="username"></param>
        /// <example>
        /// Usage:
        /// <code>
        /// AppUserService.AddAppUserAsync("test");
        /// </code>
        /// </example>
        /// <returns></returns>
        public async Task <AppUserDto> AddAppUserAsync(string username)
        {
            var existingAppUser = await _appUserRepo.GetAppUserByUsernameAsync(username).ConfigureAwait(false);

            //Check if the username already exists
            if (existingAppUser == null)
            {
                //if the appUser does not exist, create it
                return(await _appUserRepo.AddAppUserAsync(AppUser.CreateUserAsync(username).Result).ConfigureAwait(false));
            }

            //adding appUser failed
            throw new ApplicationException($"User {username} already exists");
        }