public static IEnumerable <TEntity> GetItemsList <TEntity>(Expression <Func <TEntity, bool> > predicate)
            where TEntity : class, new()
        {
            IEnumerable <TEntity> list = null;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBContext_External))
                list = unitOfWork.GetAllEntities <TEntity>(predicate);

            return(list);
        }
        //public static List<TEntity> GetStaticItemsList<TEntity>()
        //	where TEntity : IDBCommon
        //{
        //	return (List<TEntity>) entity.ReGenerateList();
        //}

        public static IEnumerable <TEntity> GetItemsList <TEntity>()
            where TEntity : class, IDBCommon, new()
        {
            IEnumerable <TEntity> itemList;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBContext_External))
                itemList = unitOfWork.GetAllEntities <TEntity>(item => item.IsOnDuty);

            return(itemList);
        }
        public static TEntity CreateNewDBEntity <TEntity>()
            where TEntity : DBCommon, new()
        {
            TEntity table = null;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBContext_External))
                table = unitOfWork.CreateDBEntity <TEntity>();
            table.DBCommonTransactionType = DB_CommonTransactionType.CreateNew;
            table.IsOnDuty = true;
            return(table);
        }
Exemple #4
0
        public static bool SaveChanges <TEntity>(this TEntity entity)
            where TEntity : class, IDBCommon, new()
        {
            int count = 0;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBCommon.DBContext_External))
            {
                if (entity.DBCommonTransactionType == DB_CommonTransactionType.CreateNew ||
                    entity.DBCommonTransactionType == DB_CommonTransactionType.SaveNew)
                {
                    unitOfWork.GetList <TEntity>().AddEntity(entity);
                    count = unitOfWork.SaveChanges();
                }
                else if (entity.DBCommonTransactionType == DB_CommonTransactionType.UpdateExisting)
                {
                    count = unitOfWork.UpdateChanges(entity);
                }
                else if (entity.DBCommonTransactionType == DB_CommonTransactionType.DeleteExisting)
                {
                    count = unitOfWork.RemoveEntity(entity);
                }
            }

            entity.ReGenerateList();

            if (entity is Person_cu)
            {
                if ((entity as Person_cu).Supplier_cu != null)
                {
                    (entity as Person_cu).Supplier_cu.ReGenerateList();
                }
                if ((entity as Person_cu).Doctor_cu != null)
                {
                    (entity as Person_cu).Doctor_cu.ReGenerateList();
                }
                if ((entity as Person_cu).Customer_cu != null)
                {
                    (entity as Person_cu).Customer_cu.ReGenerateList();
                }
                if ((entity as Person_cu).User_cu != null)
                {
                    (entity as Person_cu).User_cu.ReGenerateList();
                }
                if ((entity as Person_cu).Patient_cu != null)
                {
                    (entity as Person_cu).Patient_cu.ReGenerateList();
                }
            }

            //entity = (TEntity) entity.RegenerateEntityObject(entity);

            return(count > 0);
        }
        public static bool SaveChanges <TEntity>()
            where TEntity : class, IDBCommon, new()
        {
            int count = 0;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBCommon.DBContext_External))
            {
                unitOfWork.UpdateChanges <TEntity>(ActiveDBItem);
                count = 1;
            }

            return(count > 0);
        }
Exemple #6
0
        public static bool RemoveItem <TEntity>(this TEntity entity)
            where TEntity : class, IDBCommon, new()
        {
            int count = 0;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBCommon.DBContext_External))
            {
                entity.IsOnDuty = false;
                count           = unitOfWork.RemoveEntity(entity);
            }

            return(count > 0);
        }
        public static bool SaveChanges <TEntity>(TEntity entity)
            where TEntity : DBCommon, IDBCommon, new()
        {
            int count = 0;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBCommon.DBContext_External))
            {
                if (entity.DBCommonTransactionType == DB_CommonTransactionType.SaveNew)
                {
                    unitOfWork.GetList <TEntity>().AddEntity(entity);
                    count = unitOfWork.SaveChanges();
                }
                else
                {
                    unitOfWork.UpdateChanges(entity);
                    count = 1;
                }
            }

            return(count > 0);
        }
Exemple #8
0
        public static bool SaveChanges <TEntity>(this TEntity entity, DB_CommonTransactionType commonTransactionType)
            where TEntity : class, IDBCommon, new()
        {
            int count = 0;

            using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBCommon.DBContext_External))
            {
                switch (commonTransactionType)
                {
                case DB_CommonTransactionType.UpdateExisting:
                    count = unitOfWork.UpdateChanges(entity);

                    break;

                case DB_CommonTransactionType.SaveNew:
                    unitOfWork.GetList <TEntity>().AddEntity(entity);
                    count = unitOfWork.SaveChanges();
                    break;
                }
            }
            return(count > 0);
        }
 public virtual void AddEntity <TEntity>(TEntity entity)
     where TEntity : class, new()
 {
     using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBContext_External))
         unitOfWork.GetList <TEntity>().AddEntity(entity);
 }
 public static TEntity GetEntity <TEntity>(Expression <Func <TEntity, bool> > predicate)
     where TEntity : class, new()
 {
     using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBContext_External))
         return(unitOfWork.GetEntity <TEntity>(predicate));
 }
 public static TEntity GetEntity <TEntity>(int id)
     where TEntity : class, new()
 {
     using (UnitOfWork.UnitOfWork unitOfWork = new UnitOfWork.UnitOfWork(DBContext_External))
         return(unitOfWork.GetEntity <TEntity>(id));
 }