public new void OrganisationAttachmentUpdate(OrganisationAttachment entity) { // check permission: admin, writer PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered"); PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permReg.Union(permAdmin).Demand(); TraceCallEnterEvent.Raise(); try { OrganisationService srvOrg = new OrganisationService(); Organisation selectedOrg = srvOrg.OrganisationSelect(entity.OrganisationRef); if (selectedOrg == null) throw new ApplicationException("A megadott azonosítóval nem létezik szervezet."); string writerRole = selectedOrg.ID.Value.ToString() + ".Writer"; PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole); permWriter.Union(permAdmin).Demand(); // check required fields: if (entity.Name.Length == 0) throw new ArgumentNullException("OrganisationAttachment.Name", "A csatolt fájl neve nincs megadva."); if (entity.Description.Length == 0) throw new ArgumentNullException("OrganisationAttachment.Description", "A csatolt fájl leírása nincs megadva."); OrganisationAttachment selected = base.OrganisationAttachmentSelect(entity.ID); if (selected == null) throw new ApplicationException("A csatolt dokumentum nem létezik."); if (!selected.IsActive) throw new ApplicationException("A csatolt dokumentum nem aktív."); // save data if (entity.DownloadData != null && entity.DownloadData.Length > 0) { if (entity.Path.Length == 0 || entity.Path == DBString.Null ) throw new ArgumentNullException("OrganisationAttachment.Path", "A fájlnév nincs megadva."); OrganisationAttachment newAttachment = new OrganisationAttachment(Guid.NewGuid(), entity); string fileName = newAttachment.ID.Value.ToString() + Path.GetExtension(newAttachment.Path); FileDataContext fileDataContext = new FileDataContext(); fileDataContext.OrganisationAttachmentInsert(newAttachment.OrganisationRef, fileName, entity.DownloadData); newAttachment.CreatedDate = DBDateTime.Now; newAttachment.IsActive = true; newAttachment.FileSize = entity.DownloadData.Length; newAttachment.KefFileTypeRef = entity.KefFileTypeRef; selected.IsActive = false; m_DataContext.BeginNestedTran(); try { base.OrganisationAttachmentInsert(newAttachment); OrganisationAttachmentDelete(selected); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } } else { selected.Name = entity.Name; selected.Description = entity.Description; selected.Author = entity.Author; selected.Publisher = entity.Publisher; selected.PublishedYear = entity.PublishedYear; selected.Keywords = entity.Keywords; selected.KefFileTypeRef = entity.KefFileTypeRef; base.OrganisationAttachmentUpdate(selected); } BusinessAuditEvent.Success( new EventParameter("OrganisationAttachmentID", entity.ID.ToString()), new EventParameter("OrganisationAttachmentName", entity.Name), new EventParameter("OrganisationID", entity.OrganisationRef.ToString()) ); TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("OrganisationAttachmentID", entity.ID.ToString()), new EventParameter("OrganisationAttachmentName", entity.Name), new EventParameter("OrganisationID", entity.OrganisationRef.ToString()) ); TraceCallReturnEvent.Raise(false); throw; } }
public new void OrganisationAttachmentInsert(OrganisationAttachment entity) { // check permission: admin PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered"); PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permReg.Union(permAdmin).Demand(); TraceCallEnterEvent.Raise(); try { // check required fields: if (entity.Path.Length == 0 || entity.Path== DBString.Null) throw new ArgumentNullException("OrganisationAttachment.PictureUrl", "A fájl útvonal nincs megadva."); if (entity.DownloadData == null || entity.DownloadData.Length == 0) throw new ArgumentNullException("OrganisationAttachment.DownloadData", "A file nincs megadva."); if (entity.Description.Length == 0) throw new ArgumentNullException("OrganisationAttachment.Description", "A csatolt fájl leírása nincs megadva."); string fileName = entity.ID.ToString() + Path.GetExtension(entity.Path).ToLower(); // logical checks: FileDataContext fileDataContext = new FileDataContext(); fileDataContext.OrganisationAttachmentInsert(entity.OrganisationRef, fileName, entity.DownloadData); entity.CreatedDate = DBDateTime.Now; entity.IsActive = true; entity.FileSize = entity.DownloadData.Length; base.OrganisationAttachmentInsert(entity); BusinessAuditEvent.Success(); TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()) ); TraceCallReturnEvent.Raise(false); throw; } }