private async Task CalculateResult(IDialogContext context)
        {
            var  totalScore = _responses.Sum(x => x.Score);
            bool isPass;

            if (totalScore >= 3)
            {
                isPass = true;
                await context.PostAsync("Congratulations, You have cleared intial screening round.");
            }
            else
            {
                isPass = false;
                await context.PostAsync("Sorry, You have not cleared the intial screening round.");
            }
            using (var dbContext = new InterviewDataContext())
            {
                dbContext.Responses.AddRange(_responses);

                dbContext.Interviews.Add(new Interview
                {
                    StartTime = DateTime.Now,
                    EndTime   = DateTime.Now,
                    Score     = totalScore,
                    IsPass    = isPass
                });
                dbContext.SaveChanges();
            }
        }
        private List <Data.Models.Skill> GetMatchingSkills(IDialogContext context)
        {
            using (var dbContext = new InterviewDataContext())
            {
                var candidateId = context.UserData.GetValue <int>("CandidateId");
                var candidate   = dbContext.Candidates.First(x => x.Id == candidateId);

                var skills = candidate.Skills.Split(',');

                var test           = dbContext.Skills.Include("Topics.Questions").ToList();
                var matchingSkills = test
                                     .Where(x => skills.Contains(x.Name, StringComparer.OrdinalIgnoreCase)).ToList();
                return(matchingSkills);
            }
        }
Exemple #3
0
        public static IForm <InterviewCandidate> BuildForm()
        {
            return(new FormBuilder <InterviewCandidate>()
                   .OnCompletion(async(context, profileForm) =>
            {
                // Save  Candidate Data
                try
                {
                    var userName = context.UserData.GetValue <string>("Name");

                    List <Skill> skills = profileForm.Skills;
                    var candidateSkills = skills.Select(s => s.ToString()).ToList();

                    var candidate = new Candidate
                    {
                        Name = userName,
                        Email = profileForm.Email,
                        Phone = profileForm.PhoneNumber,
                        Skills = String.Join(",", candidateSkills)
                    };

                    using (var dbContext = new InterviewDataContext())
                    {
                        candidate = dbContext.Candidates.Add(candidate);
                        dbContext.SaveChanges();
                    }
                    context.UserData.SetValue <int>("CandidateId", candidate.Id);

                    await context.PostAsync("");
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                // Tell the user that the form is complete
            })
                   .Build());
        }