private static E.Applicant CreateApplicant(DbContext context, string firstName, string lastName, string emailAddress, string username) { Common.Helpers.ValidationHelper.ValidateRequiredField(firstName, "First Name"); Common.Helpers.ValidationHelper.ValidateRequiredField(lastName, "Last Name"); Common.Helpers.ValidationHelper.ValidateRequiredField(emailAddress, "Email Address"); Common.Helpers.ValidationHelper.ValidateStringLength(firstName, "First Name", Constants.MaxNameLength); Common.Helpers.ValidationHelper.ValidateStringLength(lastName, "Last Name", Constants.MaxNameLength); Common.Helpers.ValidationHelper.ValidateStringLength(emailAddress, "Email Address", Constants.MaxEmailAddressLength); Common.Helpers.ValidationHelper.ValidateEmailAddress(emailAddress); E::Applicant newApplicant = new E::Applicant(); newApplicant.ID = Guid.NewGuid(); newApplicant.FirstName = firstName; newApplicant.LastName = lastName; newApplicant.EmailAddress = emailAddress; newApplicant.CreatedBy = username; newApplicant.CreatedDate = DateTime.UtcNow; newApplicant.LastUpdatedBy = username; newApplicant.LastUpdatedDate = DateTime.UtcNow; context.Applicants.Add(newApplicant); return newApplicant; }
private static void ChangePassword(DbContext context, User user, string newPassword) { byte[] salt; user.PasswordHash = HashPasswordGeneratingSalt(newPassword, out salt); user.PasswordSalt = salt; context.SaveChanges(); }
public static void CreateUser(DbContext context, string username, string password, string emailAddress, string firstName, string lastName, bool isAdmin) { User user = new User(); user.ID = username; user.FirstName = firstName; user.LastName = lastName; user.EmailAddress = emailAddress; user.CreatedDate = DateTime.UtcNow; user.LastUpdatedDate = DateTime.UtcNow; user.IsAdmin = isAdmin; byte[] salt; user.PasswordHash = HashPasswordGeneratingSalt(password, out salt); user.PasswordSalt = salt; context.Users.Add(user); }
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)); }
private static void AddQuestions(DbContext context, Guid interviewId, bool useQuestionSet, Guid? questionSetId, Guid[] questionIds) { if (useQuestionSet) { questionIds = context.QuestionSetQuestions .Where(q => q.QuestionSetID == questionSetId.Value) .Select(q => q.QuestionID) .ToArray(); } foreach (Guid questionId in questionIds) { E::InterviewQuestion newInterviewQuestion = new E.InterviewQuestion(); newInterviewQuestion.ID = Guid.NewGuid(); newInterviewQuestion.InterviewID = interviewId; newInterviewQuestion.QuestionID = questionId; context.InterviewQuestions.Add(newInterviewQuestion); } }