Esempio n. 1
0
        public new void JobOfferInsert(JobOffer 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("JobOffer.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.JobOfferInsert(entity);

            JobOfferAttachmentService attSrv = new JobOfferAttachmentService(m_DataContext);

            // EDocumentAttachments - insert:
            foreach (JobOfferAttachment file in entity.JobOfferAttachments.Current)
            {
              file.JobOfferRef = entity.ID;
              file.IsActive = true;
              file.CreatedDate = DateTime.Now;
              attSrv.JobOfferAttachmentInsert(file);
            }
            m_DataContext.CommitNested();

            #region Találati mail
            entity = JobOfferSelect(entity.ID); // a refid miatt kell

            //Ellenõrizni kell, hogy van-epárja megye, végzettség szerint. Ha van levelet kell küldeni
            //a pár feladójának
            JobFindService srvJobFind = new JobFindService();
            JobFind filter = new JobFind(Guid.Empty);
            filter.RegionRef = entity.RegionRef;
            filter.Qualification = entity.QualificationMinRef;
            filter.Status = JobStatusEnum.ACT;
            //filter.Expiredate = DateTime.Now;
            QualificationService srvQualification = new QualificationService();
            UserService srvUser = new UserService();

            JobFindContainer finds = srvJobFind.JobFindSelectFiltered(filter);
            //Van pár
            foreach (JobFind find in finds.All)
            {
              //Itt meg kell nézni azt is, hogy nem õ-e a másik hirdetés feladója
              if (find.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.JobFindMatchCreated);
            mail.Category = EmailCategory.JobFindMatchCreated;
            mail.Subject = subject;

            User findSender = srvUser.UserSelect(find.Sender);
            if (findSender != null)
            {
              mail.To = findSender.Email;
              body = body.Replace("<FULL_USER_NAME>", findSender.Name);
              body = body.Replace("<JOB_REFID>", entity.RefId.ToString());
              body = body.Replace("<JOB_DESCRIPTION>", entity.Description);
              body = body.Replace("<SENDER_NAME>", entity.ContactName);
              body = body.Replace("<SENDER_MAIL>", entity.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);
                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("JobOfferID", entity.ID.ToString()),
              new EventParameter("JobOfferLogin", entity.Sender)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            m_DataContext.RollbackNested();
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("JobOfferID", entity.ID.ToString()),
              new EventParameter("JobOfferLogin", entity.Sender)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Esempio 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;
              }
        }
Esempio 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;
              }
        }
Esempio n. 4
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="emailTo">The email to.</param>
        /// <param name="mustUpdate">if set to <c>true</c> [must update].</param>
        /// <param name="id">The id.</param>
        private void SendMailToSender(string category, string body, string subject, string emailTo, bool mustUpdate, Guid id)
        {
            //set mail:
              Email mail = new Email(Guid.NewGuid());

              mail.Category = category;
              mail.Subject = subject;
              mail.To = emailTo;
              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)
              {

            JobFindService srv = new JobFindService(m_DataContext);
            JobFind job = srv.JobFindSelect(id);
            if(job != null)
            {
              job.NotificationSend = true;
              job.LastModified = DateTime.Now;
              srv.JobFindUpdate(job);
            }

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

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