Esempio n. 1
0
        public async Task <bool> SeedDatabaseAsync()
        {
            var sampleSeed = _seedOptions.Value.SampleSeed;

            sampleSeed.CheckArgumentIsNull(nameof(sampleSeed));

            const string thisMethodName = nameof(SeedDatabaseAsync);

            var sampleExists = await _sampleService.Exists();

            if (sampleExists)
            {
                _logger.LogInformation($"{thisMethodName}: Sample is already exists.");
                return(true);
            }

            //Create the `Sample` if it does not exist

            var sampleResult = await _sampleService.Create(new SampleViewModel
            {
                Title = sampleSeed.Title
            });

            if (sampleResult <= 0)
            {
                _logger.LogError($"{thisMethodName}: Sample CreateAsync failed. {sampleResult}");
                return(false);
            }

            _logger.LogInformation($"{thisMethodName}: Sample already exists.");
            return(true);
        }