예제 #1
0
        public async Task <IActionResult> CreateSessionForAttendee([FromBody] TestAttendees attendee, [FromRoute] string testLink, [FromRoute] bool isTestEnd)
        {
            await HttpContext.Session.LoadAsync();

            if (isTestEnd)
            {
                HttpContext.Session.SetString(_stringConstants.Path, "");
                var response = await _reportRepository.SetTestStatusAsync(attendee, isTestEnd);

                if (response == null)
                {
                    return(NotFound());
                }
            }
            else
            {
                if (HttpContext.Session.GetInt32(_stringConstants.AttendeeIdSessionKey) == null)
                {
                    HttpContext.Session.SetInt32(_stringConstants.AttendeeIdSessionKey, attendee.Id);
                }
                var response = await _reportRepository.SetTestStatusAsync(attendee, isTestEnd);

                if (response == null)
                {
                    return(NotFound());
                }
            }
            return(Ok(attendee));
        }
예제 #2
0
        /// <summary>
        ///This method used to initialize test attendee model parameters.
        /// </summary>
        /// <returns>It return TestAttendee model object which contain first name,last name,email,contact number,roll number</returns>
        private TestAttendees InitializeTestAttendeeParameters()
        {
            var testAttendee = new TestAttendees()
            {
                FirstName     = "Hardik",
                LastName      = "Patel",
                Email         = "*****@*****.**",
                ContactNumber = "1234567890",
                RollNumber    = "13it055",
                TestLogs      = new DomainModel.Models.TestLogs.TestLogs()
                {
                    VisitTestLink        = default(DateTime),
                    FillRegistrationForm = default(DateTime),
                    StartTest            = default(DateTime),
                    FinishTest           = default(DateTime)
                },
                Report = new DomainModel.Models.Report.Report()
                {
                    TimeTakenByAttendee = 0,
                    TotalMarksScored    = 4
                }
            };

            return(testAttendee);
        }
예제 #3
0
        public async Task <TestAttendees> SetTestStatusAsync(TestAttendees attendee, bool isTestEnd)
        {
            attendee.Report = await _dbContext.Report.FirstOrDefaultAsync(x => x.TestAttendeeId == attendee.Id);

            if (attendee.Report != null)
            {
                if (isTestEnd)
                {
                    attendee.Report.IsTestPausedUnWillingly = false;
                    if (attendee.Report.TestStatus == TestStatus.AllCandidates)
                    {
                        attendee.Report.TestStatus = TestStatus.CompletedTest;
                    }
                }
                else
                {
                    attendee.Report.IsTestPausedUnWillingly = false;
                    attendee.Report.IsAllowResume           = true;
                    attendee.Report.TestStatus = TestStatus.AllCandidates;
                }
                _dbContext.Report.Update(attendee.Report);
                await _dbContext.SaveChangesAsync();

                return(attendee);
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        /// <summary>
        /// This method gets the generated report of the candidate and then sends back to the report display page
        /// </summary>
        /// <param name="testAttendee"></param>
        /// <returns>Sends the testAttendee object to getReport method in client side</returns>
        public Task SendReport(TestAttendees testAttendee)
        {
            string connectionId = Context.ConnectionId;

            Attendees.TryGetValue(connectionId, out Attendee attendee);
            if (attendee != null)
            {
                attendee.IsAttendeeReset = false;
            }

            return(Clients.All.InvokeAsync("getReport", testAttendee));
        }
예제 #5
0
        public async Task <bool> IsTestAttendeeExistAsync(TestAttendees testAttendee, string magicString)
        {
            var testObject = (await _dbContext.Test.FirstOrDefaultAsync(x => (x.Link == magicString)));

            if (testObject != null)
            {
                testAttendee.TestId = testObject.Id;
                var isTestAttendeeExist = await _dbContext.TestAttendees.AnyAsync(x => x.Email == testAttendee.Email && x.TestId == testAttendee.TestId && x.RollNumber == testAttendee.RollNumber);

                return(isTestAttendeeExist);
            }
            return(false);
        }
예제 #6
0
        /// <summary>
        /// Creates an attendee for a test
        /// </summary>
        /// <param name="testId">Id of the test taken by an attendee</param>
        /// <returns>Object of TestAttendees</returns>
        private TestAttendees CreateTestAttendee(int testId)
        {
            var testAttendee = new TestAttendees()
            {
                Id         = 1,
                FirstName  = "Madhurima",
                LastName   = "Das",
                Email      = "*****@*****.**",
                RollNumber = "1",
                TestId     = testId,
                AttendeeBrowserToleranceCount = 0
            };

            return(testAttendee);
        }
예제 #7
0
        /// <summary>
        /// Creates test attendee
        /// </summary>
        /// <param name="testId">Contains the Id of the Test taken by the test attendee</param>
        /// <returns>Object of Test Attendees</returns>
        private TestAttendees CreateTestAttendee(int testId)
        {
            var testAttendee = new TestAttendees()
            {
                Id            = 1,
                FirstName     = "Madhurima",
                LastName      = "Das",
                Email         = "*****@*****.**",
                RollNumber    = "1",
                ContactNumber = "98098776708",
                TestId        = testId
            };

            return(testAttendee);
        }
예제 #8
0
        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));
                }
            }
        }
