Beispiel #1
0
        /// <summary>
        /// Creates a CosmosDB user if the user doesn't already exist.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="documentClient"></param>
        /// <returns></returns>
        private static async Task <User> CreateUserIfNotExistAsync(string userId, CosmosDBRepository repo)
        {
            User cosmosDBUser = null;

            try
            {
                cosmosDBUser = await repo.GetUserAsync(userId);
            }
            catch (DocumentClientException e)
            {
                if (e.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    cosmosDBUser = await repo.UpsertUserAsync(new User { Id = userId });
                }
            }

            return(cosmosDBUser);
        }