private async Task PrepareDatabaseRows(ApplicationDbContext dbContext)
        {
            if (await dbContext.Users.CountAsync() <= 0)
            {
                UserModel.PrepareUserRows(dbContext);
                await dbContext.SaveChangesAsync();
            }

            if (await dbContext.Test.CountAsync() <= 0)
            {
                testModel.PrepareTestRows(dbContext);
                await dbContext.SaveChangesAsync();
            }

            if (await dbContext.TestAnswer.CountAsync() <= 0)
            {
                testAnswerModel.PrepareTestAnswerRows(dbContext);
                await dbContext.SaveChangesAsync();
            }

            if (await dbContext.TestWrongAnswer.CountAsync() <= 0)
            {
                testWrongAnswerModel.PrepareTestWrongAnswerRows(dbContext);
                await dbContext.SaveChangesAsync();
            }
        }
示例#2
0
        private void PrepareDatabaseRows()
        {
            if (!dbContext.Users.Any())
            {
                UserModel.PrepareUserRows(dbContext);
                dbContext.SaveChanges();
            }

            if (!dbContext.Tests.Any())
            {
                testModel.PrepareTestRows(dbContext);
                dbContext.SaveChanges();
            }

            if (!dbContext.UserTestCorrectAnswers.Any())
            {
                testAnswerModel.PrepareTestAnswerRows(dbContext);
                dbContext.SaveChanges();
            }

            if (!dbContext.UserTestWrongAnswers.Any())
            {
                testWrongAnswerModel.PrepareTestWrongAnswerRows(dbContext);
                dbContext.SaveChanges();
            }
        }