Esempio n. 1
0
        protected DbResponse <List <TModel> > GetCollection(IEnumerable <TModel> query, Action <Exception, string> errorLog = null, string summary = null)
        {
            var db = new DbResponse <List <TModel> >();

            try
            {
                db.Object = query.ToList();
            }
            catch (DbUpdateException dbEx)
            {
                db.Message = dbEx.Message;
                errorLog?.Invoke(dbEx, summary);
            }
            catch (Exception ex)
            {
                db.Message = ex.Message;
                errorLog?.Invoke(ex, summary);
            }
            return(db);
        }
Esempio n. 2
0
        protected async Task <DbResponse <TEntity> > GetAsync(IQueryable <TEntity> query, Action <Exception, string> errorLog = null, string summary = null)
        {
            var db = new DbResponse <TEntity>();

            try
            {
                db.Object = await query.FirstOrDefaultAsync();
            }
            catch (DbUpdateException dbEx)
            {
                db.Message = dbEx.Message;
                errorLog?.Invoke(dbEx, summary);
            }
            catch (Exception ex)
            {
                db.Message = ex.Message;
                errorLog?.Invoke(ex, summary);
            }
            return(db);
        }
Esempio n. 3
0
        protected async Task <DbResponse <List <TModel> > > GetCollectionAsync(IQueryable <TModel> query, Action <Exception, string> errorLog = null, string summary = null)
        {
            var db = new DbResponse <List <TModel> >();

            try
            {
                db.Object = await query.ToListAsync();

                db.Status = DbQueryStatus.Success;
            }
            catch (DbUpdateException dbEx)
            {
                db.Message = dbEx.Message;
                errorLog?.Invoke(dbEx, summary);
            }
            catch (Exception ex)
            {
                db.Message = ex.Message;
                errorLog?.Invoke(ex, summary);
            }
            return(db);
        }