/// <summary> /// Adds a classroom gradebook to the database. /// </summary> public TestDatabaseBuilder AddSectionGradebook( string classroomName, string gradebookName, string sectionName, DateTime lastTransferDate) { var classroom = _buildContext.Classrooms .Include(c => c.Sections) .Include(c => c.ClassroomGradebooks) .Single(c => c.Name == classroomName); var section = classroom.Sections .Single(s => s.Name == sectionName); var classroomGradebook = classroom.ClassroomGradebooks .Single(cg => cg.Name == gradebookName); var sectionGradebook = new SectionGradebook() { ClassroomGradebookId = classroomGradebook.Id, SectionId = section.Id, LastTransferDate = lastTransferDate }; _buildContext.SectionGradebooks.Add(sectionGradebook); _buildContext.SaveChanges(); return(this); }
/// <summary> /// Marks assignments in the given section as graded. /// </summary> public async Task MarkAssignmentsGradedAsync( string classroomName, string sectionName, string gradebookName, DateTime dateTime) { var classroom = await LoadClassroomAsync(classroomName); var section = classroom.Sections.SingleOrDefault(s => s.Name == sectionName); if (section == null) { throw new InvalidOperationException("Invalid section."); } var classroomGradebook = await _dbContext.ClassroomGradebooks .Where(cg => cg.ClassroomId == classroom.Id) .Where(cg => cg.Name == gradebookName) .SingleAsync(); var sectionGradebook = await _dbContext.SectionGradebooks .Where(sg => sg.Section.Name == sectionName) .Where(sg => sg.ClassroomGradebook.Id == classroomGradebook.Id) .SingleOrDefaultAsync(); if (sectionGradebook == null) { sectionGradebook = new SectionGradebook() { SectionId = section.Id, ClassroomGradebookId = classroomGradebook.Id, LastTransferDate = dateTime }; _dbContext.Add(sectionGradebook); } else { sectionGradebook.LastTransferDate = dateTime; _dbContext.Update(sectionGradebook); } await _dbContext.SaveChangesAsync(); }