public ActionResult Create(CandidateDocumentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newDocument = new CandidateDocument
                {
                    CandidateId  = vm.CandidateId,
                    DocumentType = vm.DocumentType,
                    FileSize     = 0.0
                };

                if (vm.Document != null)
                {
                    var siteSettings      = _settingsService.GetSiteSettings();
                    var blobUploadService = new BlobUploadService(siteSettings.BlobSettings);
                    var blobPath          = blobUploadService.UploadRecruitDocument(vm.Document);
                    newDocument.DocumentPath = blobPath;
                    newDocument.FileName     = vm.Document.FileName;
                }

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

                return(RedirectToAction("Details", "Candidates", new { id = vm.CandidateId }));
            }

            return(View(vm));
        }
Exemple #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));
        }