예제 #9
0
        public async Task RegisterTestAttendeesAsync(TestAttendees testAttendee)
        {
            await _dbContext.TestAttendees.AddAsync(testAttendee);

            await _dbContext.SaveChangesAsync();

            var testLogsObject = new TestLogs();

            if (testLogsObject != null)
            {
                testLogsObject.TestAttendeeId       = testAttendee.Id;
                testLogsObject.VisitTestLink        = DateTime.UtcNow;
                testLogsObject.FillRegistrationForm = DateTime.UtcNow;
                await _dbContext.TestLogs.AddAsync(testLogsObject);

                await _dbContext.SaveChangesAsync();
            }
        }
예제 #10
0
        /// <summary>
        ///This method used to initialize test attendee model parameters.
        /// </summary>
        /// <returns>It return TestAttendee model object which contain first name,last name,email,contact number,roll number</returns>
        private TestAttendees TestAttendeeReport(int id)
        {
            var testAttendee = new TestAttendees()
            {
                Id               = 1,
                FirstName        = "Hardik",
                LastName         = "Patel",
                Email            = "*****@*****.**",
                ContactNumber    = "1234567890",
                RollNumber       = "13it055",
                StarredCandidate = true,
                TestId           = id,
                Report           = new Report()
                {
                    Percentage          = 45.55,
                    Percentile          = 46,
                    TotalMarksScored    = 45.55,
                    TestStatus          = TestStatus.BlockedTest,
                    TimeTakenByAttendee = 45
                }
            };

            return(testAttendee);
        }
예제 #11
0
        /// <summary>
        /// This method is used to create a test attendee with attendee details under a test
        /// </summary>
        /// <param name="testId">Id of the test</param>
        /// <returns>returns the object of type TestAttendees</returns>
        private TestAttendees CreateTestAttendee(int testId)
        {
            var testAttendee = new TestAttendees()
            {
                Id         = 1,
                FirstName  = "Ritika",
                LastName   = "Mohata",
                Email      = "*****@*****.**",
                RollNumber = "1",
                TestId     = testId,
                Report     = new DomainModel.Models.Report.Report()
                {
                    Id                  = 1,
                    TestAttendeeId      = 1,
                    TotalMarksScored    = 180,
                    Percentage          = 80,
                    Percentile          = 50,
                    TestStatus          = 0,
                    TimeTakenByAttendee = 150
                },
            };

            return(testAttendee);
        }
예제 #12
0
        public async Task <IActionResult> GetTestBundle([FromRoute] string link, [FromRoute] bool isPreview)
        {
            var attendeeId   = 0;
            var testBundle   = new TestBundleModelAC();
            var testAttendee = new TestAttendees();

            if (link == null)
            {
                return(BadRequest());
            }

            if (!await _testConductRepository.IsTestInValidDateWindow(link, isPreview))
            {
                return(NotFound());
            }

            if (isPreview == false)
            {
                await HttpContext.Session.LoadAsync();

                var attendeeSession = HttpContext.Session.GetInt32(_stringConstants.AttendeeIdSessionKey);

                if (attendeeSession == null)
                {
                    return(NotFound());
                }

                //TODO: optimization scope
                if (!await _testConductRepository.IsTestAttendeeExistByIdAsync(attendeeSession.Value))
                {
                    return(NotFound());
                }

                attendeeId = attendeeSession.Value;

                testAttendee = await _testConductRepository.GetTestAttendeeByIdAsync(attendeeId);
            }
            var testDetails = await _testRepository.GetTestByLinkAsync(link);

            if (testDetails == null)
            {
                return(NotFound());
            }

            if (isPreview == false)
            {
                await _testRepository.SetStartTestLogAsync(attendeeId);
            }

            var questions = await _testRepository.GetTestQuestionByTestIdAsync(testDetails.Id);

            if (testAttendee.Report != null && (testAttendee.Report.TestStatus == TestStatus.BlockedTest || testAttendee.Report.TestStatus == TestStatus.ExpiredTest))
            {
                await HttpContext.Session.LoadAsync();

                HttpContext.Session.SetString(_stringConstants.Path, "");
            }

            testBundle.Test          = testDetails;
            testBundle.TestQuestions = questions;
            testBundle.TestAttendee  = testAttendee;

            return(Ok(testBundle));
        }