/// <summary>
        /// This function adds/update the job application and creates the candidate if couldn't find one
        /// </summary> 
        /// <param name="jApplication"></param>
        /// <returns></returns>
        // ReSharper disable once FunctionComplexityOverflow
        public JobApplicationPostResponse AddUpdateJobApplication(JobApplication jApplication)
        {
            var response = new JobApplicationPostResponse
            {
                ContactId = -1,
                JobApplicationId = -1
            };
            var context = new dbDataContext();
            // check candidate - create or update candidate details
            if (jApplication.JobApplicationId <= 0)
            {
                var contactId = new Contacts().AddUpdateCandidate(jApplication.Candidate);
                if (contactId > 0)
                    jApplication.ContactId = contactId;
                else
                    return response;
            }
            response.ContactId = jApplication.ContactId;
            // check for job Application - create or update job application details
            var jobApplication = context.tbl_JobApplications.FirstOrDefault(t => t.JobApplicationId == jApplication.JobApplicationId) ?? new tbl_JobApplication();
            jobApplication.CandidateId = jApplication.ContactId;
            jobApplication.JobId = jApplication.JobId;
            jobApplication.AgentId = jApplication.AgentId;
            jobApplication.InternalCandidate = jApplication.InternalCandidate;
            //check for application status changing
            var isAppStatusChanged = (jobApplication.ApplicationStatusId != jApplication.ApplicationStatusId);
            jobApplication.ApplicationStatusId = jApplication.ApplicationStatusId;
            jobApplication.LastUpdatedDate = DateTime.Now;
            jobApplication.ReferrerId = jApplication.ReferrerId;
            jobApplication.ReferredBy = jApplication.ReferredBy;
            jobApplication.ReferringEmpNo = jApplication.ReferringEmpNo;
            jobApplication.UrlReferrer = jApplication.UrlReferrer;

            try
            {
                var isAdd = false;
                // Add/Update candidate
                if (jobApplication.JobApplicationId <= 0)
                {
                    isAdd = true;
                    jobApplication.CreatedDate = DateTime.Now;
                    jobApplication.ApplicationStatusId = jobApplication.ApplicationStatusId < 1 ? 1 : jobApplication.ApplicationStatusId;
                    context.tbl_JobApplications.InsertOnSubmit(jobApplication);
                }
                context.SubmitChanges();

                // Add Application status changed record


                if (isAdd && jobApplication.ApplicationStatusId != 1)
                {
                    //add the new candidates status first
                    new ApplicationStatuses().ChangeApplicationStatuses(jobApplication.JobApplicationId.ToString(), 1);
                }
                if (isAppStatusChanged)
                    new ApplicationStatuses().ChangeApplicationStatuses(jobApplication.JobApplicationId.ToString(), jobApplication.ApplicationStatusId);

                //send notification email 
                if (isAdd && jApplication.SendConfirmationEmail)
                {
                    var contact = new Contacts().GetCandidate(jApplication.ContactId);
                    if (contact != null && !string.IsNullOrEmpty(contact.Email))
                    {
                        try
                        {
                            var template = new Templates().GetTemplates(new TemplateFilter { Title = "Job Application Successful" }).FirstOrDefault();
                            if (template != null)
                            {
                                var emailBody = Utils.GetFullEmailReplacingMainTemplateTags(-1, template.TemplateBody);
                                emailBody = new Utils().GetOriginalBody(emailBody, jApplication.ContactId, jApplication.JobId, 0, 0, 0, contact);
                                //send email
                                var email = new Email
                                {
                                    Body = emailBody,
                                    FromAddress = new Recipient { DisplayName = "Resonate Search", MailAddress = "*****@*****.**" },
                                    Subject = template.Subject,
                                    ToAddress = new Recipient { DisplayName = contact.Forename + " " + contact.Surname, MailAddress = contact.Email }
                                };
                                new Emails().SendEmail(email);
                            }
                        }
                        catch (Exception)
                        {
                            //ignore
                        }
                    }
                }
                if (isAdd)
                    // Add History Record 
                    new Histories().AddHistory(new History
                    {
                        RefId = jApplication.ContactId,
                        RefType = "Contact",
                        ClientUserId = jApplication.UpdatedBy,
                        TypeId = 4,
                        SubRefType = "JobApplication",
                        SubRefId = jobApplication.JobApplicationId
                    });

                response.JobApplicationId = jobApplication.JobApplicationId;
                return response;
            }
            catch (Exception)
            {
                return response;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Do not replace the body if the object is null
        /// </summary>
        /// <param name="rawBody"></param>
        /// <param name="contactId"></param>
        /// <param name="jobId"></param>
        /// <param name="userId"></param>
        /// <param name="consultantid"></param>
        /// <param name="clientId"></param>
        /// <param name="candidate"></param>
        /// <param name="job"></param>
        /// <param name="cUser"></param>
        /// <param name="consultant"></param>
        /// <param name="client"></param>
        /// <param name="intRequestId"></param>
        /// <param name="timeSlotId"></param>
        /// <returns></returns>
        public string GetOriginalBodyForPreview(string rawBody, int contactId = 0, int jobId = 0, int userId = 0, int consultantid = 0, int clientId = 0,
        Candidate candidate = null, Job job = null, User cUser = null, User consultant = null, Client client = null, int intRequestId = 0, int timeSlotId = 0)
        {
            // get contact by id  
            if (contactId > 0)
                candidate = new Contacts().GetCandidate(contactId);
            //retrieve objects if null and have an id passed
            if (job == null && jobId > 0)
                job = new Jobs().GetJob(jobId);
            if (cUser == null && userId > 0)
                cUser = new Users().GetUser(userId);
            if (consultant == null && consultantid > 0)
                consultant = new Users().GetUser(consultantid);
            if (client == null && clientId > 0)
                client = new Clients().GetClient(clientId);

            InterviewRequest intRequest = null;
            if (intRequestId > 0)
            {
                intRequest = new Interviews().GetInterviewRequest(intRequestId);
            }

            TimeSlot timeSlot = null;
            if (timeSlotId > 0)
            {
                timeSlot = new Interviews().GetTimeSlot(timeSlotId);
            }

            //Contact
            if (candidate != null)
            {
                var pwdlink = "http://www.resonatesearch.co.uk/reset-password.aspx?token=" + candidate.RefId;
                rawBody = rawBody.Replace("#ContactTitle#", candidate.Title);
                rawBody = rawBody.Replace("#ContactForename#", candidate.Forename);
                rawBody = rawBody.Replace("#ContactSurname#", candidate.Surname);
                rawBody = rawBody.Replace("#ContactJobTitle#", candidate.JobTitle);
                rawBody = rawBody.Replace("#ContactEmployer#", candidate.Employer);
                rawBody = rawBody.Replace("#ContactEmail#", candidate.Email);
                rawBody = rawBody.Replace("#ContactPassword#", candidate.Password);
                if (string.IsNullOrEmpty(candidate.Password))
                    rawBody = rawBody.Replace("#PasswordResetLink#", "If you wish to create a password for your account on  Resonate Search please click link below:<br/><a href='" + pwdlink + "'>" + pwdlink + "</a><br/>");
                else
                    rawBody = rawBody.Replace("#PasswordResetLink#", "");
            }


            //Job
            if (job != null)
            {
                rawBody = rawBody.Replace("#VacancyTitle#", job.JobTitle);
                rawBody = rawBody.Replace("#VacancyRef#", job.Ref);
                rawBody = rawBody.Replace("#VacancyBenefits#", job.Benefits);
                rawBody = rawBody.Replace("#VacancyOverview#", job.Overview);
            }


            // User
            if (cUser != null)
            {
                rawBody = rawBody.Replace("#UserForename#", cUser.Forename);
                rawBody = rawBody.Replace("#UserSurname#", cUser.Surname);
                rawBody = rawBody.Replace("#UserEmail#", cUser.Email);
                rawBody = rawBody.Replace("#UserMobile#", cUser.Mobile);
                rawBody = rawBody.Replace("#UserPassword#", cUser.Password);
                rawBody = rawBody.Replace("#UserJobTitle#", cUser.JobTitle);
            }

            // Consultant
            if (consultant != null)
            {
                rawBody = rawBody.Replace("#ConsultantForename#", consultant.Forename);
                rawBody = rawBody.Replace("#ConsultantSurname#", consultant.Surname);
                rawBody = rawBody.Replace("#ConsultantEmail#", consultant.Email);
                rawBody = rawBody.Replace("#ConsultantMobile#", consultant.Mobile);
                rawBody = rawBody.Replace("#ConsultantJobTitle#", consultant.Password);
            }


            // Client
            if (client != null)
            {
                rawBody = rawBody.Replace("#ClientName#", client.ClientName);
                rawBody = rawBody.Replace("#ClientEmail#", client.Email);
            }


            // Interview Request  
            if (intRequest != null)
            {
                var requestLink = "http://www.resonatesearch.co.uk/interview/interview-request.aspx?ref=" + intRequest.RefId;
                rawBody = rawBody.Replace("#InterviewRequestLink#", requestLink);
            }

            // Time Slot
            if (timeSlot != null)
            {
                rawBody = rawBody.Replace("#InterviewDate#", "Interview Date: <b>" + Convert.ToDateTime(timeSlot.SlotDate).ToString("dd MMM, yyyy") + " - " + timeSlot.SlotTime + "</b>");
                rawBody = rawBody.Replace("#Duration#", "Duration:<b> " + GetDurationText(timeSlot.Duration) + "</b>");
                rawBody = rawBody.Replace("#InterviewLocation#", timeSlot.Location != null ? GetInterviewLocation(timeSlot) : "");
                rawBody = rawBody.Replace("#Interviewers#", timeSlot.Interviewers != null && timeSlot.Interviewers.Any() ? GetInterviewers(timeSlot) : "");
            }

            return rawBody;
        }