예제 #1
0
        public int Add(FileDto file)
        {
            file.Added = DateTime.Now;

            //_logger.Log(string.Format("{0}, {1}", file.CandidateId, file.VacancyId));

            var formatedFileName = FormatFileName(file);
            switch (file.FileType)
            {
                case FileType.Resume:
                    file.Path = "Resume\\";
                    break;
                case FileType.Test:
                    file.Path = string.Format("Test\\{0}\\", file.VacancyId);
                    break;
                case FileType.Other:
                    file.Path = "Other\\";
                    break;
            }
            var fullPath = Path.Combine(_localStorage, file.Path);

            if (!Directory.Exists(fullPath))
                Directory.CreateDirectory(fullPath);

            string fileName = Path.Combine(file.Path, formatedFileName);
            try
            {
                SaveFile(file.File, fileName);
                var newFile = file.ToFile();
                newFile.Path = fileName;
                _fileRepository.UpdateAndCommit(newFile);

                if (file.FileType == FileType.Resume)
                {
                    var candidate = _candidateService.Get(file.CandidateId);
                    if (candidate != null)
                    {
                        candidate.Resume.Add(new Resume()
                        {
                            FileId = newFile.Id
                        });

                        _candidateRepository.UpdateAndCommit(candidate);
                    }
                   _activityHelperService.CreateUploadedResumeActivity(candidate);
                }
                if (file.FileType==FileType.Test)
                {
                    _activityHelperService.CreateUploadedTestActivity(_cardRepository.GetByCandidateAndVacancy(file.CandidateId, file.VacancyId));
                }

                return newFile.Id;
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
            }
            return -1;
        }
예제 #2
0
        public void Update(FileDto file)
        {
            file.Added = DateTime.Now;
            var entity = _fileRepository.Get(file.Id);
            var path = Path.Combine(_localStorage, entity.Path);
            if (entity == null)
                return;

            if (File.Exists(path))
                File.Delete(path);

            file.ToFile(entity);
            _fileRepository.UpdateAndCommit(entity);
            SaveFile(file.File, file.Path);
        }