Beispiel #1
0
        /// <summary>
        /// Displays a view with form to create new job applictation.
        /// </summary>
        /// <param name="jobOfferId"></param>
        /// <returns></returns>
        public async Task <ActionResult> Create(int?jobOfferId)
        {
            if (!jobOfferId.HasValue)
            {
                return(BadRequest($"jobOfferId cannot be null"));
            }
            var model = new CreateJobApplicationViewModel();
            var title = await _context.JobOffers.Where(x => x.Id == jobOfferId).Select(x => x.Title).FirstOrDefaultAsync();

            if (title == null)
            {
                return(NotFound($"offer not found in DB"));
            }

            var user = await _context.Users.FirstOrDefaultAsync(x => x.ProviderUserId == User.FindFirst(ClaimTypes.NameIdentifier).Value);

            model.JobTitle   = title;
            model.JobOfferId = jobOfferId.Value;
            //Pre-fill the form with data from users Database
            model.FirstName    = user.FirstName;
            model.EmailAddress = user.EmailAddress;
            model.LastName     = user.LastName;

            return(View(model));
        }
Beispiel #2
0
        public async Task <ActionResult> Create(CreateJobApplicationViewModel model)
        {
            if (!ModelState.IsValid || model.UploadedCVFile == null)
            {
                var title = await _context.JobOffers.Where(x => x.Id == model.JobOfferId).Select(x => x.Title).FirstOrDefaultAsync();

                if (title == null)
                {
                    return(NotFound($"offer not found in DB"));
                }
                model.JobTitle = title;
                return(View(model));
            }

            var user = await _context.Users.FirstOrDefaultAsync(x => x.ProviderUserId == User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (user == null)
            {
                return(NotFound($"user not found"));
            }

            var offer = await _context.JobOffers.FirstOrDefaultAsync(x => x.Id == model.JobOfferId);

            if (offer == null)
            {
                return(NotFound($"offer not found in DB"));
            }

            string trustedName = user.ProviderUserId + DateTime.Now.ToFileTime() + ".pdf";

            // Upload CV to AzureBlob

            UploadCV(model.UploadedCVFile, trustedName);
            JobApplication jobApplication = new JobApplication
            {
                FirstName        = model.FirstName,
                LastName         = model.LastName,
                EmailAddress     = model.EmailAddress,
                PhoneNumber      = model.PhoneNumber,
                JobOfferId       = model.JobOfferId,
                ContactAgreement = model.ContactAgreement,
                CreatedOn        = DateTime.Now,
                ApplicationState = ApplicationState.Waiting,
                UserId           = user.Id,
                User             = user,
                CvUrl            = trustedName
            };

            offer.JobApplications.Add(jobApplication);
            await _context.JobApplications.AddAsync(jobApplication);

            await _context.SaveChangesAsync();

            // Send notification emails using SendGrid
            SendNotifications(offer.CompanyId);

            return(RedirectToAction("Details", "JobOffer", new { id = model.JobOfferId, Area = "User" }));
        }