예제 #1
0
        public new void DesignerDrogInsert( DesignerDrog entity )
        {
            // check permission: admin
            PrincipalPermission permAdmin = new PrincipalPermission( Thread.CurrentPrincipal.Identity.Name, "Administrator" );
            permAdmin.Demand();

            TraceCallEnterEvent.Raise();
            try
            {

            // check required fields:
            if (entity.Title.Length == 0) throw new ArgumentNullException( "DesignerDrog.Title", "A Designer drog elem címe nincs megadva." );
            if (entity.Abstract.Length == 0)
              throw new ArgumentNullException( "DesignerDrog.Abstract", "A Designer drog elem rövid összefoglalója nincs megadva." );
            if (entity.Body.Length == 0)
              throw new ArgumentNullException( "DesignerDrog.Body", "A Designer drog elem szövege nincs megadva." );

            // logical checks:
            if (entity.PictureUrl.Length > 0 && entity.PictureUrl != DBString.Null)
            {
                string ext = Path.GetExtension( entity.PictureUrl ).ToLower();
                if (!(ext.Equals( ".gif" ) || ext.Equals( ".jpg" ) || ext.Equals( "jpeg" )))
                    throw new ApplicationException( "Csak jpeg vagy gif formátumú kép csatolható." );
                if (entity.PictureData == null || entity.PictureData.Length == 0)
                    throw new ApplicationException( "A fájlnévhez nem tartozik adat." );
            }
            if (entity.PictureData != null && entity.PictureData.Length > 0)
            {
                if (entity.PictureUrl.Length == 0)
                    throw new ApplicationException( "A kép adathoz nem tartozik fájlnév." );
            }

            // save data
            entity.CreatedDate = DBDateTime.Now;

            DesignerDrogPictureService designerDrogPictureSrv = new DesignerDrogPictureService( m_DataContext );
            m_DataContext.BeginNestedTran();
            try
            {
                // DesignerDrog
                base.DesignerDrogInsert( entity );

                if (entity.PictureData != null && entity.PictureData.Length > 0)
                {
                    FileDataContext fileDataContext = new FileDataContext();
                    fileDataContext.DesignerDrogInsert( entity.ID, entity.PictureData );
                }

                // DesignerDrogPictures
                foreach (DesignerDrogPicture pic in entity.DesignerDrogPictures.Current)
                {
                  if (/*pic.PicturePath.Length > 0 &&*/  entity.PictureUrl != DBString.Null && entity.PictureData != null && pic.PictureData.Length > 0)
                    designerDrogPictureSrv.DesignerDrogPictureInsert( pic );
                }
                DesignerDrogAttachmentService attSrv = new DesignerDrogAttachmentService( m_DataContext );
                DesignerDrogLinkService linkSrv = new DesignerDrogLinkService( m_DataContext );

                // EDocumentAttachments - insert:
                foreach (DesignerDrogAttachment file in entity.DesignerDrogAttachments.Current)
                {
                    file.ItemRef= entity.ID;
                    file.IsActive = true;
                    file.CreatedDate = DateTime.Now;
                    attSrv.DesignerDrogAttachmentInsert( file );
                }

                foreach (DesignerDrogLink link in entity.DesignerDrogLinks.Current)
                {
                  link.ItemRef = entity.ID;
                  linkSrv.DesignerDrogLinkInsert( link );
                }
                m_DataContext.CommitNested();
            }
            catch
            {
                m_DataContext.RollbackNested();
                throw;
            }

            BusinessAuditEvent.Success(
              new EventParameter( "DesignerDrogID", entity.ID.ToString() ),
              new EventParameter( "DesignerDrogTitle", entity.Title )
              );
            TraceCallReturnEvent.Raise();
            return;
            }
            catch (Exception ex)
            {
            ExceptionManager.Publish( ex );
            BusinessAuditEvent.Fail(
              new EventParameter( "Exception", ex.ToString() ),
              new EventParameter( "DesignerDrogID", entity.ID.ToString() ),
              new EventParameter( "DesignerDrogTitle", entity.Title )
              );
            TraceCallReturnEvent.Raise( false );
            throw;
            }
        }
