Пример #1
0
        public async Task <TResult> SaveChangesForScopedAsync <TResult>(
            Func <MongoUowScoped, Task <TResult> > func,
            Func <Exception, Task <TResult> > exceptionFunc,
            CancellationToken ctok)
        {
            using (var session = GetDbTransaction())
            {
                var mongoSession = (MongoUowTransaction)session;
                try
                {
                    var scoped = new MongoUowScoped(this, mongoSession.Transaction);
                    var result = await func(scoped);

                    await mongoSession.CommitAsync(ctok);

                    return(result);
                }
                catch (Exception ex)
                {
                    await mongoSession.RollbackAsync(ctok);

                    return(await exceptionFunc(ex));
                }
            }
        }
Пример #2
0
 public TResult SaveChangesForScoped <TResult>(
     Func <MongoUowScoped, TResult> func,
     Func <Exception, TResult> exceptionFunc)
 {
     using (var session = GetDbTransaction())
     {
         var mongoSession = (MongoUowTransaction)session;
         try
         {
             var scoped = new MongoUowScoped(this, mongoSession.Transaction);
             var result = func(scoped);
             mongoSession.Commit();
             return(result);
         }
         catch (Exception ex)
         {
             mongoSession.Rollback();
             return(exceptionFunc(ex));
         }
     }
 }