Exemplo n.º 1
0
        public new void EDocumentUpdate(EDocument 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("News.Title", "A dokumentum címe nincs megadva.");

            // Logical checks
            EDocument selected = EDocumentSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik dokumentum.");

            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
            selected.Title = entity.Title;
            selected.Abstract = entity.Abstract;
            selected.Author = entity.Author;
            selected.CategoryRef = entity.CategoryRef;
            selected.CreatedDate = entity.CreatedDate;
            selected.IsVirtual = entity.IsVirtual;
            selected.LanguageRef = entity.LanguageRef;
            selected.Link = entity.Link;
            selected.SubTypeRef = entity.SubTypeRef;
            selected.Title = entity.Title;
            selected.TypeRef = entity.TypeRef;
            selected.VisibleForRegistered = entity.VisibleForRegistered;
            selected.VisibleForVisitor = entity.VisibleForVisitor;
            selected.ModifiedDate = DateTime.Now;
            selected.Summary = entity.Summary;
            selected.PictureUrl = entity.PictureUrl;

            EDocumentAttachmentsService attSrv = new EDocumentAttachmentsService(m_DataContext);
            EDocumentCommendationService commSrv = new EDocumentCommendationService(m_DataContext);
            EDocumentPublisherService pubSrv = new EDocumentPublisherService(m_DataContext);
            EDocumentPictureService pictureSrv = new EDocumentPictureService(m_DataContext);
            FileDataContext fileDataContext = new FileDataContext();
            m_DataContext.BeginNestedTran();
            try
            {

              // Clear old files:
              EDocumentPictureContainer oldPics = base.SelectChildrenByPictureOfEdocument(entity.ID);
              foreach (EDocumentPicture oldPic in oldPics.All)
              {
            pictureSrv.EDocumentPictureDelete(oldPic);
              }
              // EDocumentPictures
              foreach (EDocumentPicture pic in entity.EDocumentPictures.Current)
              {
            if (pic.PicturePath.Length > 0 && entity.PictureUrl != DBString.Null && entity.PictureData != null && pic.PictureData.Length > 0)
             pictureSrv.EDocumentPictureInsert(pic);
              }

              // Clear old files:
              EDocumentAttachmentsContainer oldFiles = base.SelectChildrenByAttachmentOfEDocument(entity.ID);
              foreach (EDocumentAttachments oldFile in oldFiles.All)
              {
            attSrv.EDocumentAttachmentsDelete(oldFile);
              }

              // EDocumentAttachments - insert:
              foreach (EDocumentAttachments file in  entity.EDocumentAttachments.Current)
              {
            attSrv.EDocumentAttachmentsInsert(file);
              }
              EDocumentCommendationContainer oldComms = base.SelectChildrenByCommendationOfEDocument(entity.ID);

              // Commendation
              foreach (EDocumentCommendation comm in entity.EDocumentCommendations.Current)
              {
            if (oldComms[comm.ID.Value.ToString()] != null)
            {
              commSrv.EDocumentCommendationUpdate(comm);
            }
            else
            {
              commSrv.EDocumentCommendationInsert(comm);
            }
              }
              // Commendation
              foreach (EDocumentCommendation comm in entity.EDocumentCommendations.Deleted)
              {
            commSrv.EDocumentCommendationDelete(comm);
              }

              EDocumentPublisherContainer oldpubs = base.SelectChildrenByPublisherOfEDocument(entity.ID);

              // Publisher
              foreach (EDocumentPublisher pub in entity.EDocumentPublishers.Current)
              {
            if (oldpubs[pub.ID.Value.ToString()] != null)
            {
              pubSrv.EDocumentPublisherUpdate(pub);
            }
            else
            {
              pub.CreatedDate = DateTime.Now;
              pubSrv.EDocumentPublisherInsert(pub);
            }
              }
              // Publisher
              foreach (EDocumentPublisher pub in entity.EDocumentPublishers.Deleted)
              {
            pubSrv.EDocumentPublisherDelete(pub);
              }
              // EDocument
              base.EDocumentUpdate(selected);

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

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

            BusinessAuditEvent.Success(
              new EventParameter("EDocumentID", entity.ID.ToString()),
              new EventParameter("EDocumentTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("EDocumentID", entity.ID.ToString()),
              new EventParameter("EDocumentTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Exemplo n.º 2
0
        public new void EDocumentInsert(EDocument 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("EDocument.Title", "A dokumentum címe nincs megadva.");

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

            // 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.");
            }

            EDocumentAttachmentsService attachSrv = new EDocumentAttachmentsService(m_DataContext);
            EDocumentCommendationService commSrv = new EDocumentCommendationService(m_DataContext);
            EDocumentPublisherService pubSrv = new EDocumentPublisherService(m_DataContext);
            EDocumentPictureService pictureSrv = new EDocumentPictureService(m_DataContext);

            m_DataContext.BeginNestedTran();

            try
            {
              // EDocuments
              base.EDocumentInsert(entity);
              EDocumentPictureContainer oldPicts = base.SelectChildrenByPictureOfEdocument(entity.ID);
              foreach (EDocumentPicture oldFile in oldPicts.All)
              {
            pictureSrv.EDocumentPictureDelete(oldFile);
              }

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

              // EDocumentPictures
              foreach (EDocumentPicture pic in entity.EDocumentPictures.Current)
              {
            pictureSrv.EDocumentPictureInsert(pic);
              }
              // Files
              foreach (EDocumentAttachments attach in entity.EDocumentAttachments.Current)
              {
            attachSrv.EDocumentAttachmentsInsert(attach);
              }

              // Commendation
              foreach (EDocumentCommendation comm in entity.EDocumentCommendations.Current)
              {
            commSrv.EDocumentCommendationInsert(comm);
              }

              // Publisher
              foreach (EDocumentPublisher pub in entity.EDocumentPublishers.Current)
              {
            pub.CreatedDate = DateTime.Now;
            pubSrv.EDocumentPublisherInsert(pub);
              }
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

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