public async Task <IActionResult> RegisterTestAttendeesAsync([FromBody] TestAttendees testAttendee, [FromRoute] string magicString) { if (!ModelState.IsValid) { return(BadRequest()); } var test = await _testRepository.GetTestByLinkAsync(magicString); //If test link is invalid if (test == null) { return(BadRequest()); } testAttendee.TestId = test.Id; var dbTestAttendee = await _testConductRepository.GetTestAttendeeByEmailIdAndRollNo(testAttendee.Email, testAttendee.RollNumber, testAttendee.TestId); //If attendee doesnt exist add him if (dbTestAttendee == null) { await _testConductRepository.RegisterTestAttendeesAsync(testAttendee); HttpContext.Session.SetInt32(_stringConstants.AttendeeIdSessionKey, testAttendee.Id); return(Ok(testAttendee)); } //If attendee exist else { var testStatus = await _testConductRepository.GetAttendeeTestStatusAsync(dbTestAttendee.Id); //Then check his status if (testStatus != TestStatus.AllCandidates) { return(NotFound()); } //If status is first one then just set session and return him else { HttpContext.Session.SetInt32(_stringConstants.AttendeeIdSessionKey, dbTestAttendee.Id); return(Ok(testAttendee)); } } }
public async Task ValidRegisterTestAttendeesAsyncTest() { var testAttendee = InitializeTestAttendeeParameters(); await CreateTestAsync(); await _testConductRepository.RegisterTestAttendeesAsync(testAttendee); Assert.True(_trappistDbContext.TestAttendees.Count() == 1); Assert.True(testAttendee.TestLogs.VisitTestLink != default(DateTime)); Assert.True(testAttendee.TestLogs.FillRegistrationForm != default(DateTime)); }
public async Task GetTestAttendeeReportAsyncTest() { var createTest = await CreateTestAsync(); var testAttendeeReport = TestAttendeeReport(createTest.Id); await _testConductRepository.RegisterTestAttendeesAsync(testAttendeeReport); var report = await _reportRepository.GetAllTestAttendeesAsync(createTest.Id); Assert.True(report.Count() == 1); }