コード例 #1
0
        private async Task LoadAsync(ApplicationUser user, BinderModel binderModel)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            binderModel.Username = userName;
            if (((Candidate)user).CV != null)
            {
                binderModel.CV = ((Candidate)user).CV.Title;
            }
            else
            {
                binderModel.CV = null;
            }
            binderModel.Input = ((Candidate)user).Educations;
        }
コード例 #2
0
        // GET: Admin/JobPosts/Delete/5
        public async Task <IActionResult> Apply(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var jobPost = await _context.JobPosts
                          .Include(j => j.Department)
                          .FirstOrDefaultAsync(m => m.Id == id);

            if (jobPost == null || jobPost.Status == JobPostStatus.Closed)
            {
                return(NotFound());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (((Candidate)user).JobApplications.Any(J => J.JobPostId == jobPost.Id))
            {
                TempData["AppMessage"] = "You have already applied.";
                return(RedirectToAction(nameof(Details), new { id = jobPost.Id }));
            }


            BinderModel binderModel = new BinderModel();

            binderModel.PrefDateToJoin = null;
            await LoadAsync(user, binderModel);



            return(View(binderModel));
        }
コード例 #3
0
 public void Post([FromForm] BinderModel value)
 {
 }
コード例 #4
0
        public async Task <IActionResult> Apply(int id, [Bind("PrefDateToJoin,FormFile")] BinderModel binderModel, ICollection <Education> Input)
        {
            var jobPost = await _context.JobPosts.FindAsync(id);

            if (jobPost == null || jobPost.Status == JobPostStatus.Closed)
            {
                return(NotFound());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (((Candidate)user).JobApplications.Any(J => J.JobPostId == jobPost.Id))
            {
                TempData["AppMessage"] = "You have already applied.";
                return(RedirectToAction(nameof(Details), new { id = jobPost.Id }));
            }



            bool cvUploaded = (binderModel.FormFile != null);

            if (!cvUploaded && ((Candidate)user).CV == null)
            {
                //binderModel.StatusMessage = "You must provide cv to apply.";
                ModelState.AddModelError("CV", "You must provide cv to apply.");
                binderModel = new BinderModel();
                await LoadAsync(user, binderModel);

                //TempData["StatusMessage"] = "You must provide cv to apply.";
                return(View(binderModel));
            }
            byte[] Content = new byte[0];

            if (cvUploaded)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await binderModel.FormFile.CopyToAsync(memoryStream);

                    // Upload the file if less than 2 MB
                    if (memoryStream.Length < 2097152 * 4)
                    {
                        Content = memoryStream.ToArray();
                    }
                    else
                    {
                        ModelState.AddModelError("File", "The file is too large.");
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                binderModel = new BinderModel();
                await LoadAsync(user, binderModel);

                return(View(binderModel));
            }

            var cnt = ((Candidate)user).Educations.Count;

            ((Candidate)user).Educations = Input;

            if (cvUploaded)
            {
                CV cv = new CV();
                cv.Title     = binderModel.FormFile.FileName;
                cv.Content   = Content;
                cv.Extension = Path.GetExtension(binderModel.FormFile.FileName);
                if (cv.Extension.Length > 20)
                {
                    cv.Extension = "unknown";
                }
                ((Candidate)user).CV = cv;
            }

            var updt = await _userManager.UpdateAsync(user);

            if (!updt.Succeeded)
            {
                TempData["AppMessage"] = "Unexpected error when trying to update educations.";
                //binderModel.StatusMessage = "Unexpected error when trying to update educations.";
                return(RedirectToAction());
            }


            var newApp = new JobApplication()
            {
                JobPostId      = jobPost.Id,
                CandidateId    = user.Id,
                CV             = ((Candidate)user).CV,
                AppStatus      = AppStatus.AppReceived,
                PrefDateToJoin = (DateTime)binderModel.PrefDateToJoin,
                AppDate        = DateTime.Now
            };

            _context.Add(newApp);
            await _context.SaveChangesAsync();

            TempData["AppMessage"] = "We Have Received Your Application.";
            return(RedirectToAction(nameof(Details), new { id = jobPost.Id }));
        }