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();
            }
        }
Esempio n. 2
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());
        }