Beispiel #1
0
        private static Attachment getAttachment(Models.CV cv, string cvFolder)
        {
            Attachment attachment = null;

            if (cv != null)
            {
                string attachmentFilename = Path.Combine(cvFolder, cv.Name);
                attachment = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
                ContentDisposition disposition = attachment.ContentDisposition;
                disposition.CreationDate     = File.GetCreationTime(attachmentFilename);
                disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
                disposition.ReadDate         = File.GetLastAccessTime(attachmentFilename);
                disposition.FileName         = Path.GetFileName(attachmentFilename);
                disposition.Size             = new FileInfo(attachmentFilename).Length;
                disposition.DispositionType  = DispositionTypeNames.Attachment;
            }
            return(attachment);
        }
Beispiel #2
0
        public async Task<IEnumerable<CvViewModel>> Add(HttpRequestMessage request)
        {
            var provider = new CvMultipartFormDataStreamProvider(this.workingFolder);
            
            await request.Content.ReadAsMultipartAsync(provider);
   
            var cvs = new List<CvViewModel>();
            var db = new DBContext();
            foreach(var file in provider.FileData)
            {
                var fileInfo = new FileInfo(file.LocalFileName);

                var cv = new CV
                {
                    Name = fileInfo.Name,
                    Created = fileInfo.CreationTime,
                    Modified = fileInfo.LastWriteTime,
                    Size = fileInfo.Length / 1024
                };
                db.CVs.Add(cv);
               
                db.SaveChanges();

                cvs.Add(new CvViewModel
                {
                    Id = cv.Guid,
                    Name = fileInfo.Name,
                    Created = fileInfo.CreationTime,
                    Modified = fileInfo.LastWriteTime,
                    Size = fileInfo.Length /1024
                });
            }

            return cvs;            
        }