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;
              }
        }
Exemplo n.º 2
0
        public new void JobFindInsert(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();
              m_DataContext.BeginNestedTran();
              try
              {
            // check required fields:
            if (entity.Description.Length == 0)
              throw new ArgumentNullException("JobFind.Description", "A hirdetés leírása nincs megadva.");

            entity.Sender = Thread.CurrentPrincipal.Identity.Name;
            entity.Status = JobStatusEnum.ACT;
            entity.NotificationSend = false;
            entity.LastModified = DateTime.Now;
            entity.Created = DateTime.Now;
            base.JobFindInsert(entity);

            JobFindAttachmentService attSrv = new JobFindAttachmentService(m_DataContext);

            // EDocumentAttachments - insert:
            foreach (JobFindAttachment file in entity.JobFindAttachments.Current)
            {
              file.JobFindRef = entity.ID;
              file.IsActive = true;
              file.CreatedDate = DateTime.Now;
              attSrv.JobFindAttachmentInsert(file);
            }

            m_DataContext.CommitNested();

            #region Találati mail

            entity = JobFindSelect(entity.ID); // a refid miatt kell
            UserService srvUser = new UserService();

            //Felado
            User sender = srvUser.UserSelect(entity.Sender);

            //Ellenõrizni kell, hogy van-epárja megye, végzettség szerint. Ha van levelet kell küldeni
            //a pár feladójának
            JobOfferService srvJobFind = new JobOfferService();
            JobOffer filter = new JobOffer(Guid.Empty);
            filter.RegionRef = entity.RegionRef;

            filter.QualificationMinRef = sender.QualificationRef;
            filter.Status = JobStatusEnum.ACT;

            JobOfferContainer offers = srvJobFind.JobOfferSelectFiltered(filter);
            //Van pár
            foreach (JobOffer offer in offers.All)
            {
              //Itt meg kell nézni azt is, hogy nem õ-e a másik hirdetés feladója
              if (offer.Sender != entity.Sender)
              {
            //értesítjük a feladót, hogy valaki válaszolt a hirdetésére
            //set mail:
            Email mail = new Email(Guid.NewGuid());
            //Subject és body lekérdezése
            string body = "";
            string subject = "";
            EmailTemplateService srvTemplate = new EmailTemplateService();
            srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.JobOfferMatchCreated);
            mail.Category = EmailCategory.JobOfferMatchCreated;
            mail.Subject = subject;

            mail.To = offer.ContactEmail;
            body = body.Replace("<FULL_USER_NAME>", offer.ContactName);
            body = body.Replace("<JOB_REFID>", entity.RefId.ToString());
            body = body.Replace("<JOB_DESCRIPTION>", entity.Description);
            body = body.Replace("<SENDER_NAME>", sender.Name);
            body = body.Replace("<SENDER_MAIL>", sender.Email);
            mail.MailBody = body;

            if (mail.MailBody != null && mail.To != null && mail.Subject != null)
            {
              // Save data to database
              EmailService emailSrv = new EmailService(m_DataContext);
              m_DataContext.BeginNestedTran();
              try
              {
                emailSrv.EmailInsert(mail);
                m_DataContext.CommitNested();
              }
              catch
              {
                m_DataContext.RollbackNested();
                throw;
              }

              // Sending mail:
              try
              {
                emailSrv.EmailSend(mail.ID);
              }
              catch (Exception ex)
              {
                ExceptionManager.Publish(ex);
                return;
              }
            }
              }
            }

            #endregion

            BusinessAuditEvent.Success(
              new EventParameter("JobFindID", entity.ID.ToString()),
              new EventParameter("JobFindLogin", entity.Sender)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            m_DataContext.RollbackNested();
            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;
              }
        }