示例#1
0
        public new void NewsUpdate(News 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 hír címe nincs megadva.");
            if (entity.Abstract.Length == 0)
              throw new ArgumentNullException("News.Abstract", "A hír abstract nincs megadva.");
            if (entity.NewsBody.Length == 0)
              throw new ArgumentNullException("News.NewsBody", "A hír 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)
            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
            News selected = NewsSelect(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.NewsBody = entity.NewsBody;
            selected.VisibleForVisitor = entity.VisibleForVisitor;
            selected.VisibleForRegistered = entity.VisibleForRegistered;
            selected.IsActive = entity.IsActive;
            selected.PictureUrl = entity.PictureUrl;
            selected.IsActual = entity.IsActual;
            selected.CategoryRef = entity.CategoryRef;

            NewsPictureService newsPictureSrv = new NewsPictureService(m_DataContext);
            FileDataContext fileDataContext = new FileDataContext();
            m_DataContext.BeginNestedTran();
            try
            {
              // Clear old files:
              NewsPictureContainer oldPics = base.SelectChildrenByPictureOfNews(entity.ID);
              foreach (NewsPicture oldPic in oldPics.All)
              {
            newsPictureSrv.NewsPictureDelete(oldPic);
              }

              // NewsPicture - insert:
              foreach (NewsPicture pic in entity.NewsPictures.Current)
              {
            if (/*pic.PicturePath.Length > 0 &&*/  entity.PictureUrl != DBString.Null && entity.PictureData != null && pic.PictureData.Length > 0)
              newsPictureSrv.NewsPictureInsert(pic);
              }

              selected.NewsAttachments = entity.NewsAttachments;

              NewsAttachmentService attSrv = new NewsAttachmentService(m_DataContext);

              // Clear old files:
              NewsAttachmentContainer oldFiles = base.SelectChildrenByAttachmentOfNews(entity.ID);
              foreach (NewsAttachment oldFile in oldFiles.All)
              {
            attSrv.NewsAttachmentDelete(oldFile);
              }
              NewsAttachment newFile;
              // EDocumentAttachments - insert:
              foreach (NewsAttachment file in selected.NewsAttachments.Current)
              {
            if (file.FileData.Length == 0)
            {
              newFile = attSrv.NewsAttachmentSelectFile(file.ID);
            }
            else
            {
              newFile = file;
            }
            newFile.NewsRef = selected.ID;
            newFile.Name = file.Name;
            newFile.Description = file.Description;
            newFile.CreatedDate = DateTime.Now;

            if (attSrv.NewsAttachmentSelect(newFile.ID) != null)
            {
              attSrv.NewsAttachmentUpdate(newFile);
            }
            else
            {
              attSrv.NewsAttachmentInsert(newFile);
            }
              }
              // News
              base.NewsUpdate(selected);

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

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

            BusinessAuditEvent.Success(
              new EventParameter("NewsID", entity.ID.ToString()),
              new EventParameter("NewsTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("NewsID", entity.ID.ToString()),
              new EventParameter("NewsTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
示例#2
0
        public new void NewsInsert(News 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 hír címe nincs megadva.");
            if (entity.Abstract.Length == 0)
              throw new ArgumentNullException("News.Abstract", "A hír abstract nincs megadva.");
            if (entity.NewsBody.Length == 0)
              throw new ArgumentNullException("News.NewsBody", "A hír 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;

            NewsPictureService newsPictureSrv = new NewsPictureService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              // News
              base.NewsInsert(entity);

              if (entity.PictureData != null && entity.PictureData.Length > 0)
              {

            FileDataContext fileDataContext = new FileDataContext();
            fileDataContext.NewsInsert(entity.ID, entity.PictureData);
              }

              // NewsPictures
              foreach (NewsPicture pic in entity.NewsPictures.Current)
              {
            if (/*pic.PicturePath.Length > 0 &&*/  entity.PictureUrl != DBString.Null && entity.PictureData != null && pic.PictureData.Length > 0)
            newsPictureSrv.NewsPictureInsert(pic);
              }
              NewsAttachmentService attSrv = new NewsAttachmentService(m_DataContext);

              // EDocumentAttachments - insert:
              foreach (NewsAttachment file in entity.NewsAttachments.Current)
              {
            file.NewsRef = entity.ID;
            file.IsActive = true;
            file.CreatedDate = DateTime.Now;
            attSrv.NewsAttachmentInsert(file);
              }
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

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