Example #1
0
        public void Delete(Guid id)
        {
            var item = db.Set(typeof(T)).Find(id);

            db.Set(typeof(T)).Remove(item);
            db.SaveChanges();
        }
Example #2
0
        public void Delete(int id)
        {
            var obj = _context.Set <T>().Find(id);

            if (obj != null)
            {
                _context.Set <T>().Remove(obj);
            }
        }
        /// <summary>
        /// CreateAsync
        /// </summary>
        /// <param name="todoItem"></param>
        /// <returns>Sngle TodoItem</returns>
        public async Task <TodoItem> CreateAsync(TodoItem todoItem)
        {
            if (todoItem == null)
            {
                throw new ArgumentNullException(nameof(todoItem));
            }
            _ctxt.Set <TodoItem>().Add(todoItem);
            await _ctxt.SaveChangesAsync();

            return(todoItem);
        }
Example #4
0
        public virtual async Task <BaseResponse> Get()
        {
            try
            {
                var result = await _context.Set <T>().Where(x => x.IsActive).ToListAsync();

                return(new SuccessResponse(result));
            }
            catch (Exception ex)
            {
                return(new ErrorResponse(State.ConnectionError, "System Error", ex.Message));
            }
        }
Example #5
0
        public T Create(T item)
        {
            item.Id      = Guid.NewGuid();
            item.Created = DateTime.Now;
            //TODO entity.CreatedById
            item.Modified = DateTime.Now;
            //TODO entity.ModifiedById

            _dbContext.Set <T>().Add(item);
            _dbContext.SaveChanges();

            return(item);
        }
Example #6
0
        public void Remove(int id)
        {
            using (var db = new TodoContext())
            {
                var item = db.Set <TEntity>().Find(id);
                //COMMENT: null érték használatáról dönteni
                if (null == item)
                {
                    throw new ArgumentOutOfRangeException(nameof(id));
                }

                db.Set <TEntity>().Remove(item);
                db.SaveChanges();
            }
        }
Example #7
0
 public async Task <IEnumerable <T> > List()
 {
     using (var data = new TodoContext(_OptionsBuilder))
     {
         return(await data.Set <T>().AsNoTracking().ToListAsync());
     }
 }
