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));
        }
        public ActionResult LinkedInApply(int jobId, string profileJson)
        {
            var response = new LinkedInApplyResponse();

            // user must be logged in to apply for a job
            if (!SitefinityHelper.IsUserLoggedIn())
            {
                response.Errors.Add("You must be logged in to apply for a job.");

                return(Json(response));
            }

            // check whether requested job exist or not
            var jobDetails = GetJobDetails(jobId);

            if (jobDetails == null)
            {
                response.Errors.Add("Job does not exist.");

                return(Json(response));
            }

            // process the submitted LinkedIn data
            var processLinkedInData = new ProcessLinkedInData();
            var result = processLinkedInData.ProcessData(null, null, profileJson);

            if (result == null || !result.Success)
            {
                response.Errors = result.Errors;

                return(Json(response));
            }

            result.JobId = jobId;
            if (TempData["Urlreferal"] != null)
            {
                result.UrlReferral = TempData["Urlreferal"].ToString();
            }


            var viewModel = new SocialMediaJobViewModel
            {
                Status = JobApplicationStatus.Available
            };

            ApplicantInfo applicantInfo = new ApplicantInfo()
            {
                FirstName   = result.FirstName,
                LastName    = result.LastName,
                Email       = result.Email,
                PhoneNumber = result.PhoneNumber,
                IsNewUser   = false
            };

            // create the job application and redirect to success page if possible
            var applicationResponse = CreateJobApplication(result, jobDetails, applicantInfo, result.Email);

            if (applicationResponse.Status == JobApplicationStatus.Applied_Successful)
            {
                response.Success = true;
                response.Messages.Add(applicationResponse.Message);

                if (!string.IsNullOrEmpty(this.JobApplicationSuccessPageId))
                {
                    response.RedirectUrl = SitefinityHelper.GetPageUrl(this.JobApplicationSuccessPageId);
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(applicationResponse.Message))
                {
                    response.Errors.Add("An unexpected error occurred while processing your request. Please try again.");
                }
                else
                {
                    response.Errors.Add(applicationResponse.Message);
                }
            }

            return(Json(response));
        }