Beispiel #1
0
        public async Task <IActionResult> JobApply(Guid jobId)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var result = await _service.ApplyForJob(jobId, userId);

            if (result == null)
            {
                return(View(result));
            }
            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// This action represents the applying for a job functionaity.
        /// If the user has already applied for the requested job,
        /// he is prompted that he has already applied and nothing happens.
        /// If the user is not logged in yet and tries to apply for a job, he is
        /// redirected to the log in page where he can log in and then apply for the desired job.
        /// Otherwise (if the user has logged in and wants to apply for a job he has not already applied for),
        /// the job application is successfull and that job is put in the ViewData
        /// Depending on the outcome of the 'ApplyForJob' method inside the Jobs service
        /// the ViewBag message is different.
        /// The ViewBag message, alongside with the View data, is passed into the ViewJob view
        /// </summary>
        /// <param name="id">The id of the job the user wants to apply for</param>
        /// <returns>The ViewJob view where the user can view the job in more detail (so in fact - he stays in the same view)</returns>
        public IActionResult ApplyForJob(int id)
        {
            ViewBag.Message = "Successfully applied for job.";
            if (JobsService.ApplyForJob(id) == -1)
            {
                ViewBag.Message = "You have already applied for this job.";
            }
            else if (JobsService.ApplyForJob(id) == -2)
            {
                ViewBag.Message = "You can't apply for a job you have created.";
            }
            else if (JobsService.ApplyForJob(id) == 0)
            {
                return(RedirectToAction("Login", "User"));
            }

            ViewData["Job"] = JobsService.ViewJob(id);
            CheckLoggedUser();
            return(View("ViewJob"));
        }
 public IActionResult ApplyForJob(string jobId)
 {
     try
     {
         var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         _jobService.ApplyForJob(userId, jobId);
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message);
         _logger.LogError(e.StackTrace);
         return(View("Error", new ErrorViewModel()
         {
             RequestId = e.Message
         }));
     }
 }