Exemple #1
0
        public List <ApplicantJobs> getJobsApplied()
        {
            List <ApplicantJobs> pocos = new List <ApplicantJobs>();

            using (SqlConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand
                {
                    Connection  = _connection,
                    CommandText = @"select cd.Company_Name, aja.Application_Date, cjd.Job_Name, cjd.Job_Descriptions
                                    from Applicant_Job_Applications aja
                                    join Company_Jobs_Descriptions cjd on aja.Job = cjd.Job
                                    join Company_Jobs cj on cjd.Job = cj.Id
                                    join Company_Descriptions cd on cj.Company = cd.Company
                                    where aja.Applicant = '" + System.Web.HttpContext.Current.Session["ApplicantProfileId"].ToString() + "';"
                };

                _connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ApplicantJobs poco = new ApplicantJobs
                    {
                        CompanyName     = reader.GetString(0),
                        ApplicationDate = reader.GetDateTime(1),
                        JobName         = reader.GetString(2),
                        JobDescription  = reader.GetString(3)
                    };

                    pocos.Add(poco);
                }
                _connection.Close();
            }
            return(pocos);
        }
        public ActionResult ApplyForJob(int?id)
        {
            ApplicationUser user = GetUser();

            if (user == null)
            {
                TempData["CurrentUrl"] = Request.Url.ToString();
                Session["url"]         = TempData["CurrentUrl"].ToString();
                return(RedirectToAction("Login", "Account"));
            }
            Guid userId    = new Guid(User.Identity.GetUserId());
            var  applicant = jobService.GetApplicant(userId);

            if (applicant == null)
            {
                TempData["CurrentUrl"] = Request.Url.ToString();
                Session["url"]         = TempData["CurrentUrl"].ToString();
                return(RedirectToAction("Index", "Applicant", new { returnUrl = Request.Url.ToString() }));
            }
            else
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                Job job = jobService.GetById((int)id);
                if (job == null)
                {
                    return(HttpNotFound());
                }
                if (job.Active == false)
                {
                    return(RedirectToAction("JobNoLongerActive"));
                }

                if (job.ClosedDate < DateTime.Now)
                {
                    return(RedirectToAction("JobClosed"));
                }

                if (job.Active && job.ClosedDate > DateTime.Now)
                {
                    List <ApplicantJobs> jobs = jobService.GetApplicantJobs(applicant.Id).ToList();
                    foreach (var item in jobs)
                    {
                        if (item.JobId == id)
                        {
                            return(RedirectToAction("JobAlreadyAppliedTo"));
                        }
                    }
                    ApplicantJobs appJob = new ApplicantJobs();
                    appJob.ApplicantId = applicant.Id;
                    appJob.JobId       = (int)id;
                    Session["url"]     = null;
                    return(RedirectToAction("Apply", "Jobs", job));
                }
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult SubmitJobApplication(Job job)
        {
            Guid userId = new Guid(User.Identity.GetUserId());

            //Checking to see if the user is already in the database
            //Applicant applicant = db.Applicants.Where(a => a.RegisterId == userId).FirstOrDefault();
            Applicant     applicant = jobService.GetApplicant(userId);
            ApplicantJobs appJob    = jobService.SubmitJobApplication(job, applicant);

            jobService.SendConfirmationEmail(userId, applicant, appJob);
            Session["url"] = null;
            // send them to a confirmation page then redirect them to the index page
            return(View("JobAppliedToConfirmation", job));
        }