mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
new syncronization for quizzes, add only
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using LocalModels;
|
||||
using Management.Planner;
|
||||
using Management.Services;
|
||||
using Management.Services.Canvas;
|
||||
|
||||
public class QuizEditorContext
|
||||
{
|
||||
public event Action? StateHasChanged;
|
||||
private CoursePlanner planner { get; }
|
||||
|
||||
public QuizEditorContext(CoursePlanner planner)
|
||||
public QuizEditorContext(CoursePlanner planner, CanvasService canvas,
|
||||
MyLogger<CanvasAssignmentService> logger)
|
||||
{
|
||||
this.planner = planner;
|
||||
this.canvas = canvas;
|
||||
this.logger = logger;
|
||||
}
|
||||
public event Action? StateHasChanged;
|
||||
private CoursePlanner planner { get; }
|
||||
private CanvasService canvas { get; }
|
||||
|
||||
|
||||
private LocalQuiz? _quiz;
|
||||
private readonly MyLogger<CanvasAssignmentService> logger;
|
||||
|
||||
public LocalQuiz? Quiz
|
||||
{
|
||||
get => _quiz;
|
||||
@@ -62,6 +71,49 @@ public class QuizEditorContext
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task AddQuizToCanvas()
|
||||
{
|
||||
logger.Log("started to add quiz to canvas");
|
||||
if(Quiz == null)
|
||||
{
|
||||
logger.Log("cannot add null quiz to canvas");
|
||||
return;
|
||||
}
|
||||
await planner.LoadCanvasData();
|
||||
if(planner.CanvasQuizzes == null)
|
||||
{
|
||||
logger.Log("cannot add quiz to canvas, failed to retrieve current quizzes");
|
||||
return;
|
||||
}
|
||||
if(planner.LocalCourse == null)
|
||||
{
|
||||
logger.Log("cannot add quiz to canvas, no course stored in planner");
|
||||
return;
|
||||
}
|
||||
var updatedQuiz = await planner.LocalCourse.AddQuizToCanvas(Quiz, planner.CanvasQuizzes, canvas);
|
||||
|
||||
|
||||
|
||||
var courseCanvasId = planner.LocalCourse.Settings.CanvasId;
|
||||
var currentModule = getCurrentModule(Quiz, planner.LocalCourse);
|
||||
|
||||
await canvas.CreateModuleItem(
|
||||
(ulong)courseCanvasId,
|
||||
(ulong)currentModule.CanvasId,
|
||||
updatedQuiz.Name,
|
||||
"Quiz",
|
||||
(ulong)updatedQuiz.CanvasId
|
||||
);
|
||||
|
||||
await planner.LocalCourse.Modules.First().SortModuleItems(
|
||||
(ulong)courseCanvasId,
|
||||
(ulong)currentModule.CanvasId,
|
||||
canvas
|
||||
);
|
||||
logger.Log("added quiz to canvas");
|
||||
}
|
||||
|
||||
private static LocalModule getCurrentModule(LocalQuiz newQuiz, LocalCourse course)
|
||||
{
|
||||
return course.Modules.First(m => m.Quizzes.Select(q => q.Id).Contains(newQuiz.Id))
|
||||
|
||||
Reference in New Issue
Block a user