public async Task <IActionResult> PutTesting(int id, Testing testing) { if (id != testing.EID) { return(BadRequest()); } _context.Entry(testing).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TestingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <TestDetailsResponse> Handle(EditCommand <TestEditCommand, TestDetailsResponse> request, CancellationToken cancellationToken) { var test = await context.Tests.Include(x => x.StudentTests) .SingleAsync(x => x.Id == request.Id, cancellationToken); if (test.StartedAt != null) { throw new InvalidOperationException("A dolgozat nem szerkeszthető az elindítása után."); } test.Name = request.InnerCommand.Name; test.ScheduledStart = request.InnerCommand.ScheduledStart; test.ScheduledLength = TimeSpan.FromMinutes(request.InnerCommand.ScheduledLengthInMinutes); context.StudentTests.RemoveRange(test.StudentTests); context.StudentTests.AddRange(request.InnerCommand.StudentIds.Select(x => new StudentTest { StudentId = x, TestId = test.Id })); await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TestDetailsResponse>(test)); }
public async Task <TestAnswerDetailsResponse> Handle(TestAnswerCreateCommand request, CancellationToken cancellationToken) { var currentUserId = identityService.GetCurrentUserId(); var test = await context.Tests.Include(x => x.Tasks) .Include(x => x.StudentTests) .ThenInclude(x => x.TestAnswer) .Include(x => x.StudentTests) .ThenInclude(x => x.Student) .SingleAsync(x => x.Id == request.TestId, cancellationToken); var studentTest = test.StudentTests.Single(x => x.Student.UserId == currentUserId); if (studentTest.TestAnswer != null) { throw new InvalidOperationException("Ehhez a tanulóhoz már létezik dolgozat megoldás."); } var testAnswer = new TestAnswer { Id = Guid.NewGuid(), Started = DateTime.Now, StudentTest = studentTest, TaskAnswers = new List <TaskAnswer>() }; context.TestAnswers.Add(testAnswer); studentTest.TestAnswer = testAnswer; await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TestAnswerDetailsResponse>(testAnswer)); }
public async Task <TaskAnswerResponse> Handle(TRequest request, CancellationToken cancellationToken) { var currentUserId = identityService.GetCurrentUserId(); var testAnswer = await context.TestAnswers.Include(x => x.TaskAnswers) .SingleAsync(x => x.StudentTest.Student.UserId == currentUserId && x.StudentTest.Test.Tasks.Any(t => t.Id == request.TaskId), cancellationToken); if (testAnswer.Closed != null) { throw new UnauthorizedAccessException("A beadás nem módosítható, mert már lezárásra került."); } var answer = testAnswer.TaskAnswers.SingleOrDefault(x => x.TestTaskId == request.TaskId); if (answer == null) { answer = mapper.Map <TaskAnswerCreateEditCommand, TaskAnswer>(request); context.TaskAnswers.Add(answer); } else { mapper.Map <TaskAnswerCreateEditCommand, TaskAnswer>(request, answer); } await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TaskAnswer, TaskAnswerResponse>(answer)); }
public async Task <TestTaskEditorResponse> Handle(TCommand request, CancellationToken cancellationToken) { var task = mapper.Map <TestTaskCreateEditCommand, TestTask>(request); context.Tasks.Add(task); await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TestTaskEditorResponse>(task)); }
public async Task <TestDetailsResponse> Handle(TestStartCommand request, CancellationToken cancellationToken) { var test = await context.Tests.FindOrThrowAsync(request.Id, cancellationToken); test.Start(); await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TestDetailsResponse>(test)); }
public async Task <Unit> Handle(TaskAnswerCorrectCommand request, CancellationToken cancellationToken) { var answer = await context.TaskAnswers.FindOrThrowAsync(request.TaskAnswerId, cancellationToken); answer.ManualCorrect(request.GivenPoints); await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <TestDetailsResponse> Handle(TestCloseCommand request, CancellationToken cancellationToken) { var test = await context.Tests.Include(x => x.StudentTests) .ThenInclude(x => x.TestAnswer) .SingleAsync(x => x.Id == request.Id, cancellationToken); test.Close(); await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TestDetailsResponse>(test)); }
public async Task <TestTaskEditorResponse> Handle(EditCommand <TCommand, TestTaskEditorResponse> request, CancellationToken cancellationToken) { var task = await context.Tasks.Include(x => x.Test) .SingleAsync(x => x.Id == request.Id, cancellationToken); if (task.Test.StartedAt != null) { throw new InvalidOperationException("A feladatok nem szerkeszthetők a dolgozat megkezdése után."); } mapper.Map <TestTaskCreateEditCommand, TestTask>(request.InnerCommand, task); await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TestTask, TestTaskEditorResponse>(task)); }
public async Task <Unit> Handle(TestAnswerCloseCommand request, CancellationToken cancellationToken) { var currentUserId = identityService.GetCurrentUserId(); var answer = await context.TestAnswers.Include(x => x.StudentTest) .ThenInclude(x => x.Student) .SingleAsync(x => x.Id == request.Id, cancellationToken); if (answer.StudentTest.Student.UserId != currentUserId) { throw new UnauthorizedAccessException("Mindenki csak a saját dolgozat beadását módosíthatja!"); } answer.Close(false); await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(TestCorrectCommand request, CancellationToken cancellationToken) { var test = await context.Tests.Include(x => x.Answers) .ThenInclude(x => x.TaskAnswers) .SingleAsync(x => x.Id == request.TestId, cancellationToken); foreach (var testAnswer in test.Answers) { foreach (var taskAnswer in testAnswer.TaskAnswers) { taskAnswer.AutoCorrect(); } } await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <TestDetailsResponse> Handle(TestCreateCommand request, CancellationToken cancellationToken) { var test = new Test { Name = request.Name, ScheduledStart = request.ScheduledStart, ScheduledLength = TimeSpan.FromMinutes(request.ScheduledLengthInMinutes), ClassSchoolYearSubjectId = request.ClassSchoolYearSubjectId, StudentTests = request.StudentIds.Select(x => new StudentTest { StudentId = x }).ToList() }; context.Tests.Add(test); await context.SaveChangesAsync(cancellationToken); return(mapper.Map <TestDetailsResponse>(test)); }
public async Task <TestTaskEditorResponse> Handle(MultipleChoiceTestTaskCreateEditCommand request, CancellationToken cancellationToken) { var options = request.Options.Select(x => new MultipleChoiceTestTaskOption { Value = x }).ToList(); var task = new MultipleChoiceTestTask { Description = request.Description, CorrectOption = options[request.CorrectOptionIndex], Options = options, IncorrectAnswerPointValue = request.IncorrectAnswerPointValue, PointValue = request.PointValue, TestId = request.TestId }; context.Tasks.Add(task); await context.SaveChangesAsync(cancellationToken); return(mapper.Map <MultipleChoiceTestTaskEditorResponse>(task)); }
public async Task <TestTaskEditorResponse> Handle( EditCommand <MultipleChoiceTestTaskCreateEditCommand, TestTaskEditorResponse> request, CancellationToken cancellationToken) { var task = await context.Set <MultipleChoiceTestTask>() .Include(x => x.Options) .Include(x => x.Test) .SingleAsync(x => x.Id == request.Id, cancellationToken); if (task.Test.StartedAt != null) { throw new InvalidOperationException("A feladatok nem szerkeszthetők a dolgozat megkezése után."); } context.Set <MultipleChoiceTestTaskOption>() .RemoveRange(task.Options); var options = request.InnerCommand.Options.Select(x => new MultipleChoiceTestTaskOption { Id = Guid.NewGuid(), Value = x, TestTask = task }).ToList(); context.Set <MultipleChoiceTestTaskOption>() .AddRange(options); task.CorrectOption = options[request.InnerCommand.CorrectOptionIndex]; task.Description = request.InnerCommand.Description; task.PointValue = request.InnerCommand.PointValue; task.IncorrectAnswerPointValue = request.InnerCommand.IncorrectAnswerPointValue; await context.SaveChangesAsync(cancellationToken); return(mapper.Map <MultipleChoiceTestTaskEditorResponse>(task)); }
public async Task SaveAsync() { await db.SaveChangesAsync(); }