public async Task <ActionResult> Apply(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Job job = await bll.GetJobById(id.Value); if (job == null) { return(HttpNotFound()); } //check if the user has already applied var jobSeekerUser = (JobSeekerUser)(await UserManager.FindByIdAsync(User.Identity.GetUserId())); using (JobSeekerBLL jsbll = new BLL.JobSeekerBLL()) { var application = await jsbll.GetApplication(jobSeekerUser.JobSeekerID.Value, job.ID); if (application == null) { return(View(job)); } } //todo how to tell the user that he has already applied. return(RedirectToAction("Index")); //todo any qualifcation checks(like is the job invitationonly //does the user have enough experience for application set by the company, etc.) //needed for a user to apply should be done here }
//GET: CompanyProfile/Invite public async Task <ActionResult> Invite(int?jobID, int?jobSeekerID, bool?cancel) { //abort inviting hence clear data if (cancel == true) { Session["JobID"] = Session["JobSeekerID"] = null; return(RedirectToAction("Invitations")); } //if jobID or jobSeekerID is not null save it in session or update the existing one in session(i.e update when both have value) if (jobID != null) { Session["JobID"] = jobID; } if (jobSeekerID != null) { Session["JobSeekerID"] = jobSeekerID; } //when both are null if ((jobID == null) && (Session["JobID"] == null)) { return(RedirectToAction("Jobs")); } //same as above if ((jobSeekerID == null) && (Session["JobSeekerID"] == null)) { return(RedirectToAction("Index", "JobSeekers")); } var companyUser = (CompanyUser)(await UserManager.FindByIdAsync(User.Identity.GetUserId())); //assigning stored value from previous request with jobID or jobSeekerID or the same request //so that these variables can be used intead of session object //can be removed but the invitaion object must be initialized with the data from session if removed //and the queries must also be changed to corresponding session object jobID = (int)Session["JobID"]; jobSeekerID = (int)Session["JobSeekerID"]; //checking if the person is already invited to the job Invitation invitation = await bll.GetInvitationAsync(jobID.Value, jobSeekerID.Value); if (invitation == null) { var job = await bll.GetJob(companyUser.CompanyID.Value, jobID.Value); JobSeeker jobSeeker = null; using (JobSeekerBLL jsbll = new BLL.JobSeekerBLL()) jobSeeker = await jsbll.GetJobSeekerById(jobSeekerID.Value); //if job or jobseeker does not exist if (job == null || jobSeeker == null) { return(HttpNotFound()); } else { invitation = new Invitation() { JobID = jobID.Value, JobSeekerID = jobSeekerID.Value, Job = job, JobSeeker = jobSeeker }; return(View(invitation)); } } else { //todo tell company user that the job seeeker is already invited to the job //clear session data since already invited Session["JobID"] = Session["JobSeekerID"] = null; return(RedirectToAction("Invitations")); } }