コード例 #1
0
        public async Task <ActionResult> Create(NewCandidateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                //log
                ViewBag.Skills = await _skillService.LoadSkillsAsync();  //TODO : avoid it by using presentator on the view

                return(View());
            }
            try
            {
                await _candidateService.SaveCandidateAsync(
                    new Core.Entities.Candidate
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                },
                    model.SkillIds
                    );

                return(RedirectToAction(nameof(CreateSuccess), model));
            }
            catch (Exception ex)
            {
                //add log exception
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Create(NewCandidateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newCandidate = new Candidate
                {
                    Source          = vm.Source,
                    Qualification   = vm.Qualification,
                    TotalExperience = vm.TotalExperience,
                    ResumePath      = vm.ResumePath,
                    PhotoPath       = vm.PhotoPath,
                    Status          = vm.Status,
                    Comments        = vm.Comments,
                    CurrentCTC      = vm.CurrentCTC,
                    ExpectedCTC     = vm.ExpectedCTC,
                    Person          = vm.Person,
                    DesignationId   = vm.CandidateDesignationId
                };


                // Clean up white spaces for Email and Phone Numbers
                if (!string.IsNullOrEmpty(newCandidate.Person.Email))
                {
                    newCandidate.Person.Email = newCandidate.Person.Email.Trim();
                }

                if (!string.IsNullOrEmpty(newCandidate.Person.SecondaryEmail))
                {
                    newCandidate.Person.SecondaryEmail = newCandidate.Person.SecondaryEmail.Trim();
                }

                if (!string.IsNullOrEmpty(newCandidate.Person.PhoneNo))
                {
                    newCandidate.Person.PhoneNo = newCandidate.Person.PhoneNo.Trim();
                }

                if (!string.IsNullOrEmpty(newCandidate.Person.OfficePhone))
                {
                    newCandidate.Person.OfficePhone = newCandidate.Person.OfficePhone.Trim();
                }

                newCandidate.RecievedOn = vm.RecievedOn;

                newCandidate.CreatedByUserId = WebUser.Id;

                _candidateRepository.Create(newCandidate);
                _unitOfWork.Commit();

                // Update the Candidate Code.
                var selectedCandidate = _candidateRepository.Get(newCandidate.Id);
                if (selectedCandidate != null)
                {
                    selectedCandidate.Code = $"LA{selectedCandidate.Id.ToString("D" + 6)}";
                    _candidateRepository.Update(selectedCandidate);
                    _unitOfWork.Commit();
                }

                // Map the Technologies
                if (vm.TechnologyIds != null)
                {
                    foreach (var technologyId in vm.TechnologyIds)
                    {
                        var newMap = new CandidateTechnologyMap
                        {
                            CandidateId  = newCandidate.Id,
                            TechnologyId = technologyId
                        };

                        _candidateTechnologyMapRepository.Create(newMap);
                    }

                    _unitOfWork.Commit();
                }

                // Add the resume and map it to docs.
                if (vm.Resume != null)
                {
                    var newDocument = new CandidateDocument
                    {
                        CandidateId  = newCandidate.Id,
                        DocumentType = CandidateDocumentType.Resume
                    };

                    var siteSettings      = _settingsService.GetSiteSettings();
                    var blobUploadService = new BlobUploadService(siteSettings.BlobSettings);
                    var blobPath          = blobUploadService.UploadRecruitDocument(vm.Resume);
                    newDocument.DocumentPath = blobPath;
                    newDocument.FileName     = vm.Resume.FileName;

                    _candidateDocumentRepository.Create(newDocument);
                    _unitOfWork.Commit();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CandidateDesignationId = new SelectList(_candidateDesignationRepository.GetAll(), "Id", "Title");
            return(View(vm));
        }