public void PopulateQuestionTemplate(string questionFile) { string ConnectionString = Environment.GetEnvironmentVariable("Database__ConnectionString"); if (string.IsNullOrEmpty(ConnectionString)) { throw new ArgumentException("ConnectionString cannot be empty"); } DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); builder.UseSqlServer(ConnectionString); BmtDbContext context = new BmtDbContext(builder.Options); List <QuestionTemplate> questions; using (StreamReader reader = new StreamReader(questionFile)) { string json = reader.ReadToEnd(); questions = JsonSerializer.Deserialize <List <QuestionTemplate> >(json, JsonUtils.SerializerOptions); } int order = 0; foreach (QuestionTemplate q in questions) { q.CreateDate = DateTimeOffset.UtcNow; q.Status = Status.Active; q.Order = order; order += 1; } context.QuestionTemplates.AddRange(questions); context.SaveChanges(); Console.WriteLine($"Added {questions.Count} to questionTemplate table in DB"); }
protected DbContextTestSetup() { DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); string connectionString = new SqliteConnectionStringBuilder { DataSource = "file::memory:", Cache = SqliteCacheMode.Shared }.ToString(); _connection = new SqliteConnection(connectionString); _connection.Open(); builder.EnableSensitiveDataLogging(); builder.UseSqlite(_connection); _context = new BmtDbContext(builder.Options); _context.Database.EnsureCreated(); InitContent.PopulateDb(_context); }
public void ParticipantUnique() { DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); builder.UseSqlite(_connection); // This is done because bug in xunit making Dbcontext dispose never being called when exception is thrown using (var _context = new BmtDbContext(builder.Options)) { EvaluationService evaluationService = new EvaluationService(_context); Evaluation evaluation = evaluationService.GetAll().First(); ParticipantService participantService = new ParticipantService(_context); participantService.Create("azure_unique_id", evaluation, Organization.All, Role.OrganizationLead); Assert.Throws <DbUpdateException>(() => participantService.Create("azure_unique_id", evaluation, Organization.All, Role.OrganizationLead)); } }
public void OrderQuestionsInEvaluation(string evaluationId) { string ConnectionString = Environment.GetEnvironmentVariable("Database__ConnectionString"); if (string.IsNullOrEmpty(ConnectionString)) { throw new ArgumentException("ConnectionString cannot be empty"); } DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); builder.UseSqlServer(ConnectionString); BmtDbContext context = new BmtDbContext(builder.Options); List <Question> questions = context.Questions.Include(q => q.QuestionTemplate).Where(q => q.Evaluation.Id.Equals(evaluationId)).ToList(); foreach (Question q in questions) { q.Order = q.QuestionTemplate.Order; } context.Questions.UpdateRange(questions); context.SaveChanges(); }
public void SetAdminOrderOnQuestionTemplates() { string ConnectionString = Environment.GetEnvironmentVariable("Database__ConnectionString"); if (string.IsNullOrEmpty(ConnectionString)) { throw new ArgumentException("ConnectionString cannot be empty"); } DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); builder.UseSqlServer(ConnectionString); BmtDbContext context = new BmtDbContext(builder.Options); var questionTemplates = context.QuestionTemplates; foreach (var qt in questionTemplates) { qt.AdminOrder = qt.Order; context.QuestionTemplates.Update(qt); } context.SaveChanges(); }
public Startup(IConfiguration configuration) { Configuration = configuration; // In-memory sqlite requires an open connection throughout the whole lifetime of the database _sqlConnectionString = Configuration.GetSection("Database").GetValue <string>("ConnectionString"); if (string.IsNullOrEmpty(_sqlConnectionString)) { DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); string connectionString = new SqliteConnectionStringBuilder { DataSource = "file::memory:", Cache = SqliteCacheMode.Shared }.ToString(); _connection = new SqliteConnection(connectionString); _connection.Open(); builder.UseSqlite(_connection); using (BmtDbContext context = new BmtDbContext(builder.Options)) { context.Database.EnsureCreated(); InitContent.PopulateDb(context); } } }
public void OrderQuestionTemplates(string questionFile) { string ConnectionString = Environment.GetEnvironmentVariable("Database__ConnectionString"); if (string.IsNullOrEmpty(ConnectionString)) { throw new ArgumentException("ConnectionString cannot be empty"); } DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); builder.UseSqlServer(ConnectionString); BmtDbContext context = new BmtDbContext(builder.Options); List <QuestionTemplate> questionsFromFile; using (StreamReader reader = new StreamReader(questionFile)) { string json = reader.ReadToEnd(); questionsFromFile = JsonSerializer.Deserialize <List <QuestionTemplate> >(json, JsonUtils.SerializerOptions); } List <QuestionTemplate> questions = context.QuestionTemplates.ToList(); Console.WriteLine($"Ordering {questions.Count} questions"); foreach (QuestionTemplate questionTemplate in questions) { QuestionTemplate qtFromFile = questionsFromFile.First(qt => qt.Text.Equals(questionTemplate.Text)); questionTemplate.Order = qtFromFile.Order + 1; } List <int> ints = questions.Select(qt => qt.Order).ToList(); HashSet <int> intSet = new HashSet <int>(ints); Console.WriteLine($"Distinct orders after: {intSet.Count}"); context.QuestionTemplates.UpdateRange(questions); context.SaveChanges(); }
public ClosingRemarkService(BmtDbContext context) { _context = context; }
public AnswerService(BmtDbContext context) { _context = context; }
public NoteService(BmtDbContext context) { _context = context; }
public QuestionTemplateService(BmtDbContext context) { _context = context; }
public ParticipantService(BmtDbContext context) { _context = context; }
public ActionService(BmtDbContext context) { _context = context; }
public ProjectService(BmtDbContext context) { _context = context; }
public EvaluationService(BmtDbContext context) { _context = context; }
public ProjectCategoryService(BmtDbContext context) { _context = context; }
public QuestionService(BmtDbContext context) { _context = context; }