Esempio n. 1
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);
        }
Esempio n. 2
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);
        }