private void SetFileFromVM(File file, CaveFileViewModel vm)
 {
     if (vm.Data != null)
     {
         using (var memoryStream = new System.IO.MemoryStream())
         {
             vm.Data.InputStream.CopyTo(memoryStream);
             file.Data = memoryStream.ToArray();
         }
         file.FileName = vm.Data.FileName;
         file.MimeType = vm.Data.ContentType;
     }
 }
        private MetaFile PopulateCaveFileFromVM(CaveFileViewModel vm)
        {
            File file = new File();
            SetFileFromVM(file, vm);

            MetaFile caveFile = new MetaFile();
            caveFile.File = file;

            caveFile.FileType = db.FileTypes.Find(vm.FileTypeID);
            caveFile.FileTypeId = vm.FileTypeID;

            caveFile.Description = vm.Description;

            db.Caves.Find(vm.CaveID).MetaFiles.Add(caveFile);
            return caveFile;
        }