Exemplo n.º 1
0
        public async Task <TransResult <T> > UpdateAsync(T updated)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            if (updated == null)
            {
                return(new TransResult <T>()
                {
                    IsSuccess = false
                });;
            }
            try
            {
                _context.Set <T>().Attach(updated);
                _context.Entry(updated).State = EntityState.Modified;
                var commitReult = await _unitOfWork.Commit();

                result.IsSuccess = commitReult.IsSuccess;
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <TransResult <T> > UpdateRangeAsync(ICollection <T> entities)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                foreach (var updated in entities)
                {
                    _context.Set <T>().Attach(updated);
                    _context.Entry(updated).State = EntityState.Modified;
                }

                var commitReult = await _unitOfWork.Commit();

                result.IsSuccess = commitReult.IsSuccess;
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 3
0
        public TransResult <T> Update(T updated)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            if (updated == null)
            {
                return(new TransResult <T>()
                {
                    IsSuccess = false
                });;
            }
            try
            {
                _context.Set <T>().Attach(updated);
                _context.Entry(updated).State = EntityState.Modified;
                _context.SaveChanges();
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 4
0
        public TransResult <T> DeleteRangeUnCommitted(ICollection <T> entities)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                _context.Set <T>().RemoveRange(entities);
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 5
0
        public TransResult <T> DeleteUnCommitted(T t)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                _context.Set <T>().Remove(t);
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 6
0
        public TransResult <T> AddUnCommitted(T entity)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                _context.Set <T>().Add(entity);
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 7
0
        public async Task <TransResult <int> > Commit()
        {
            TransResult <int> transResult = new TransResult <int>()
            {
                IsSuccess = true
            };

            try
            {
                transResult.Object = await _dbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                transResult.IsSuccess = false;
            }

            return(transResult);
        }
Exemplo n.º 8
0
        public TransResult <T> UpdateUnCommitted(T updated)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                _context.Set <T>().Attach(updated);
                _context.Entry(updated).State = EntityState.Modified;
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 9
0
        public TransResult <T> AddRange(ICollection <T> entities)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                _context.Set <T>().AddRange(entities);
                _context.SaveChanges();
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 10
0
        public async Task <TransResult <T> > AddAsync(T entity)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                _context.Set <T>().Add(entity);
                var commitReult = await _unitOfWork.Commit();

                result.IsSuccess = commitReult.IsSuccess;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 11
0
        public async Task <TransResult <T> > DeleteRangeAsync(ICollection <T> entities)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                _context.Set <T>().RemoveRange(entities);

                var commitReult = await _unitOfWork.Commit();

                result.IsSuccess = commitReult.IsSuccess;
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }
Exemplo n.º 12
0
        public TransResult <T> UpdateRangeUnCommitted(ICollection <T> entities)
        {
            TransResult <T> result = new TransResult <T>()
            {
                IsSuccess = true
            };

            try
            {
                foreach (var updated in entities)
                {
                    _context.Set <T>().Attach(updated);
                    _context.Entry(updated).State = EntityState.Modified;
                }
            }
            catch (Exception)
            {
                result.IsSuccess = false;
            }

            return(result);
        }