示例#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 override async Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content,
            IFormatterLogger formatterLogger,
            CancellationToken cancellationToken)

        {
            if (!content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var fileDto = new FileDto();
            var parts = await content.ReadAsMultipartAsync(cancellationToken);
            //file content
            var fileContent = parts.Contents.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "\"file\"");
            //file information
            var data = parts.Contents.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "\"data\"");
            var dataStr = await data.ReadAsStringAsync();
            fileDto = JsonConvert.DeserializeObject<FileDto>(dataStr);

            fileDto.File = await fileContent.ReadAsStreamAsync();

            return fileDto;

        }
示例#3
0
 public int Post(FileDto data)
 {
     return _fileService.Add(data);
 }
示例#4
0
 private string FormatFileName(FileDto file)
 {
     return string.Format("{0}##{1}##{2}", file.CandidateId, file.Added.ToShortDateString(), file.FileName);
 }
示例#5
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);
        }