All pastes #635526 Raw Edit

Something

public text v1 · immutable
#635526 ·published 2007-07-27 04:12 UTC
rendered paste body
        public bool DeepDelete(Spool entity)
        {
            bool success = false;
            bool hydrotestsuccess = false;
            bool typesuccess = false;
            bool logsuccess = false;

            //First we instantiate the transaction manager to create a new service transaction
            TransactionManager DbTransactionManager = new TransactionManager(DbConnectionString);

            try
            {
                //logic goes here
                Type[] ChildObjects = new Type[]{
                    typeof (TList<HydroTestSpool>),
                    typeof(TList<SpoolRevision>),
                    typeof(TList<Weld>),
                    typeof(TList<WeldActivityLog>),
                    typeof(TList<WeldTest>)
                };
                DeepLoad(entity, true, DeepLoadType.IncludeChildren, ChildObjects);

                //Begin Transaction
                DbTransactionManager.BeginTransaction();

                //Start With HydroTestSpool

                if (DataRepository.HydroTestSpoolDAL.Delete(DbTransactionManager, entity.HydroTestSpoolCollection) == entity.HydroTestSpoolCollection.Count)
                {
                    hydrotestsuccess = true;
                }
                else
                {
                    hydrotestsuccess = false;
                    DbTransactionManager.Rollback();
                }

                //removes the weld test type entries and their parents up to the spools
                if (hydrotestsuccess)
                {
                    if (entity.SpoolRevisionCollection > 0)
                    {
                        for (int i = 0; i < entity.SpoolRevisionCollection.Count; i++)
                        {
                            if (entity.SpoolRevisionCollection[i].WeldCollection.Count > 0)
                            {
                                for (j = 0; j < entity.SpoolRevisionCollection[i].WeldCollection.Count; j++)
                                {
                                    if (entity.SpoolRevisionCollection[i].WeldCollection[j].WeldActivityLogCollection.Count > 0)
                                    {
                                        if (DataRepository.WeldActivityLogDAL.Delete(DbTransactionManager, entity.SpoolRevisionCollection[i].WeldCollection[j].WeldActivityLogCollection) == entity.SpoolRevisionCollection[i].WeldCollection[j].WeldActivityLogCollection.Count)
                                        {
                                            if (DataRepository.WeldTestDAL.Delete(DbTransactionManager, entity.SpoolRevisionCollection[i].WeldCollection[j].WeldTestCollection) == entity.SpoolRevisionCollection[i].WeldCollection[j].WeldTestCollection.Count)
                                            {
                                                if (DataRepository.WeldDAL.Delete (DbTransactionManager, entity.SpoolRevisionCollection[i].WeldCollection[j]))
                                                {
                                                    success = true;
                                                }
                                                else
                                                {
                                                    success = false;
                                                    DbTransactionManager.Rollback();
                                                }
                                            }
                                            else
                                            {
                                                success = false;
                                                DbTransactionManager.Rollback();
                                            }

                                        }
                                        else
                                        {
                                            success = false;
                                            DbTransactionManager.Rollback();
                                        }
                                    }
                                    else
                                    {
                                        if (DataRepository.WeldDAL.Delete(TransactionManager, entity.SpoolRevisionCollection[i].WeldCollection[j]))
                                        {
                                            success = true;
                                        }
                                        else
                                        {
                                            success = false;
                                            DbTransactionManager.Rollback();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (DataRepository.SpoolRevisionDAL.Delete(DbTransactionManager, entity.SpoolRevisionCollection[i]))
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                    DbTransactionManager.Rollback();
                                }
                            }
                        }
                    }
                    else
                    {
                        success = false;
                        DbTransactionManager.Rollback();
                    }
                }
                else
                {
                    success = false;
                    DbTransactionManager.Rollback();
                }

                if (success)
                {
                    if (DataRepository.SpoolDAL.Delete(DbTransactionManager, entity))
                    {
                        DbTransactionManager.Commit();
                    }
                    else
                    {
                        success = false;
                        DbTransactionManager.Rollback();
                    }
                }

            }
            catch (Exception ex)
            {
                DbTransactionManager.Rollback();
                throw new Exception(ex.Message + "<br/>Spool BLL<br/>" + ex.InnerException + "<br/>" + ex.StackTrace);
            }
            finally
            {
                DbTransactionManager.Dispose();
            }

            //return
            return success;
        }