public QuestionTemplate Create( Barrier barrier, Organization organization, string text, string supportNotes ) { DateTimeOffset createDate = DateTimeOffset.UtcNow; int last = _context.QuestionTemplates.Max(qt => qt.Order) + 1; QuestionTemplate newQuestionTemplate = new QuestionTemplate { CreateDate = createDate, Barrier = barrier, Organization = organization, Status = Status.Active, Text = text, Order = last, SupportNotes = supportNotes }; _context.QuestionTemplates.Add(newQuestionTemplate); _context.SaveChanges(); return(newQuestionTemplate); }
public Action Create( Participant createdBy, Participant assignedTo, string description, DateTimeOffset dueDate, string title, Priority priority, Question question ) { DateTimeOffset createDate = DateTimeOffset.UtcNow; Action newAction = new Action { CreateDate = createDate, AssignedTo = assignedTo, CreatedBy = createdBy, Description = description, DueDate = dueDate, OnHold = false, Completed = false, Priority = priority, Title = title, Question = question }; _context.Actions.Add(newAction); _context.SaveChanges(); return(newAction); }
public Answer Create( Participant answeredBy, Question question, Severity severity, string text, Progression progression ) { DateTimeOffset createDate = DateTimeOffset.UtcNow; Answer newAnswer = new Answer { CreateDate = createDate, AnsweredBy = answeredBy, Progression = progression, Question = question, Severity = severity, Text = text }; _context.Answers.Add(newAnswer); _context.SaveChanges(); return(newAnswer); }
public ProjectCategory Create(string name) { var newProjectCategory = _Create(name); _context.ProjectCategories.Add(newProjectCategory); _context.SaveChanges(); return(newProjectCategory); }
public Question Create( QuestionTemplate template, Evaluation evaluation ) { Question newQuestion = CreateInternal(template, evaluation); _context.Questions.Add(newQuestion); _context.SaveChanges(); return(newQuestion); }
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"); }
private QuestionTemplate Create( Barrier barrier, Organization organization, Status status, string text, string supportNotes ) { DateTime createDate = DateTime.UtcNow; QuestionTemplate newQuestionTemplate = new QuestionTemplate { CreateDate = createDate, Barrier = barrier, Organization = organization, Status = status, Text = text, SupportNotes = supportNotes }; _context.QuestionTemplates.Add(newQuestionTemplate); _context.SaveChanges(); return(newQuestionTemplate); }
public Evaluation Create(string name, Project project) { DateTime createDate = DateTime.UtcNow; Evaluation newEvaluation = new Evaluation { CreateDate = createDate, Name = name, Progression = Progression.Nomination, Project = project }; _context.Evaluations.Add(newEvaluation); _context.SaveChanges(); return(newEvaluation); }
public Participant Create(string azureUniqueId, Evaluation evaluation, Organization organization, Role role) { DateTime createDate = DateTime.UtcNow; Participant newParticipant = new Participant { CreateDate = createDate, AzureUniqueId = azureUniqueId, Evaluation = evaluation, Organization = organization, Role = role }; _context.Participants.Add(newParticipant); _context.SaveChanges(); return(newParticipant); }
public Note Create( Participant createdBy, string text, Action action ) { DateTimeOffset createDate = DateTimeOffset.UtcNow; Note newNote = new Note { CreateDate = createDate, Text = text, CreatedBy = createdBy, Action = action }; _context.Notes.Add(newNote); _context.SaveChanges(); return(newNote); }
public Evaluation Create(string name, Project project, string previousEvaluationId) { DateTimeOffset createDate = DateTimeOffset.UtcNow; Evaluation newEvaluation = new Evaluation { CreateDate = createDate, Name = name, Progression = Progression.Nomination, Project = project, Status = Status.Active, Summary = "", PreviousEvaluationId = previousEvaluationId }; _context.Evaluations.Add(newEvaluation); _context.SaveChanges(); return(newEvaluation); }
public Project Create(string fusionProjectID) { DateTimeOffset createDate = DateTimeOffset.UtcNow; Project newProject = new Project { FusionProjectId = fusionProjectID, CreateDate = createDate }; _context.Projects.Add(newProject); _context.SaveChanges(); return(newProject); }
public ClosingRemark Create( Participant createdBy, string text, Action action ) { DateTimeOffset createDate = DateTimeOffset.UtcNow; ClosingRemark newClosingRemark = new ClosingRemark { CreateDate = createDate, Text = text, CreatedBy = createdBy, Action = action }; _context.ClosingRemarks.Add(newClosingRemark); _context.SaveChanges(); return(newClosingRemark); }
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 QuestionTemplate Create( Barrier barrier, Organization organization, string text, string supportNotes, int newOrder = 0 ) { DateTimeOffset createDate = DateTimeOffset.UtcNow; int last = _context.QuestionTemplates .Where(qt => qt.Status == Status.Active) .Max(qt => qt.Order) + 1 ; int maxAdminOrder = _context.QuestionTemplates .Where(qt => qt.Status == Status.Active) .Max(qt => qt.AdminOrder) + 1 ; // If newOrder == 0, we want to place the new // question template as the last one in the barrier if (newOrder == 0) { newOrder = _context.QuestionTemplates .Where(qt => qt.Status == Status.Active) .Where(qt => qt.Barrier == barrier) .Max(qt => qt.Order) + 1 ; } QuestionTemplate newQuestionTemplate = new QuestionTemplate { CreateDate = createDate, Barrier = barrier, Organization = organization, Status = Status.Active, Text = text, Order = last, SupportNotes = supportNotes, AdminOrder = maxAdminOrder }; _context.QuestionTemplates.Add(newQuestionTemplate); _context.SaveChanges(); return(ReorderQuestionTemplateInternal(newQuestionTemplate, newOrder)); }
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 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(); }