public ActionResult ApplyCV(Guid id)
        {
            var recruitment = _recruitmentService.Get(id);
            var vm          = new RecruitmentCVViewModel();

            vm.Recruitment   = recruitment;
            vm.RecruitmentId = id;
            return(View(vm));
        }
        public ActionResult ApplyCV(RecruitmentCVViewModel vm)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var uploadFolderPath =
                    HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath,
                                                             "ApplyCV" + "/" + vm.RecruitmentId));
                if (!Directory.Exists(uploadFolderPath))
                {
                    Directory.CreateDirectory(uploadFolderPath);
                }
                if (vm.Files != null)
                {
                    if (vm.Files[0] != null)
                    {
                        // Loop through each file and get the file info and save to the users folder and Db
                        // var file = vm.Files[0];
                        if (vm.Files.Length > 0)
                        {
                            List <string> filedata = new List <string>();
                            foreach (var file in vm.Files)
                            {
                                var uploadResult = AppHelpers.UploadRecruitmentFile(file, uploadFolderPath, LocalizationService);

                                if (!uploadResult.UploadSuccessful)
                                {
                                    return(Json(new
                                    {
                                        Result = false,
                                        Message = "Hồ sơ không đúng định dạng!"
                                    }, JsonRequestBehavior.AllowGet));
                                }

                                filedata.Add(uploadResult.UploadedFileUrl);
                            }

                            vm.FileUrl = string.Join(";", filedata);
                        }
                    }
                }

                if (vm.Images[0] != null)
                {
                    // Loop through each file and get the file info and save to the users folder and Db
                    // var file = vm.Files[0];
                    if (vm.Images.Length > 0)
                    {
                        List <string> imageData = new List <string>();
                        foreach (var img in vm.Images)
                        {
                            var uploadResult = AppHelpers.UploadRecruitmentFile(img, uploadFolderPath, LocalizationService,
                                                                                true);

                            if (!uploadResult.UploadSuccessful)
                            {
                                TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                                {
                                    Message     = uploadResult.ErrorMessage,
                                    MessageType = GenericMessages.danger
                                };
                                return(Json(new
                                {
                                    Result = false,
                                    Message = "Hình ảnh không đúng định dạng lớn hơn 2mb!"
                                }, JsonRequestBehavior.AllowGet));
                            }

                            imageData.Add(uploadResult.UploadedFileUrl);
                        }

                        vm.HinhAnhChungChi = string.Join(";", imageData);
                    }
                }
                //    // Loop through each file and get the file info and save to the users folder and Db
                //    var file = vm.Files[0];
                //if (file != null)
                //{
                //    // If successful then upload the file
                //    var uploadResult = AppHelpers.UploadFile(file, uploadFolderPath, LocalizationService);

                //    if (!uploadResult.UploadSuccessful)
                //    {
                //        return Json(new
                //        {
                //            Result = false,
                //            Message = uploadResult.ErrorMessage

                //        }, JsonRequestBehavior.AllowGet);
                //    }

                //    // Save image to data
                //    vm.FileUrl = uploadResult.UploadedFileName;
                //}

                try
                {
                    var cv          = vm.ToEntity();
                    var recruitment = _recruitmentService.Get(vm.RecruitmentId);
                    cv.Recruitment = recruitment;
                    _recruitmentService.AddApplyCV(cv);

                    unitOfWork.Commit();
                    return(Json(new
                    {
                        Result = true,
                        Message = "Nộp hồ sơ ứng tuyển thành công!"
                    }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return(Json(new
                    {
                        Result = false,
                        Message = "Vui lòng kiểm tra lại thông tin"
                    }, JsonRequestBehavior.AllowGet));
                }
            }
        }