예제 #1
0
        public async Task <bool> Commit <T>(T entity) where T : class
        {
            await using (var transaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    var dbEntityEntry = _dbContext.Entry(entity);

                    if (dbEntityEntry.State != EntityState.Detached)
                    {
                        dbEntityEntry.State = EntityState.Added;
                    }

                    await _dbContext.SaveChangesAsync();

                    transaction.Commit();

                    DetachAll();

                    Success = true;
                    // Message = Info.OperationSuccess;
                }
                catch (DbUpdateException)
                {
                    // transaction.Rollback();
                }
                catch (Exception)
                {
                    // transaction.Rollback();
                }
            }

            return(Success);
        }
예제 #2
0
        public virtual async Task <bool> DeleteAsync(Guid entityId)
        {
            var filter = new TFilter
            {
                Id = entityId
            };
            var entity = await GetAsync(filter);

            var result = _dbSet.Remove(entity);

            if (result.State != EntityState.Deleted)
            {
                return(false);
            }

            await _context.SaveChangesAsync();

            return(true);
        }