public CandidateTest CreateTest(CandidateTest test)
 {
     test.Created = DateTime.UtcNow;
     _context.Tests.Add(test);
     _context.SaveChanges();
     return(test);
 }
 public ConditionalExpressionInfo(ConditionalExpression node, Stack <Expression> stack, CandidateTest matchingTest)
 {
     this.Expression = node;
     this.Hierarchy  = stack;
     this.Test       = matchingTest;
     this.Test.MatchCount++;
 }
Beispiel #3
0
        public async Task <CandidateTestDto> CreateCandidateTest(UserInfo userInfo)
        {
            if (userInfo.IsCandidateLogin)
            {
                throw new Exception("You do not have access to perform this action!");
            }

            using (var db = new CMSContext())
            {
                var candidate = await db.Candidates.SingleOrDefaultAsync(c => c.Id == Dto.CandidateId && c.CompanyId == userInfo.CompanyId);

                if (candidate == null)
                {
                    throw new Exception("Candidate with specified id was not found!");
                }

                var checkExistingCandidate = db.CandidateTests.Any(c => c.CandidateId == Dto.CandidateId && c.TestId == Dto.TestId);
                if (checkExistingCandidate)
                {
                    throw new Exception("Candidate already has this Test in his profile!");
                }

                var candidateTest = new CandidateTest
                {
                    Id          = Guid.NewGuid(),
                    CandidateId = Dto.CandidateId,
                    TestId      = Dto.TestId,
                };

                db.CandidateTests.Add(candidateTest);

                var testScores = await db.TestScores.Include(ts => ts.Test).Where(c => c.TestId == Dto.TestId && c.Test.CompanyId == userInfo.CompanyId).ToListAsync();

                if (testScores == null)
                {
                    throw new Exception("Test Score with specified id was not found!");
                }

                foreach (var testScore in testScores)
                {
                    var candidateTestScore = new CandidateTestScore
                    {
                        Id = Guid.NewGuid(),
                        CandidateTestId = candidateTest.Id,
                        TestScoreId     = testScore.Id,
                        Value           = null,
                        Comment         = null
                    };

                    db.CandidateTestScores.Add(candidateTestScore);
                }

                await db.SaveChangesAsync();

                return((await new GetCandidateTestsInternalQuery(Dto.TestId, companyId: userInfo.CompanyId, candidateId: Dto.CandidateId).GetCandidateTests()).SingleOrDefault());
            }
        }
 public CandidateTestModel(CandidateTest testEntity)
 {
     TestId       = testEntity.TestId;
     Name         = testEntity.Name;
     CandidateId  = testEntity.CandidateId;
     Created      = testEntity.Created;
     Finished     = testEntity.Finished;
     HasQuestions = testEntity.TestQuestions.Any();
 }
 public ActionResult <CandidateTest> CreateTest(CandidateTest test)
 {
     return(_interviewService.CreateTest(test));
 }