public void Run()
        {
            var dataManager = new DataManager();

            var serviceLevelContacts = dataManager.ServiceLevelContact.SelectAll();

            var today = DateTime.Now.Date;

            foreach (var serviceLevelContact in serviceLevelContacts)
            {
                var startDate = today;
                var endDate   = today;

                if (!RequestNotificationService.GetDatesRangeByServiceLevelContact(serviceLevelContact, today, ref startDate, ref endDate))
                {
                    continue;
                }

                var informClient = false;

                switch ((ServiceLevelIncludeToInform)serviceLevelContact.IncludeToInformID)
                {
                case ServiceLevelIncludeToInform.All:
                    informClient = dataManager.Requirement.SelectAllByCompanyId(serviceLevelContact.tbl_ServiceLevelClient.ClientID, startDate, endDate).Any();
                    break;

                case ServiceLevelIncludeToInform.Personal:
                    informClient = dataManager.Requirement.SelectPersonal(serviceLevelContact.ContactID, startDate, endDate).Any();
                    break;
                }

                if (informClient)
                {
                    RequestNotificationService.Notify(serviceLevelContact.tbl_Contact.SiteID, serviceLevelContact.ContactID, serviceLevelContact.ID);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Replaces the specified subject.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <param name="body">The body.</param>
        public override void Replace(ref string subject, ref string body)
        {
            if (!SiteAction.ObjectID.HasValue)
            {
                return;
            }

            PortalSettings = DataManager.PortalSettings.SelectMapBySiteId(SiteAction.SiteID, true);

            ReplaceUserInfo(ref body);

            if (PortalSettings != null)
            {
                PortalLink = DataManager.PortalSettings.SelectPortalLink(PortalSettings.SiteID);
                RequirementLinkTemplate = RequirementLinkTemplate.Replace("#PortalLink#", PortalLink);
                RequestLinkTemplate     = RequestLinkTemplate.Replace("#PortalLink#", PortalLink);
            }

            var request = DataManager.Request.SelectById(SiteAction.SiteID, (Guid)SiteAction.ObjectID);

            if (request != null)
            {
                var         serviceLevel = request.tbl_ServiceLevel;
                tbl_Contact responsible  = null;
                tbl_Contact contact      = null;
                tbl_Company company      = null;

                if (request.ResponsibleID.HasValue)
                {
                    responsible = DataManager.Contact.SelectById(SiteAction.SiteID, (Guid)request.ResponsibleID);
                }
                if (request.ContactID.HasValue)
                {
                    contact = DataManager.Contact.SelectById(SiteAction.SiteID, (Guid)request.ContactID);
                }
                company = request.tbl_Company;

                subject = ReplaceText(subject, request, serviceLevel, responsible, contact, company);
                body    = ReplaceText(body, request, serviceLevel, responsible, contact, company);
                if (body.Contains("#Requirement.RegisteredList#"))
                {
                    var requirements = DataManager.Requirement.SelectByRequestId(request.SiteID, request.ID);

                    ProceedRegisteredRequirements(ref body, requirements);
                }

                if (company != null)
                {
                    body    = body.Replace("#Request.Notification.Company#", company.Name);
                    subject = subject.Replace("#Request.Notification.Company#", company.Name);
                }
                else
                {
                    body    = body.Replace("#Request.Notification.Company#", string.Empty);
                    subject = subject.Replace("#Request.Notification.Company#", string.Empty);
                }
            }


            var requirement = DataManager.Requirement.SelectById(SiteAction.SiteID, (Guid)SiteAction.ObjectID);

            if (requirement != null)
            {
                var shortDescription = requirement.ShortDescription;
                var requirementLink  = string.Format(RequirementLinkTemplate, requirement.ID);
                shortDescription = string.Format("<a href='{0}'>{1}</a>", requirementLink, shortDescription);

                body = body.Replace("#Requirement.ShortDescription#", shortDescription);

                if (requirement.CompanyID.HasValue)
                {
                    body    = body.Replace("#Requirement.Notification.Company#", requirement.tbl_Company.Name);
                    subject = subject.Replace("#Requirement.Notification.Company#", requirement.tbl_Company.Name);
                }
                else
                {
                    body    = body.Replace("#Requirement.Notification.Company#", string.Empty);
                    subject = subject.Replace("#Requirement.Notification.Company#", string.Empty);
                }
            }


            if (((body.Contains("#Requirement.WorkedList#") || body.Contains("#Requirement.CompanyList#") ||
                  body.Contains("#Requirement.CompletedList#")) && SiteAction.ContactID.HasValue))
            {
                var serviceLevelContact = DataManager.ServiceLevelContact.SelectById((Guid)SiteAction.ObjectID);

                if (serviceLevelContact != null)
                {
                    body    = body.Replace("#Requirement.Notification.Company#", serviceLevelContact.tbl_ServiceLevelClient.tbl_Company.Name);
                    subject = subject.Replace("#Requirement.Notification.Company#", serviceLevelContact.tbl_ServiceLevelClient.tbl_Company.Name);

                    var startDate = SiteAction.ActionDate.Date;
                    var endDate   = SiteAction.ActionDate.Date;
                    RequestNotificationService.GetDatesRangeByServiceLevelContact(serviceLevelContact, SiteAction.ActionDate.Date, ref startDate, ref endDate);

                    var requirements = new List <tbl_Requirement>();

                    switch ((ServiceLevelIncludeToInform)serviceLevelContact.IncludeToInformID)
                    {
                    case ServiceLevelIncludeToInform.All:
                        requirements = DataManager.Requirement.SelectAllByCompanyId(serviceLevelContact.tbl_ServiceLevelClient.ClientID, startDate, endDate).ToList();
                        break;

                    case ServiceLevelIncludeToInform.Personal:
                        requirements = DataManager.Requirement.SelectPersonal(serviceLevelContact.ContactID, startDate, endDate).ToList();
                        break;
                    }

                    body = body.Replace("#Requirement.CompanyList#", string.Empty);

                    ProceedWorkedRequirements(ref body, requirements.Where(o => !o.tbl_RequirementStatus.IsLast).ToList(), startDate, endDate);
                    ProceedCompletedRequirements(ref body, requirements.Where(o => o.tbl_RequirementStatus.IsLast).ToList());
                }
            }
        }