예제 #1
0
 public void CreateNewVersionOfFile(File file, Stream inputStream)
 {
     using (var db = DbHelper.CreateConnection())
     {
         var lastVersion =
             db.Select <FileVersion>(version => version.FileId == file.Id)
             .OrderByDescending(version => version.Id).FirstOrDefault();
         CreateNewVersion(lastVersion == null ? 1 : lastVersion.VersionNumber + 1, file, inputStream, db);
     }
 }
예제 #2
0
        private void CreateNewVersion(int versionNumber, File file, Stream inputStream, IDbConnection db)
        {
            byte[] binaryFile;
            using (var stream = new MemoryStream())
            {
                inputStream.CopyTo(stream);
                binaryFile = stream.ToArray();
            }

            var version = new FileVersion
            {
                File          = binaryFile,
                FileId        = file.Id,
                VersionNumber = versionNumber
            };

            db.Insert(version);
        }
예제 #3
0
 public void CreateNewFile(File file, Stream inputStream)
 {
     using (var db = DbHelper.CreateConnection())
     {
         var transaction = db.BeginTransaction();
         try
         {
             db.Insert(file);
             file.Id = (int)db.GetLastInsertId();
             CreateNewVersion(1, file, inputStream, db);
             transaction.Commit();
         }
         catch (Exception)
         {
             transaction.Rollback();
             throw;
         }
     }
 }
예제 #4
0
        public void CreateDocument(Stream inputStream, int profileName, string fileName)
        {
            File file = _documentRepository.GetFileByNameAndFolder(fileName, _sessionHelper.CurrentFolder.FolderId);

            if (file != null)
            {
                _documentRepository.CreateNewVersionOfFile(file, inputStream);
            }
            else
            {
                _documentRepository.CreateNewFile(new File
                {
                    FolderId   = _sessionHelper.CurrentFolder.FolderId,
                    FileName   = fileName,
                    CreateDate = DateTime.Now,
                    Owner      = _sessionHelper.CurrentUser.Id
                }, inputStream);
            }
        }