Exemplo n.º 1
0
        public new void JobFindUpdate(JobFind entity)
        {
            // check permission: Writer or 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.Description.Length == 0)
              throw new ArgumentNullException("JobFind.Description", "A hirdetés leírása nincs megadva.");

            // Logical checks
            JobFind selected = base.JobFindSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik hirdetés.");

            // Save data
            selected.Description = entity.Description;
            selected.City = entity.City;
            selected.RegionRef = entity.RegionRef;
            selected.Status = entity.Status;

            selected.ActivityPrevention = entity.ActivityPrevention;
            selected.ActivityResearch = entity.ActivityResearch;
            selected.ActivityRehabilitation = entity.ActivityRehabilitation;
            selected.ActivityOther = entity.ActivityOther;
            selected.Expiredate = entity.Expiredate;
            selected.NotificationSend = entity.NotificationSend;

            selected.NotificationDate = entity.NotificationDate;

            selected.LastModified = DateTime.Now;
            selected.JobFindAttachments = entity.JobFindAttachments;

            JobFindAttachmentService attSrv = new JobFindAttachmentService(m_DataContext);

            // Clear old files:
            //JobFindAttachmentContainer oldFiles = base.SelectChildrenByAttachmentOfJobFind(entity.ID);
            //foreach (JobFindAttachment oldFile in oldFiles.All)
            //{
            //  if (oldFile.FileData.Length == 0)
            //  {
            //    attSrv.JobFindAttachmentDelete(oldFile);
            //  }
            //}
            JobFindAttachment newFile;
            // EDocumentAttachments - insert:
            foreach (JobFindAttachment file in selected.JobFindAttachments.Current)
            {
              if (file.FileData.Length == 0)
              {
            newFile = attSrv.JobFindAttachmentSelectFile(file.ID);
              }
              else
              {
            newFile = file;
              }
              newFile.JobFindRef = selected.ID;
              newFile.Name = file.Name;
              newFile.Description = file.Description;
              newFile.CreatedDate = DateTime.Now;

              if (attSrv.JobFindAttachmentSelect(newFile.ID) != null)
              {
            attSrv.JobFindAttachmentUpdate(newFile);
              }
              else
              {
            attSrv.JobFindAttachmentInsert(newFile);
              }
            }

            base.JobFindUpdate(selected);

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