예제 #2
0
        public new void DesignerDrogUpdate( DesignerDrog entity )
        {
            // Check permission: Admin
            PrincipalPermission permAdmin = new PrincipalPermission( Thread.CurrentPrincipal.Identity.Name, "Administrator" );
            permAdmin.Demand();

            TraceCallEnterEvent.Raise();
            try
            {
            // Check required fields:
              if (entity.Title.Length == 0) throw new ArgumentNullException( "DesignerDrog.Title", "A Designer drog elem címe nincs megadva." );
            if (entity.Abstract.Length == 0)
              throw new ArgumentNullException( "DesignerDrog.Abstract", "A Designer drog elem abstract nincs megadva." );
            if (entity.Body.Length == 0)
              throw new ArgumentNullException( "DesignerDrog.Body", "A Designer drog elem szövege nincs megadva." );

            if (entity.PictureUrl.Length > 0 && entity.PictureUrl != DBString.Null)
            {
                string ext = Path.GetExtension( entity.PictureUrl ).ToLower();
                if (!(ext.Equals( ".gif" ) || ext.Equals( ".jpg" ) || ext.Equals( ".jpeg" )))
                    throw new ApplicationException( "Csak jpeg vagy gif formátumú kép csatolható." );
                if (entity.PictureData == null || entity.PictureData.Length == 0)
                {
                  entity.PictureUrl = "";
                  //throw new ApplicationException("A fájlnévhez nem tartozik adat.");
                }
              if (entity.PictureData != null && entity.PictureData.Length > 0)
                {
                    if (entity.PictureUrl.Length == 0)
                        throw new ApplicationException( "A kép adathoz nem tartozik fájlnév." );
                }
            }
            // Logical checks
            DesignerDrog selected = DesignerDrogSelect( entity.ID );
            if (selected == null)
                throw new ApplicationException( "A megadott azonosítóval nem létezik hír." );

            //string oldFileName = selected.PictureUrl;

            // Save data
            selected.Title = entity.Title;
            selected.Abstract = entity.Abstract;
            selected.Body = entity.Body;
            selected.Source = entity.Source;
            selected.Author = entity.Author;
            selected.IsActive = entity.IsActive;
            selected.PictureUrl = entity.PictureUrl;
            selected.IsActual = entity.IsActual;
            selected.CategoryRef = entity.CategoryRef;

            DesignerDrogPictureService designerDrogPictureSrv = new DesignerDrogPictureService( m_DataContext );
                      DesignerDrogLinkService designerDrogLinkSrv = new DesignerDrogLinkService( m_DataContext );
            FileDataContext fileDataContext = new FileDataContext();
            m_DataContext.BeginNestedTran();
            try
            {
                // Clear old files:
                DesignerDrogPictureContainer oldPics = base.SelectChildrenByPictureOfDesignerDrogItems( entity.ID );
                foreach (DesignerDrogPicture oldPic in oldPics.All)
                {
                    designerDrogPictureSrv.DesignerDrogPictureDelete( oldPic );
                }

                // DesignerDrogPicture - insert:
                foreach (DesignerDrogPicture pic in entity.DesignerDrogPictures.Current)
                {
                  if (/*pic.PicturePath.Length > 0 &&*/  entity.PictureUrl != DBString.Null && entity.PictureData != null && pic.PictureData.Length > 0)
                        designerDrogPictureSrv.DesignerDrogPictureInsert( pic );
                }

                #region Links
                // Clear old files:
                DesignerDrogLinkContainer oldLinks = base.SelectChildrenByLinkOfDesignerDrogItem( entity.ID );
                foreach (DesignerDrogLink oldLink in oldLinks.All)
                {
                  designerDrogLinkSrv.DesignerDrogLinkDelete( oldLink );
                }

                // DesignerDrogPicture - insert:
                foreach (DesignerDrogLink link in entity.DesignerDrogLinks.Current)
                {
                  designerDrogLinkSrv.DesignerDrogLinkInsert( link );
                }
                #endregion

              selected.DesignerDrogLinks = entity.DesignerDrogLinks;
                selected.DesignerDrogAttachments = entity.DesignerDrogAttachments;

                DesignerDrogAttachmentService attSrv = new DesignerDrogAttachmentService( m_DataContext );

                // Clear old files:
                DesignerDrogAttachmentContainer oldFiles = base.SelectChildrenByAttachmentOfDesignerDrogItem( entity.ID );
                foreach (DesignerDrogAttachment oldFile in oldFiles.All)
                {
                    attSrv.DesignerDrogAttachmentDelete( oldFile );
                }
                DesignerDrogAttachment newFile;
                // EDocumentAttachments - insert:
                foreach (DesignerDrogAttachment file in selected.DesignerDrogAttachments.Current)
                {
                    if (file.FileData.Length == 0)
                    {
                        newFile = attSrv.DesignerDrogAttachmentSelectFile( file.ID );
                    }
                    else
                    {
                        newFile = file;
                    }
                    newFile.ItemRef = selected.ID;
                    newFile.Name = file.Name;
                    newFile.Description = file.Description;
                    newFile.CreatedDate = DateTime.Now;

                    if (attSrv.DesignerDrogAttachmentSelect( newFile.ID ) != null)
                    {
                        attSrv.DesignerDrogAttachmentUpdate( newFile );
                    }
                    else
                    {
                        attSrv.DesignerDrogAttachmentInsert( newFile );
                    }
                }
                // DesignerDrog
                base.DesignerDrogUpdate( selected );

                // DesignerDrog base picture update
                fileDataContext.DesignerDrogDelete( selected.ID );
                if (entity.PictureData != null && entity.PictureData.Length > 0)
                {
                    fileDataContext.DesignerDrogInsert( entity.ID, entity.PictureData );
                }

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

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