Exemple #1
0
        public async Task DeleteAsync(IEnumerable <TEntity> entities, bool isSave = true)
        {
            foreach (var item in entities)
            {
                var table = await _entities.FindAsync(item.Id);

                PropertyInfo property = table.GetType().GetProperties().FirstOrDefault(x => x.Name == "IsRemoved");
                if (property != null)
                {
                    SetValueWithReflectionExtention.SetValue(table, "IsRemoved", true);
                    if (isSave)
                    {
                        _context.SaveChanges();
                    }
                }
                else
                {
                    _entities.Remove(table);
                    if (isSave)
                    {
                        _context.SaveChanges();
                    }
                }
            }
        }
Exemple #2
0
        public async Task DeleteAsync(TType id)
        {
            var table = await _entities.FindAsync(id);

            PropertyInfo property = table.GetType().GetProperties().FirstOrDefault(x => x.Name == "IsRemoved");

            //check soft delete or hard delete
            if (property != null)
            {
                SetValueWithReflectionExtention.SetValue(table, "IsRemoved", true);
                _context.SaveChanges();
            }
            else
            {
                _entities.Remove(table);
                _context.SaveChanges();
            }
        }
Exemple #3
0
        public void Delete(TEntity entity, bool isSave = true)
        {
            var          table    = _entities.Find(entity.Id);
            PropertyInfo property = table.GetType().GetProperties().FirstOrDefault(x => x.Name == "IsRemoved");

            if (property != null)
            {
                SetValueWithReflectionExtention.SetValue(table, "IsRemoved", true);
                if (isSave)
                {
                    _context.SaveChanges();
                }
            }
            else
            {
                _entities.Remove(table);
                if (isSave)
                {
                    _context.SaveChanges();
                }
            }
        }