// Interface method public SocialMediaProcessedResponse ProcessData(string data, string state, string linkedInJson) { SocialMediaProcessedResponse processedResponse = null; if (!linkedInJson.IsNullOrEmpty()) { processedResponse = new SocialMediaProcessedResponse(); try { var linkedInRequest = new LinkedInSocialMediaRequest(); linkedInRequest.LinkedInApplicationJson = linkedInJson; var linkedInSocialMediaService = new LinkedInSocialMediaService(); var linkedInSocialMediaResponse = linkedInSocialMediaService.ProcessSocialMediaIntegration <LinkedInSocialMediaResponse, LinkedInSocialMediaRequest>(linkedInRequest); if (linkedInSocialMediaResponse.SocialMediaProcessSuccess) { processedResponse.Success = true; processedResponse.Email = linkedInSocialMediaResponse.LinkedInJobApplication.emailAddress; processedResponse.FirstName = linkedInSocialMediaResponse.LinkedInJobApplication.firstName; processedResponse.LastName = linkedInSocialMediaResponse.LinkedInJobApplication.lastName; processedResponse.PhoneNumber = linkedInSocialMediaResponse.LinkedInJobApplication.phoneNumber; processedResponse.FileStream = GenerateWordResumeStream(linkedInSocialMediaResponse.HTMLResumeFile); processedResponse.FileName = processedResponse.FirstName.ToLower() + "-" + processedResponse.LastName.ToLower() + "-" + DateTime.Now.ToFileTime() + ".docx"; } else { processedResponse.Success = false; processedResponse.Errors = linkedInSocialMediaResponse.Errors; } } catch (Exception ex) { Log.Write(ex); processedResponse.Success = false; List <string> errors = new List <string>(); errors.Add(ex.Message); processedResponse.Errors = errors; } } else { processedResponse.Errors.Add("LinkedIn profile data is empty."); } return(processedResponse); }
// Interface method public SocialMediaProcessedResponse ProcessData(string code, string state, string indeedData) { Log.Write("ProcessData Seek ProcessData : ", ConfigurationPolicy.ErrorLog); SocialMediaProcessedResponse processedResponse = null; if (!code.IsNullOrEmpty()) { Log.Write("ProcessData Seek Condtion check true : ", ConfigurationPolicy.ErrorLog); processedResponse = new SocialMediaProcessedResponse(); try { var siteSettingsHelper = new SiteSettingsHelper(); // Fetaching Seek information from site settings var clientId = siteSettingsHelper.GetCurrentSiteSeekClientId(); var clientSecret = siteSettingsHelper.GetCurrentSiteSeekClientSecret(); var advertiserId = siteSettingsHelper.GetCurrentSiteSeekClientAdvertiserId(); var redirectUri = siteSettingsHelper.GetCurrentSiteSeekRedirectUri(); // Fill the seek request for the API call SeekSocialMediaRequest req = new SeekSocialMediaRequest(); req.AuthorisationCode = code; req.ClientId = clientId; req.ClientSecret = clientSecret; req.AdvertiserId = advertiserId; req.RedirectUri = redirectUri; req.JobTitle = "developer"; req.CountryCode = "61"; req.JobUrl = "http://localhost:60876/jobs"; req.PositionUrl = "dfdf"; req.PostalCode = "2145"; SeekSocialMediaService seekSocialMediaService = new SeekSocialMediaService(); if (Int32.TryParse(state, out int jobId)) { processedResponse.JobId = jobId; } // Seek API call var seekAPIResponse = seekSocialMediaService.ProcessSocialMediaIntegration <SeekSocialMediaResponse, SeekSocialMediaRequest>(req); #region Downloading the resume // Downloading the resume from seek if (seekAPIResponse.SocialMediaProcessSuccess && seekAPIResponse.SeekApplication.resume != null) { processedResponse.Success = true; processedResponse.Email = seekAPIResponse.SeekApplication.applicantInfo.emailAddress; processedResponse.FirstName = seekAPIResponse.SeekApplication.applicantInfo.firstName; processedResponse.LastName = seekAPIResponse.SeekApplication.applicantInfo.lastName; processedResponse.PhoneNumber = seekAPIResponse.SeekApplication.applicantInfo.phoneNumber; HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(seekAPIResponse.SeekApplication.resume.link); webReq.ContentType = "application/json"; webReq.Accept = "application/octet-stream"; webReq.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + seekAPIResponse.SeekApplication.OAuthToken); WebResponse webResponse = webReq.GetResponse(); string[] splits = webResponse.Headers["Content-Disposition"].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string resumeFileNameSplit = splits.Where(c => c.Contains("filename=")).FirstOrDefault(); string resumeFileName = resumeFileNameSplit.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries).Last(); MemoryStream fileStream = new MemoryStream(); byte[] fileBytes = GetStreamBytes(webResponse); fileStream = new MemoryStream(fileBytes); processedResponse.FileStream = fileStream; processedResponse.FileName = resumeFileName; } else { if (!seekAPIResponse.SocialMediaProcessSuccess) { processedResponse.Success = false; processedResponse.Errors = seekAPIResponse.Errors; } else { processedResponse.Success = false; processedResponse.ResumeLinkNotExists = true; processedResponse.Errors = new List <string>() { "Seek Resume Link is NULL" }; } } } #endregion catch (Exception ex) { processedResponse.Success = false; List <string> errors = new List <string>(); errors.Add(ex.Message); processedResponse.Errors = errors; } } return(processedResponse); }
// Interface method public SocialMediaProcessedResponse ProcessData(string data, string state, string indeedData) { Log.Write("ProcessData Indeed In : " + data, ConfigurationPolicy.ErrorLog); SocialMediaProcessedResponse processedResponse = null; if (data.IsNullOrEmpty() && !indeedData.IsNullOrEmpty()) { Log.Write("ProcessData Indeed Intial Condtion pass : "******"ProcessData Indeed entered try block : ", ConfigurationPolicy.ErrorLog); IndeedSocialMediaRequest indeedReq = new IndeedSocialMediaRequest(); indeedReq.IndeedApplicationJson = indeedData; IndeedSocialMediaService indeedSocialMediaService = new IndeedSocialMediaService(); // Indeed API call var indeedAPIResponse = indeedSocialMediaService.ProcessSocialMediaIntegration <IndeedSocialMediaResponse, IndeedSocialMediaRequest>(indeedReq); if (indeedAPIResponse.SocialMediaProcessSuccess) { Log.Write("ProcessData Indeed indeedAPIResponse.SocialMediaProcessSuccess : ", ConfigurationPolicy.ErrorLog); processedResponse.Success = true; processedResponse.Email = indeedAPIResponse.IndeedJobApplication.IndeedApplicant.Email; processedResponse.FirstName = indeedAPIResponse.IndeedJobApplication.IndeedApplicant.FullName?.Split(' ').FirstOrDefault(); processedResponse.LastName = indeedAPIResponse.IndeedJobApplication.IndeedApplicant.FullName?.Split(' ').LastOrDefault(); processedResponse.PhoneNumber = indeedAPIResponse.IndeedJobApplication.IndeedApplicant.PhoneNumber; processedResponse.FileStream = indeedAPIResponse.IndeedJobApplication.IndeedResume.data; processedResponse.FileName = indeedAPIResponse.IndeedJobApplication.IndeedResume.fileName; if (!string.IsNullOrEmpty(indeedAPIResponse.IndeedJobApplication.JXTNextJob.jobMeta)) { string[] metaData = indeedAPIResponse.IndeedJobApplication.JXTNextJob.jobMeta.Split(new char[] { ';' }); if (metaData.Count() > 1) { string email = metaData[1]; if (!string.IsNullOrEmpty(email)) { email = email.Trim(); Log.Write("ProcessData Indeed this.isValidEmail(email): " + this.isValidEmail(email), ConfigurationPolicy.ErrorLog); Log.Write("ProcessData Indeed email: " + email, ConfigurationPolicy.ErrorLog); processedResponse.LoginUserEmail = this.isValidEmail(email) ? email : null; processedResponse.LoginUserEmail = email; } } if (metaData.Count() > 2) { string source = metaData[2]; if (!string.IsNullOrEmpty(source)) { source = source.Trim(); Log.Write("ProcessData Indeed source: " + source, ConfigurationPolicy.ErrorLog); processedResponse.JobSource = source; } } } if (Int32.TryParse(indeedAPIResponse.IndeedJobApplication.JXTNextJob.jobId, out int jobId)) { Log.Write("ProcessData Indeed indeedAPIResponse.SocialMediaProcessSuccess job id is extracted : ", ConfigurationPolicy.ErrorLog); processedResponse.JobId = jobId; } } else { Log.Write("ProcessData Indeed indeedAPIResponse.SocialMediaProcessSuccess false: " + indeedAPIResponse.Errors.FirstOrDefault(), ConfigurationPolicy.ErrorLog); processedResponse.Success = false; processedResponse.Errors = indeedAPIResponse.Errors; } } catch (Exception ex) { Log.Write("ProcessData Indeed catch block : " + ex.Message, ConfigurationPolicy.ErrorLog); processedResponse.Success = false; List <string> errors = new List <string>(); errors.Add(ex.Message); processedResponse.Errors = errors; } } return(processedResponse); }
public ActionResult Index(string code, string state, int?JobId) { SocialMediaJobViewModel viewModel = new SocialMediaJobViewModel(); try { // Logging this info for Indeed test Log.Write("Social Handler Index Action Start : ", ConfigurationPolicy.ErrorLog); // This is the CSS classes enter from More Options ViewBag.CssClass = this.CssClass; if (string.IsNullOrWhiteSpace(this.TemplateName)) { this.TemplateName = "SocialHandler.Simple"; } viewModel.Status = JobApplicationStatus.Available; if (_socialHandlerLogics != null) { Log.Write("_socialHandlerLogics not null", ConfigurationPolicy.ErrorLog); if (Request.InputStream != null) { Request.InputStream.Position = 0; } StreamReader reader = new StreamReader(Request.InputStream); string indeedJsonStringData = String.Empty; string indeedJsonStringData2 = null; if (reader != null) { indeedJsonStringData = reader.ReadToEnd(); } using (StreamReader reader2 = new StreamReader(Request.InputStream, Encoding.UTF8)) { indeedJsonStringData2 = reader.ReadToEnd(); } SocialMediaProcessedResponse result = null; if (!code.IsNullOrEmpty()) { result = _processSocialMediaSeekData.ProcessData(code, state, indeedJsonStringData); if (TempData["source"] != null && !string.IsNullOrWhiteSpace(TempData["source"].ToString())) { result.UrlReferral = TempData["source"].ToString(); } } else if (code.IsNullOrEmpty() && !indeedJsonStringData.IsNullOrEmpty()) { result = _processSocialMediaIndeedData.ProcessData(code, state, indeedJsonStringData); result.UrlReferral = result.JobSource; } else { Log.Write("Social Handler code,sate and indeed data is null", ConfigurationPolicy.ErrorLog); } var jobDetails = GetJobDetails(result.JobId.Value); //var result = _socialHandlerLogics.ProcessSocialHandlerData(code, state, indeedJsonStringData); if (result != null && result.ResumeLinkNotExists) { if (!jobDetails.JobSEOUrl.IsNullOrEmpty()) { return(Redirect(string.Format("job-application/{0}/{1}?error=resume", jobDetails.JobSEOUrl, int.Parse(state)))); } else { return(Redirect(string.Format("job-application/{0}?error=resume", int.Parse(state)))); } } if (result != null && result.Success == true && result.JobId.HasValue) { JobApplicationStatus status = JobApplicationStatus.Available; if (_jobApplicationService != null) { ApplicantInfo applicantInfo = new ApplicantInfo() { FirstName = result.FirstName, LastName = result.LastName, Email = result.Email, Password = "******", PhoneNumber = result.PhoneNumber, IsNewUser = false }; string overrideEmail = string.Empty; if (SitefinityHelper.IsUserLoggedIn()) { var currUser = SitefinityHelper.GetUserById(ClaimsManager.GetCurrentIdentity().UserId); if (currUser != null) { Log.Write("User is already logged In " + currUser.Email, ConfigurationPolicy.ErrorLog); overrideEmail = currUser.Email; } else { Log.Write("CurUser is null", ConfigurationPolicy.ErrorLog); overrideEmail = _jobApplicationService.GetOverrideEmail(ref status, ref applicantInfo, true); } Log.Write("SitefinityHelper.IsUserLoggedIn() =" + SitefinityHelper.IsUserLoggedIn(), ConfigurationPolicy.ErrorLog); } else if (!string.IsNullOrEmpty(result.LoginUserEmail)) { overrideEmail = result.LoginUserEmail; } else { Log.Write("SitefinityHelper.IsUserLoggedIn() is false ", ConfigurationPolicy.ErrorLog); overrideEmail = _jobApplicationService.GetOverrideEmail(ref status, ref applicantInfo, true); } Log.Write("overrideEmail is : " + overrideEmail, ConfigurationPolicy.ErrorLog); if (overrideEmail != null && status == JobApplicationStatus.Available) { Log.Write("overrideEmail is in: ", ConfigurationPolicy.ErrorLog); //Create Application var response = CreateJobApplication(result, jobDetails, applicantInfo, overrideEmail); if (response.MemberApplicationResponse.Success && response.MemberApplicationResponse.ApplicationID.HasValue) { if (!response.FilesUploaded) { viewModel.Status = response.Status; // Unable to attach files viewModel.Message = response.Message; } else { viewModel.Status = response.Status; viewModel.Message = response.Message; if (!this.JobApplicationSuccessPageId.IsNullOrEmpty()) { Log.Write("JobApplicationSuccessPageId is not null: ", ConfigurationPolicy.ErrorLog); var successPageUrl = SitefinityHelper.GetPageUrl(this.JobApplicationSuccessPageId); Log.Write("successPageUrl : " + successPageUrl, ConfigurationPolicy.ErrorLog); return(Redirect(successPageUrl)); } } } else { if (viewModel.Status == JobApplicationStatus.Already_Applied) { if (!jobDetails.JobSEOUrl.IsNullOrEmpty()) { return(Redirect(string.Format("job-application/{0}/{1}?error=exists", jobDetails.JobSEOUrl, result.JobId.Value))); } else { return(Redirect(string.Format("job-application/{0}?error=exists", result.JobId.Value))); } } viewModel.Status = response.Status; viewModel.Message = response.Message; } } else { Log.Write("overrideEmail is null: ", ConfigurationPolicy.ErrorLog); if (status == JobApplicationStatus.NotAbleToLoginCreatedUser) { viewModel.Message = "Unable to process your job application. Please try logging in and re-apply for the job."; } else if (status == JobApplicationStatus.NotAbleToCreateUser) { viewModel.Message = "Unable to create user. Please register from"; } viewModel.Status = status; } } else { Log.Write("_jobApplicationService is null", ConfigurationPolicy.ErrorLog); } } } } catch (Exception ex) { Log.Write("Social Handler : Exception Caught" + ex.Message, ConfigurationPolicy.ErrorLog); } // To catch access denied error for seek int jobId; if (!string.IsNullOrEmpty(this.Request.QueryString["error"]) && this.Request.QueryString["error"].ToLower().Contains("denied") && state != null && int.TryParse(state, out jobId)) { var jobDetails = GetJobDetails(jobId); if (!jobDetails.JobSEOUrl.IsNullOrEmpty()) { return(Redirect(string.Format("job-application/{0}/{1}?error=denied", jobDetails.JobSEOUrl, jobId))); } else { return(Redirect(string.Format("job-application/{0}?error=resume", jobId))); } } if (!this.JobSearchResultsPageId.IsNullOrEmpty()) { ViewBag.JobSearchResultsUrl = SitefinityHelper.GetPageUrl(this.JobSearchResultsPageId); } var fullTemplateName = this.templateNamePrefix + this.TemplateName; return(View(fullTemplateName, viewModel)); }
private CreateJobApplicationResponse CreateJobApplication( SocialMediaProcessedResponse result, JobDetailsModel jobDetails, ApplicantInfo applicantInfo, string overrideEmail) { // Gather Attachments Guid identifier = Guid.NewGuid(); JobApplicationAttachmentUploadItem uploadItem = new JobApplicationAttachmentUploadItem() { Id = identifier.ToString(), AttachmentType = JobApplicationAttachmentType.Resume, FileName = result.FileName, FileStream = result.FileStream, PathToAttachment = identifier.ToString() + "_" + result.FileName, Status = "Ready" }; // End code for fetch job details Log.Write("overrideEmail uploadItem object created", ConfigurationPolicy.ErrorLog); List <JobApplicationAttachmentUploadItem> attachments = new List <JobApplicationAttachmentUploadItem>(); attachments.Add(uploadItem); Log.Write("overrideEmail uploadItem attachment added", ConfigurationPolicy.ErrorLog); string resumeAttachmentPath = JobApplicationAttachmentUploadItem.GetAttachmentPath(attachments, JobApplicationAttachmentType.Resume); Log.Write("After resume GetAttachmentPath", ConfigurationPolicy.ErrorLog); string coverletterAttachmentPath = JobApplicationAttachmentUploadItem.GetAttachmentPath(attachments, JobApplicationAttachmentType.Coverletter); Log.Write("After cover letter GetAttachmentPath", ConfigurationPolicy.ErrorLog); string htmlEmailContent = this.GetEmailHtmlContent(this.EmailTemplateId); string htmlEmailSubject = this.GetEmailSubject(this.EmailTemplateId); string htmlAdvertiserEmailContent = this.GetEmailHtmlContent(this.AdvertiserEmailTemplateId); string htmlAdvertiserEmailSubject = this.GetEmailSubject(this.AdvertiserEmailTemplateId); Log.Write("After GetHtmlEmailContent", ConfigurationPolicy.ErrorLog); // Email notification settings List <dynamic> emailAttachments = new List <dynamic>(); foreach (var item in attachments) { dynamic emailAttachment = new ExpandoObject(); emailAttachment.FileStream = item.FileStream; emailAttachment.FileName = item.FileName; emailAttachments.Add(emailAttachment); } EmailNotificationSettings advertiserEmailNotificationSettings = (this.AdvertiserEmailTemplateId != null) ? _createAdvertiserEmailTemplate( new JobApplicationEmailTemplateModel() { FromFirstName = result.FirstName, FromLastName = result.LastName, FromEmail = overrideEmail, ToFirstName = jobDetails.ContactDetails.GetFirstName(), ToLastName = jobDetails.ContactDetails.GetLastName(), ToEmail = jobDetails.ApplicationEmail, Subject = SitefinityHelper.GetCurrentSiteEmailTemplateTitle(this.AdvertiserEmailTemplateId), HtmlContent = SitefinityHelper.GetCurrentSiteEmailTemplateHtmlContent(this.AdvertiserEmailTemplateId), Attachments = emailAttachments }) : null; EmailNotificationSettings emailNotificationSettings = (this.EmailTemplateId != null) ? _createApplicantEmailTemplate( new JobApplicationEmailTemplateModel() { FromFirstName = this.EmailTemplateSenderName, FromLastName = null, FromEmail = this.EmailTemplateSenderEmailAddress, ToFirstName = SitefinityHelper.GetUserFirstNameById(SitefinityHelper.GetUserByEmail(overrideEmail).Id), ToLastName = null, ToEmail = overrideEmail, Subject = SitefinityHelper.GetCurrentSiteEmailTemplateTitle(this.EmailTemplateId), HtmlContent = SitefinityHelper.GetCurrentSiteEmailTemplateHtmlContent(this.EmailTemplateId), Attachments = null }) : null; EmailNotificationSettings registrationNotificationsSettings = (applicantInfo.IsNewUser && this.RegistrationEmailTemplateId != null) ? _createRegistrationEmailTemplate( new JobApplicationEmailTemplateModel() { FromFirstName = this.EmailTemplateSenderName, FromLastName = null, FromEmail = this.EmailTemplateSenderEmailAddress, ToFirstName = applicantInfo.FirstName, ToLastName = null, ToEmail = applicantInfo.Email, Subject = SitefinityHelper.GetCurrentSiteEmailTemplateTitle(this.RegistrationEmailTemplateId), HtmlContent = SitefinityHelper.GetCurrentSiteEmailTemplateHtmlContent(this.RegistrationEmailTemplateId), Attachments = null }) : null; Log.Write("emailNotificationSettings after: ", ConfigurationPolicy.ErrorLog); Log.Write("BL response before: ", ConfigurationPolicy.ErrorLog); //Create Application var response = _blConnector.MemberCreateJobApplication( new JXTNext_MemberApplicationRequest { ApplyResourceID = result.JobId.Value, MemberID = 2, ResumePath = resumeAttachmentPath, CoverletterPath = coverletterAttachmentPath, EmailNotification = emailNotificationSettings, AdvertiserEmailNotification = advertiserEmailNotificationSettings, AdvertiserName = jobDetails.ContactDetails, CompanyName = jobDetails.CompanyName, UrlReferral = result.UrlReferral, RegistrationEmailNotification = registrationNotificationsSettings }, overrideEmail); Log.Write("BL response after: ", ConfigurationPolicy.ErrorLog); var createJobApplicationResponse = new CreateJobApplicationResponse { MemberApplicationResponse = response }; if (response.Success && response.ApplicationID.HasValue) { Log.Write("BL response in: ", ConfigurationPolicy.ErrorLog); var hasFailedUpload = _jobApplicationService.UploadFiles(attachments); Log.Write("file upload is : " + hasFailedUpload, ConfigurationPolicy.ErrorLog); if (hasFailedUpload) { createJobApplicationResponse.FilesUploaded = false; createJobApplicationResponse.Status = JobApplicationStatus.Technical_Issue; // Unable to attach files createJobApplicationResponse.Message = "Unable to attach files to application"; } else { createJobApplicationResponse.FilesUploaded = true; createJobApplicationResponse.Status = JobApplicationStatus.Applied_Successful; createJobApplicationResponse.Message = "Your application was successfully processed."; } } else { if (response.Errors.FirstOrDefault().ToLower().Contains("already exists")) { createJobApplicationResponse.Status = JobApplicationStatus.Already_Applied; createJobApplicationResponse.Message = "You have already applied to this job."; } else { createJobApplicationResponse.Status = JobApplicationStatus.Technical_Issue; createJobApplicationResponse.Message = response.Errors.FirstOrDefault(); } } return(createJobApplicationResponse); }