Example #1
0
        public virtual async Task ExecuteTransAsync(Func <ICoreRepository, bool> Func, Action <Exception> Rollback = null)
        {
            ICoreRepository repository = null;

            try
            {
                if (Func != null)
                {
                    repository = await this.BeginTransAsync();

                    var res = Func(repository);
                    if (res)
                    {
                        repository.Commit();
                    }
                    else
                    {
                        repository.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                repository?.Rollback();

                if (Rollback != null)
                {
                    Rollback(ex);
                }
                else
                {
                    throw;
                }
            }
        }