Ejemplo n.º 1
0
        /// <summary>
        /// Sends the mail to sender.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="body">The body.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="offer">The offer.</param>
        /// <param name="mustUpdate">if set to <c>true</c> [must update].</param>
        private void SendMailToSender(string category, string body, string subject, JobOffer offer, bool mustUpdate)
        {
            //set mail:
              Email mail = new Email(Guid.NewGuid());

              mail.Category = category;
              mail.Subject = subject;

              mail.To = offer.ContactEmail;
              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);
              if (mustUpdate)
              {

            JobOfferService srv = new JobOfferService(m_DataContext);
            JobOffer job = srv.JobOfferSelect(offer.ID);
            if (job != null)
            {
              job.NotificationSend = true;
              job.LastModified = DateTime.Now;
              srv.JobOfferUpdate(job);
            }

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

            // Sending mail:
            try
            {
              emailSrv.EmailSend(mail.ID);
            }
            catch (Exception ex)
            {
              ExceptionManager.Publish(ex);
              return;
            }
              }
        }
Ejemplo n.º 2
0
        public new void JobAnswerInsert(JobAnswer entity)
        {
            try
              {
            PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered");
            PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
            permReg.Union(permAdmin).Demand();

            JobAnswer ja = base.JobAnswerSelect(entity.JobRef, entity.Type, entity.SubscriberNameRef, entity.SenderNameRef);
            if(ja != null)
            {
              if(ja.IsActive)
              throw new ApplicationException("Erre a hirdetésre már válaszolt.");
            }

            //entity.SubscriberNameRef = Thread.CurrentPrincipal.Identity.Name;
            entity.Created = DateTime.Now;
            entity.IsActive = true;
            if (ja == null)
            {
              base.JobAnswerInsert(entity);
            }
            else
            {
              ja = entity;
              base.JobAnswerUpdate(ja);
            }
            //é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.JobAnswerCreated);
            mail.Category = EmailCategory.JobAnswerCreated;
            mail.Subject = subject;
            UserService srvUser = new UserService();
            User subscriber = srvUser.UserSelect(entity.SubscriberNameRef);
            //Ha keresés hirdetésre jelentkezett valaki
            if (entity.Type == JobAnswerTypeEnum.FIN)
            {
              User sender = srvUser.UserSelect(entity.SenderNameRef);

              if (sender != null && sender.Email.Length > 0)
              {
            JobFindService srvJob = new JobFindService();
            JobFind find = srvJob.JobFindSelect(entity.JobRef);
            mail.To = sender.Email;
            body = body.Replace("<FULL_USER_NAME>", sender.Name);
            if (find != null)
            {
              body = body.Replace("<JOB_REFID>", find.RefId.ToString());
              body = body.Replace("<JOB_DESCRIPTION>", find.Description);
            }
              }
            }
            else
            {
              //ajánlat
              JobOfferService srvJob = new JobOfferService();
              JobOffer offer = srvJob.JobOfferSelect(entity.JobRef);
              if (offer != null && offer.ContactEmail.Length > 0)
              {
            mail.To = offer.ContactEmail;
            body = body.Replace("<FULL_USER_NAME>", offer.ContactName);
            body = body.Replace("<JOB_REFID>", offer.RefId.ToString());
            body = body.Replace("<JOB_DESCRIPTION>", offer.Description);
              }
            }
            if (subscriber != null)
            {
              body = body.Replace("<SUBSCRIBER_NAME>", subscriber.Name);
              body = body.Replace("<SUBSCRIBER_MAIL>", subscriber.Email);
              body = body.Replace("<MOTIVATION>", entity.Motivation);
            }

            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;
              }
            }
            // Log success
            BusinessAuditEvent.Success(
              new EventParameter("JobRef", entity.JobRef.ToString()),
              new EventParameter("OrganisationID", Thread.CurrentPrincipal.Identity.Name)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("JobRef", entity.JobRef.ToString()),
              new EventParameter("OrganisationID", Thread.CurrentPrincipal.Identity.Name)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Ejemplo n.º 3
0
        public void JobAnswerInactivateExpired()
        {
            TraceCallEnterEvent.Raise();
              try
              {
            // Save data
            //m_DataContext.ndihdJobFindSetStatus(entity.ID, entity.Status);
            // Save data
            //m_DataContext.ndihdJobFindSetStatus(entity.ID, entity.Status);

            //ki kell keresni azokat az aktív hirdetéseket, amiknek a lejárati dátuma már eljött, de még aktívak
            JobAnswer filter = new JobAnswer(Guid.Empty, "", "", "");
            filter.FilterOnIsActive = 1;
            filter.Expiredate = DateTime.Now;
            //filter.FilterOnSubscriberNotificationSend = 0;
            JobAnswerContainer answers = JobAnswerSelectFiltered(filter);

            string body = "";
            string subject = "";
            EmailTemplateService srvTemplate = new EmailTemplateService();
            srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.JobExpired);
            UserService srvUser = new UserService();
            JobFindService srvFind = new JobFindService();
            JobOfferService srvOff = new JobOfferService();
            foreach (JobAnswer answer in answers.All)
            {
              User subscriber = srvUser.UserSelect(answer.SubscriberNameRef);

              string refId = "";
              string description = "";
              if (answer.Type == JobAnswerTypeEnum.FIN)
              {
            JobFind job = srvFind.JobFindSelect(answer.JobRef);
            if (job != null)
            {
              refId = job.RefId.ToString();
              description = job.Description;
            }
              }
              else
              {
            JobOffer job = srvOff.JobOfferSelect(answer.JobRef);
            if (job != null)
            {
              refId = job.RefId.ToString();
              description = job.Description;
            }
              }
              string bodynew = "";
              //küldünk egy levelet a barátunknak
              bodynew = body.Replace("<FULL_USER_NAME>", subscriber == null ? answer.SubscriberNameRef : subscriber.Name);
              bodynew = bodynew.Replace("<JOB_REFID>", refId);
              bodynew = bodynew.Replace("<JOB_DESCRIPTION>", description);
              bodynew = bodynew.Replace("<JOB_TYPE>", "állásajánlat");
              bodynew = bodynew.Replace("<JOB_DATE>", answer.Expiredate.ToShortDateString());
              if (subscriber == null)
            break;
              SendMailToSender(EmailCategory.JobExpired, bodynew, subject, subscriber.Email, true, answer);
            }
            BusinessAuditEvent.Success();
            TraceCallReturnEvent.Raise("JobAnswerInactivateExpired");
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail("JobAnswerInactivateExpired",
              new EventParameter("Exception", ex.ToString()));
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Ejemplo n.º 4
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;
              }
        }