Example #8
0
 public async Task <T> GetEntityById(long Id)
 {
     using (var data = new TodoContext(_OptionsBuilder))
     {
         return(await data.Set <T>().FindAsync(Id));
     }
 }
 public void Guncelle(Tablo tablo)
 {
     using var context = new TodoContext();
     //context.Entry(tablo).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     context.Set <Tablo>().Update(tablo);//yukarıdakiyle aynı işlemi yapar
     context.SaveChanges();
 }
        public virtual T Delete(int id)
        {
            try
            {
                var existingEntity = GetById(id);

                _context.Set <T>().Remove(existingEntity);
                _context.SaveChanges();

                return(existingEntity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
        public TDto Find(int id, params Expression <Func <TEntity, object> >[] includeParams)
        {
            counters.BeginOperation();
            using (var db = new TodoContext())
            {
                var query = db.Set <TEntity>()
                            .AsQueryable();

                foreach (var include in includeParams)
                {
                    query = query.Include(include);
                }

                var item = query.SingleOrDefault(x => x.Id == id);

                //COMMENT: Tervezési kérdés a null érték használata
                if (null == item)
                {
                    return(default(TDto));
                }

                var result = Mapper.Map <TDto>(item);
                counters.EndOperation();
                return(result);
            }
        }
Example #12
0
 public async Task Update(T Objeto)
 {
     using (var data = new TodoContext(_OptionsBuilder))
     {
         data.Set <T>().Update(Objeto);
         await data.SaveChangesAsync();
     }
 }
Example #13
0
 protected RepositoryBase(TodoContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     _context = context;
     dbSet    = context.Set <TEntity>();
 }
        public void Guncelle(Tablo tablo)
        {
            using var context = new TodoContext();

            //biz bir entity nesne örneğini add update veya delete metotlarıyla gönderdiğimizde arka tarafta örnek olarak güncelleme
            //işlemi yapılıyorsa stateini modified olarak işaretler
            context.Set <Tablo>().Update(tablo);
            context.SaveChanges();
        }
 public List <MyTable> GetAll()
 {
     // using kullanildiginda ıcerısındekı islem yapilir sonra garbage
     // collector a gonderilir.
     using (var context = new TodoContext())
     {
         return(context.Set <MyTable>().ToList());
     }
 }
        public T Create <T>(T entity) where T : class
        {
            using (TodoContext db = new TodoContext())
            {
                db.Set <T>().Add(entity);
                db.SaveChanges();

                return(entity);
            }
        }
Example #17
0
        public void Update(TDto dto)
        {
            using (var db = new TodoContext())
            {
                var item = db.Set <TEntity>().Find(dto.Id);
                //COMMENT: null érték használatáról dönteni
                if (null == item)
                {
                    throw new ArgumentOutOfRangeException(nameof(dto.Id));
                }
                Mapper.Map(dto, item);

                db.SaveChanges();
            }
        }
Example #18
0
        public Task <List <TEntity> > FindAsyncByPredicateWithIncludeProperty <TEntity>(Expression <Func <TEntity, bool> > predicate,
                                                                                        params Expression <Func <TEntity, object> >[] includeProperties)
            where TEntity : BaseEntity
        {
            var entityContext = _context.Set <TEntity>();

            foreach (var includedProperty in includeProperties)
            {
                entityContext.Include(includedProperty).Load();
            }
            if (predicate != null)
            {
                return(entityContext.Where(predicate).ToListAsync());
            }
            return(entityContext.ToListAsync());
        }
Example #19
0
        public void Add(TDto dto)
        {
            //counters.BeginOperation();

            //COMMENT: Tervezési kérdés a null érték használata
            //http://netacademia.blog.hu/2017/05/30/miert_ne_hasznaljunk_null-t
            if (null == dto)
            {
                throw new ArgumentOutOfRangeException(nameof(dto));
            }

            var item = Mapper.Map <TEntity>(dto);

            db.Set <TEntity>().Add(item);
            db.SaveChanges();

            dto.Id = item.Id; //visszaküldjük a mentés után visszakapott azonosítót
            //counters.EndOperation();
        }
Example #20
0
        public void Add(TDto dto)
        {
            //counters.BeginOperation();
            //COMMENT: Tervezési kérdés a null érték használata
            //http://netacademia.blog.hu/2017/05/30/miert_ne_hasznaljunk_null-t
            if (null == dto)
            {
                throw new ArgumentOutOfRangeException(nameof(dto));
            }

            using (var db = new TodoContext())
            {
                var item = Mapper.Map <TEntity>(dto);

                db.Set <TEntity>().Add(item);

                db.SaveChanges();

                dto.Id = item.Id;
            }
            //counters.EndOperation();
        }
Example #21
0
        public TDto Find(Expression <Func <TEntity, bool> > filter,
                         params Expression <Func <TEntity, object> >[] includeParams)
        {
            using (var db = new TodoContext())
            {
                var query = db.Set <TEntity>()
                            .AsQueryable();

                foreach (var include in includeParams)
                {
                    query = query.Include(include);
                }

                var item = query.SingleOrDefault(filter);

                //COMMENT: Tervezési kérdés a null érték használata
                if (null == item)
                {
                    return(default(TDto));
                }

                return(Mapper.Map <TDto>(item));
            }
        }
Example #22
0
 public Table FindById(int id)
 {
     using var context = new TodoContext();
     return(context.Set <Table>().Find(id));
 }
 public void Sil(Tablo tablo)
 {
     using var context = new TodoContext();
     context.Set <Tablo>().Remove(tablo);
     context.SaveChanges();
 }
 public void Kaydet(Tablo tablo)
 {
     using var context = new TodoContext();
     context.Set <Tablo>().Add(tablo);
     context.SaveChanges();
 }
 public Tablo GetirIdile(int id)
 {
     using var context = new TodoContext();
     return(context.Set <Tablo>().Find(id));
 }
 public List <Tablo> GetirHepsi()
 {
     using var context = new TodoContext();
     return(context.Set <Tablo>().ToList());
 }
Example #27
0
 public void Delete(Table table)
 {
     using var context = new TodoContext();
     context.Set <Table>().Remove(table);
     context.SaveChanges();
 }
Example #28
0
 public void Save(Table table)
 {
     using var context = new TodoContext();
     context.Set <Table>().Add(table);
     context.SaveChanges();
 }
Example #29
0
 public List <Table> GetAll()
 {
     using var context = new TodoContext();
     return(context.Set <Table>().ToList());
 }
 public MyTable GetById(int id)
 {
     using var context = new TodoContext();
     return(context.Set <MyTable>().Find(id));
 }