public virtual void ProgramKeywordDelete(ProgramKeyword entity)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     m_DataContext.BeginNestedTran();
     try
     {
       m_DataContext.ndihdProgramKeywordDelete(entity.KeywordRef,
                                           entity.ProgramRef);
       m_DataContext.CommitNested();
     }
     catch
     {
       m_DataContext.RollbackNested();
       throw;
     }
     TraceCallReturnEvent.Raise();
     return;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
 // -------------------------------------------------------------------------------------
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="origInstance">Original document data to copy.</param>
 // -------------------------------------------------------------------------------------
 public ProgramKeyword(ProgramKeyword origInstance)
     : base(origInstance)
 {
 }
 public virtual ProgramKeyword ProgramKeywordSelect(DBString KeywordRefVal,
                                                DBGuid ProgramRefVal)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     ProgramKeyword result = null;
     DataSet entitySet = m_DataContext.ndihdProgramKeywordSelect(KeywordRefVal,
                                                             ProgramRefVal);
     if (entitySet.Tables[0].Rows.Count != 0)
     {
       result = new ProgramKeyword(entitySet);
     }
     TraceCallReturnEvent.Raise();
     return result;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
        public void ProgramUpdateAdmin(Program entity)
        {
            // Check permission: Admin
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permAdmin.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            if (entity.Name.Length == 0) throw new ArgumentNullException("Program.Name", "A program neve nincs megadva.");
            if (entity.Description.Length == 0)
              throw new ArgumentNullException("Program.Description", "A program leírása nincs megadva.");
            if (entity.ProgramStatus.Length == 0)
              throw new ArgumentNullException("Program.ProgramStatus", "A program státusza nincs megadva.");

            // Logical checks
            Program selected = base.ProgramSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("Ezzel az azonosítóval nem létezik program.");

            if (CheckProgramExistByName(entity.Name, selected.OrganisationRef, entity.ID))
            {
              throw new ApplicationException("Ezzel a névvel már létezik program!");
            }

            // Save data
            selected.Name = entity.Name;
            selected.Description = entity.Description;
            selected.ProgramStatus = entity.ProgramStatus;
            selected.StartDate = entity.StartDate;
            selected.FinishDate = entity.FinishDate;
            selected.NonregisteredPartners = entity.NonregisteredPartners;
            selected.ResponsibleRef = entity.ResponsibleRef;
            selected.Coordinator1Ref = entity.Coordinator1Ref;
            selected.Coordinator2Ref = entity.Coordinator2Ref;
            selected.ProgramStatus = entity.ProgramStatus;
            selected.IsActive = entity.IsActive;

            m_DataContext.BeginNestedTran();
            try
            {
              // Program participant - delete and insert
              if (entity.Experts.AllCount > 0)
              {
            m_DataContext.ndihdProgramParticipantDeleteBy(entity.ID);

            for (int i = 0; i < entity.Experts.Deleted.Count; i++)
            {
              DBGuid ExpertRef = ((Expert) entity.Experts.Deleted.Items[i]).ID;
              m_DataContext.ndihdProgramParticipantInsert(ExpertRef, entity.ID);
            }
              }

              // Program partner - delete and insert
              if (entity.Organisations.AllCount > 0)
              {
            m_DataContext.ndihdPartnerProgramDeleteBy(entity.ID);

            for (int i = 0; i < entity.Organisations.Deleted.Count; i++)
            {
              DBGuid PartnerRef = ((Organisation) entity.Organisations.Deleted.Items[i]).ID;
              m_DataContext.ndihdProgramPartnerInsert(PartnerRef, entity.ID);
            }
              }

              #region Megyék

              // Program partner - delete and insert
              //if (entity.Regions.AllCount > 0)
              {
            //összeset letöröljük
            m_DataContext.ndihdRegionOfProgramDeleteBy(entity.ID);
            //egyesével felvesszük
            for (int i = 0; i < entity.Regions.All.Count; i++)
            {
              DBString regionRef = ((ProgramRegion) entity.Regions.All.Items[i]).RegionRef;
              m_DataContext.ndihdProgramRegionInsert(entity.ID, regionRef);
            }
              }

              #endregion

              // Program attachment
              if (entity.ProgramAttachments.AllCount > 0)
              {
            for (int i = 0; i < entity.ProgramAttachments.All.Count; i++)
            {
              // Get item from container
              ProgramAttachment attEntity = (ProgramAttachment) entity.ProgramAttachments.All.Items[i];

              // Check item existance
              ProgramAttachmentService srv = new ProgramAttachmentService();
              ProgramAttachment attSelected = srv.ProgramAttachmentSelect(attEntity.ID);
              if (attSelected == null)
              {
                // Insert a new
                attEntity.CreatedDate = DBDateTime.Now;

                if (attEntity.FileData != null && attEntity.FileData.Length > 0)
                {
                  if (attEntity.Path.Length == 0 || attEntity.Path == DBString.Null )
                    throw new ArgumentNullException("ProgramAttachment.Path", "A fájlnév nincs megadva.");

                  string fileName = attEntity.ID.Value.ToString() + Path.GetExtension(attEntity.Path);
                  FileDataContext fileDataContext = new FileDataContext();
                  fileDataContext.ProgramAttachmentInsert(attEntity.ProgramRef, fileName, attEntity.FileData);
                }

                m_DataContext.ndihdProgramAttachmentInsert(attEntity.ID,
                                                           attEntity.ProgramRef,
                                                           attEntity.Path,
                                                           attEntity.Name,
                                                           attEntity.Description,
                                                           attEntity.Author,
                                                           attEntity.Publisher,
                                                           attEntity.PublishedYear,
                                                           attEntity.Keywords,
                                                           attEntity.CreatedDate,
                                                           attEntity.FileSize,
                                                           attEntity.IsActive);
              }
              else
              {
                // Update existing
                if (attEntity.FileData != null && attEntity.FileData.Length > 0)
                {
                  if (attEntity.Path.Length == 0 || attEntity.Path == DBString.Null)
                    throw new ArgumentNullException("ProgramAttachment.Path", "A fájlnév nincs megadva.");

                  ProgramAttachment newAttachment = new ProgramAttachment(Guid.NewGuid(), attEntity);

                  string fileName = newAttachment.ID.Value.ToString() + Path.GetExtension(newAttachment.Path);
                  FileDataContext fileDataContext = new FileDataContext();
                  fileDataContext.ProgramAttachmentInsert(newAttachment.ProgramRef, fileName, newAttachment.FileData);

                  newAttachment.CreatedDate = DBDateTime.Now;
                  m_DataContext.ndihdProgramAttachmentInsert(newAttachment.ID,
                                                             newAttachment.ProgramRef,
                                                             newAttachment.Path,
                                                             newAttachment.Name,
                                                             newAttachment.Description,
                                                             newAttachment.Author,
                                                             newAttachment.Publisher,
                                                             newAttachment.PublishedYear,
                                                             newAttachment.Keywords,
                                                             newAttachment.CreatedDate,
                                                             newAttachment.FileSize,
                                                             newAttachment.IsActive);

                  attSelected.IsActive = false;
                  m_DataContext.ndihdProgramAttachmentUpdate(attSelected.ID,
                                                             attSelected.ProgramRef,
                                                             attSelected.Path,
                                                             attSelected.Name,
                                                             attSelected.Description,
                                                             attSelected.Author,
                                                             attSelected.Publisher,
                                                             attSelected.PublishedYear,
                                                             attSelected.Keywords,
                                                             attSelected.CreatedDate,
                                                             attSelected.FileSize,
                                                             attSelected.IsActive);
                }
                else
                {
                  m_DataContext.ndihdProgramAttachmentUpdate(attEntity.ID,
                                                             attEntity.ProgramRef,
                                                             attEntity.Path,
                                                             attEntity.Name,
                                                             attEntity.Description,
                                                             attEntity.Author,
                                                             attEntity.Publisher,
                                                             attEntity.PublishedYear,
                                                             attEntity.Keywords,
                                                             attEntity.CreatedDate,
                                                             attEntity.FileSize,
                                                             attEntity.IsActive);
                }
              }
            }
              }

              // Program keyword - delete and insert
              if (entity.Thesauruses.AllCount > 0)
              {
            base.DeleteChildrenByProgramOfKeyword(entity.ID);

            for (int i = 0; i < entity.Thesauruses.Deleted.Count; i++)
            {
              DBString KeywordRef = ((Thesaurus) entity.Thesauruses.Deleted.Items[i]).Keyword;
              ProgramKeyword entityPK = new ProgramKeyword(KeywordRef, entity.ID);

              ProgramKeywordService srv = new ProgramKeywordService(m_DataContext);
              srv.ProgramKeywordInsert(entityPK);
            }
              }

              // Program
              selected.LastModifiedDate = DateTime.Now;
              base.ProgramUpdate(selected);

              //feltöltjük a szabadszöveges kereséshez a GlobalSearch táblát
              GlobalSearchService srvGlobalSearch = new GlobalSearchService(m_DataContext);
              srvGlobalSearch.SaveProgram(selected);

              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            BusinessAuditEvent.Success(
              new EventParameter("ProgramID", entity.ID.ToString()),
              new EventParameter("ProgramName", entity.Name)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("ProgramID", entity.ID.ToString()),
              new EventParameter("ProgramName", entity.Name)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }