public void Add(Subtitle subtitle) { string caminho_WebRoot = _appEnvironment.WebRootPath; subtitle.Path = $@"{caminho_WebRoot}\Files\{subtitle.File.FileName}"; using (var tran = _context.Database.BeginTransaction()) { try { using (var fs = new FileStream(subtitle.Path, FileMode.OpenOrCreate)) { subtitle.FileName = subtitle.File.FileName; subtitle.File.CopyTo(fs); } _context.Add(subtitle); _context.SaveChanges(); tran.Commit(); } catch (Exception e) { tran.Rollback(); throw new Exception("Erro ao processar aquivo"); } } }
/// Save changes to database /// public void Save() { m_db.SaveChanges(); }