コード例 #1
0
 public virtual BprOperationResult <IQueryable <TEntity> > GetAllAsNoTracking(Expression <Func <TEntity, bool> > expression)
 {
     try
     {
         var result = Table.Where(expression).AsNoTracking();
         return(BprOperationResult <IQueryable <TEntity> > .Success(result));
     }
     catch (Exception e)
     {
         Logger.LogError(e.Message);
         return(BprOperationResult <IQueryable <TEntity> > .Fail(e));
     }
 }
コード例 #2
0
 public virtual BprOperationResult <IQueryable <TEntity> > GetAll(Expression <Func <TEntity, bool> > expression,
                                                                  bool tracking = false)
 {
     try
     {
         var result = tracking ? GetAllAsTracking(expression) : GetAllAsNoTracking(expression);
         return(result);
     }
     catch (Exception e)
     {
         return(BprOperationResult <IQueryable <TEntity> > .Fail(e));
     }
 }
コード例 #3
0
 public virtual BprOperationResult <IQueryable <TEntity> > GetAllAsTracking()
 {
     try
     {
         var result = Table.AsTracking();
         return(BprOperationResult <IQueryable <TEntity> > .Success(result));
     }
     catch (Exception e)
     {
         Logger.LogError(e.Message);
         return(BprOperationResult <IQueryable <TEntity> > .Fail(e));
     }
 }
コード例 #4
0
 public virtual BprOperationResult <IQueryable <TEntity> > GetAll(bool tracking = false)
 {
     try
     {
         var result = tracking ? GetAllAsTracking() : GetAllAsNoTracking();
         return(result);
     }
     catch (Exception e)
     {
         Logger.LogError(e.Message);
         return(BprOperationResult <IQueryable <TEntity> > .Fail(e));
     }
 }
コード例 #5
0
 public virtual BprOperationResult <TEntity> Delete(TEntity entity)
 {
     try
     {
         var result = Table.Remove(entity);
         return(BprOperationResult <TEntity> .Success(result.Entity));
     }
     catch (Exception e)
     {
         Logger.LogError(e.Message);
         return(BprOperationResult <TEntity> .Fail(e));
     }
 }
コード例 #6
0
 public virtual BprOperationResult DeleteList(IList <TEntity> entities)
 {
     try
     {
         Table.RemoveRange(entities);
         return(BprOperationResult.Success());
     }
     catch (Exception e)
     {
         Logger.LogError(e.Message);
         return(BprOperationResult.Fail(e));
     }
 }
コード例 #7
0
        public virtual async Task <BprOperationResult <int> > SaveChangesAsync()
        {
            try
            {
                var result = await Database.SaveChangesAsync();

                return(BprOperationResult <int> .Success(result));
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult <int> .Fail(e));
            }
        }
コード例 #8
0
        public virtual async Task <BprOperationResult <bool> > IsExistsAsync(Expression <Func <TEntity, bool> > expression)
        {
            try
            {
                var result = await Table.AnyAsync(expression);

                return(BprOperationResult <bool> .Success(result));
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult <bool> .Fail(e));
            }
        }
コード例 #9
0
        public virtual async Task <BprOperationResult> AddListAsync(IList <TEntity> entities)
        {
            try
            {
                await Table.AddRangeAsync(entities);

                return(BprOperationResult.Success());
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult.Fail(e));
            }
        }
コード例 #10
0
        public virtual async Task <BprOperationResult <TEntity> > AddAsync(TEntity entity)
        {
            try
            {
                var result = await Table.AddAsync(entity);

                return(BprOperationResult <TEntity> .Success(result.Entity));
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult <TEntity> .Fail(e));
            }
        }
コード例 #11
0
        public virtual async Task <BprOperationResult <TEntity> > GetOrNullAsync(Expression <Func <TEntity, bool> > expression,
                                                                                 bool tracking = false)
        {
            try
            {
                var result = tracking
                    ? await GetOrNullAsTrackingAsync(expression)
                    : await GetOrNullAsNoTrackingAsync(expression);

                return(result);
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult <TEntity> .Fail(e));
            }
        }
コード例 #12
0
        public virtual async Task <BprOperationResult> DeleteListAsync(Expression <Func <TEntity, bool> > expression)
        {
            try
            {
                var entities = GetAll(expression);

                if (!entities.IsSucceeded)
                {
                    return(BprOperationResult.Fail(entities.Exception));
                }

                Table.RemoveRange(await entities.Data.ToListAsync());
                return(BprOperationResult.Success());
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult.Fail(e));
            }
        }
コード例 #13
0
        public virtual async Task <BprOperationResult <TEntity> > DeleteAsync(Expression <Func <TEntity, bool> > expression)
        {
            try
            {
                var entity = await GetOrNullAsync(expression);

                if (!entity.IsSucceeded)
                {
                    return(BprOperationResult <TEntity> .Fail(entity.Exception));
                }

                var result = Table.Remove(entity.Data);
                return(BprOperationResult <TEntity> .Success(result.Entity));
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult <TEntity> .Fail(e));
            }
        }
コード例 #14
0
        public virtual async Task <BprOperationResult <TEntity> > GetOrNullAsTrackingAsync(
            Expression <Func <TEntity, bool> > expression)
        {
            try
            {
                var entities = GetAllAsTracking();

                if (!entities.IsSucceeded)
                {
                    return(BprOperationResult <TEntity> .Fail(entities.Exception));
                }

                var result = await entities.Data.SingleOrDefaultAsync(expression);

                return(BprOperationResult <TEntity> .Success(result));
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
                return(BprOperationResult <TEntity> .Fail(e));
            }
        }