public async Task <ActionResult> Index(string type)
        {
            var applicant = await GetApplicant();

            if (applicant != null)
            {
                foreach (var key in Request.Files.AllKeys)
                {
                    var file = Request.Files[key];
                    if (file != null)
                    {
                        if (_updateApplicantFileService.CheckFile(file, type) != UpdateApplicantFileService.CheckFileResult.Ok)
                        {
                            if (type.Is("CV"))
                            {
                                ModelState.AddModelError("Documents", @"Error-Cv");
                            }
                            else if (type.Is("Photo"))
                            {
                                ModelState.AddModelError("Documents", @"Error-Photo");
                            }
                            else
                            {
                                ModelState.AddModelError("Documents", @"Error-Documents");
                            }
                        }

                        if (!ModelState.IsValid)
                        {
                            var documents = await new ApplicantDocumentsGetRequest(applicant.Id).LoadResult(ApiClient);
                            return(View(new IndexViewModel(await GetMandator(), documents)));
                        }


                        if (type.Is("CV"))
                        {
                            await _updateApplicantFileService.AddCv(ApiClient, applicant, file);
                        }
                        else if (type.Is("Photo"))
                        {
                            await _updateApplicantFileService.AddPhoto(ApiClient, applicant, file);
                        }
                        else
                        {
                            await _updateApplicantFileService.AddFile(ApiClient, applicant, file, type);
                        }
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Example #2
0
        public async Task <ActionResult> Register(int?job, RegisterViewModel model)
        {
            var mandator = await GetMandator();

            model.Prepare(mandator, job.HasValue ? await GetJob(mandator, _jobsService, job.Value) : null);

            if (model.Cv != null && _updateApplicantFileService.CheckFile(model.Cv, "Cv") != UpdateApplicantFileService.CheckFileResult.Ok)
            {
                ModelState.AddModelError("Cv", @"Error-Cv");
            }
            if (model.Photo != null && _updateApplicantFileService.CheckFile(model.Photo, "Photo") != UpdateApplicantFileService.CheckFileResult.Ok)
            {
                ModelState.AddModelError("Photo", @"Error-Photo");
            }
            if (model.Documents != null)
            {
                var index = 0;
                foreach (var document in model.Documents)
                {
                    if (document != null && _updateApplicantFileService.CheckFile(document, model.DocumentTypes.ElementAt(index)) != UpdateApplicantFileService.CheckFileResult.Ok)
                    {
                        ModelState.AddModelError("Documents", @"Error-Documents");
                        break;
                    }
                    index++;
                }
            }

            if (ModelState.IsValid)
            {
                //check if the email is not in use already
                if (!mandator.PortalSettings.AllowDuplicateEmail)
                {
                    var applicantsWithThisEmail = await new ApplicantsRequest(model.Email).LoadResult(ApiClient);
                    if (applicantsWithThisEmail.Any())
                    {
                        return(RedirectToAction("EmailAlreadyInUse", "Account", new { job, email = model.Email }));
                    }
                }

                //create the applicant
                var createParameter = new ApplicantParameter
                {
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Gender    = model.Gender
                };
                var applicant = await new ApplicantPutRequest(createParameter).LoadResult(ApiClient);

                //update the personal information
                applicant = await _updateApplicantService.UpdatePersonalInformation(ApiClient, applicant, model);

                //save the documents
                if (model.Cv != null)
                {
                    await _updateApplicantFileService.AddCv(ApiClient, applicant, model.Cv);
                }
                if (model.Photo != null)
                {
                    await _updateApplicantFileService.AddPhoto(ApiClient, applicant, model.Photo);
                }
                if (model.Documents != null)
                {
                    var index = 0;
                    foreach (var document in model.Documents)
                    {
                        if (document != null)
                        {
                            await _updateApplicantFileService.AddFile(ApiClient, applicant, document, model.DocumentTypes.ElementAt(index));
                        }
                        index++;
                    }
                }

                //log the applicant in and redirect either to the applicant profile or the application page
                FormsAuthentication.SetAuthCookie(applicant.Id.ToString(CultureInfo.InvariantCulture), false);
                if (job.HasValue)
                {
                    return(RedirectToAction("Index", "Application", new { job }));
                }
                return(RedirectToAction("RegisterSuccess"));
            }
            return(View(model));
        }