public static void Serialize(InterviewToken token, Stream stream)
 {
     using (BinaryWriter writer = new BinaryWriter(stream))
     {
         writer.Write(token.InterviewID.ToByteArray(), 0, 16);
         writer.Write(token.Random);
     }
 }
 public static void Serialize(InterviewToken token, Stream stream)
 {
     using (BinaryWriter writer = new BinaryWriter(stream))
     {
         writer.Write(token.InterviewID.ToByteArray(), 0, 16);
         writer.Write(token.Random);
     }
 }
        public static void SendInvitationEmail(string firstName, string lastName, string emailAddress,
            string senderFirstName, string senderLastName, string senderEmail,
            Guid interviewId)
        {
            string subject = "Interview Invitation";

            string recipientName = string.Format("{0} {1}", firstName, lastName);
            string senderFullName = string.Format("{0} {1}", senderFirstName, senderLastName);

            if (string.IsNullOrWhiteSpace(recipientName))
            {
                recipientName = emailAddress;
            }

            InterviewToken token = new InterviewToken(interviewId, Common.Helpers.RandomHelper.RandomLong());
            string encryptedToken = Convert.ToBase64String(EncryptionHelper.EncryptURL(token.AsBytes()));

            string body = Interpolate(InvitationTemplate,
                KeyValue.Of("SenderName", senderFullName),
                KeyValue.Of("InterviewURI", HttpUtility.UrlEncode(encryptedToken)));

            Enqueue(new EmailMessage
            {
                Subject = subject,
                Body = body,
                Recipient = new EmailRecipient
                {
                    EmailAddress = emailAddress,
                    FullName = recipientName
                },
                SendDate = DateTime.UtcNow,
                UseHtml = true,
                CC = new EmailRecipient
                {
                    FullName = senderFullName,
                    EmailAddress = senderEmail
                }
            });
        }
        private static void ValidateAttemptToken(DbContext context, Guid interviewQuestionId, AttemptToken attemptToken, InterviewToken interviewToken)
        {
            if (attemptToken.InterviewQuestionID != interviewQuestionId)
            {
                throw new Common.Exceptions.ValidationException("Please download the input file again.");
            }

            Guid mostRecentAttemptId = context.Attempts
                .Where(a => a.InterviewQuestionID == interviewQuestionId)
                .OrderByDescending(a => a.CreatedDate)
                .Select(a => a.ID)
                .FirstOrDefault();

            if (attemptToken.MostRecentAttemptID != mostRecentAttemptId)
            {
                throw new Common.Exceptions.ValidationException("Please download the input file again.");
            }
        }
        private static void SendInterviewCompletedEmail(InterviewToken token, DbContext context, E::Interview interview)
        {
            var applicant = context.Applicants
                .Where(a => a.ID == interview.ApplicantID)
                .Select(a => new { FirstName = a.FirstName, LastName = a.LastName, EmailAddress = a.EmailAddress })
                .FirstOrDefault();

            var applicantName = string.IsNullOrEmpty(applicant.FirstName) && string.IsNullOrEmpty(applicant.LastName) ? applicant.EmailAddress : applicant.FirstName + " " + applicant.LastName;

            string recipientName, recipientEmail;

            using (var root = DataController.CreateDbContext())
            {
                var recipient = root.Users
                    .Where(a => a.ID == interview.CreatedBy)
                    .Select(a => new { FirstName = a.FirstName, LastName = a.LastName, EmailAddress = a.EmailAddress })
                    .FirstOrDefault();

                recipientName = string.Format("{0} {1}", recipient.FirstName, recipient.LastName);
                recipientEmail = recipient.EmailAddress;
            }

            EmailController.SendInterviewCompletedEmail(recipientName, applicantName, interview.ID, recipientEmail, TimeSpan.FromMinutes(interview.MinutesAllowed));
        }