/// <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);
                RequestLinkTemplate = RequestLinkTemplate.Replace("#PortalLink#", PortalLink);
            }

            var requestComment = ContentCommentRepository.SelectById(SiteAction.SiteID, (Guid)SiteAction.ObjectID, CommentTables.tbl_RequestComment);
            var request        = DataManager.Request.SelectById(SiteAction.SiteID, requestComment.ContentID);

            if (request == null)
            {
                return;
            }

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

            var replyLink        = "Ответить";
            var shortDescription = request.ShortDescription;

            if (PortalSettings != null)
            {
                var requestLink = string.Format(RequestLinkTemplate, request.ID);
                replyLink        = string.Format("<a href='{0}'>Ответить</a>", requestLink);
                shortDescription = string.Format("<a href='{0}'>{1}</a>", requestLink, shortDescription);
            }

            body = body.Replace("#Request.ShortDescription#", shortDescription)
                   .Replace("#Request.Comment#", requestComment.Comment)
                   .Replace("#Request.Comment.ReplyLink#", replyLink);
        }
        /// <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);
                RequestLinkTemplate = RequestLinkTemplate.Replace("#PortalLink#", PortalLink);
            }

            var invoiceComment = ContentCommentRepository.SelectById(SiteAction.SiteID, (Guid)SiteAction.ObjectID, CommentTables.tbl_InvoiceComment);
            var invoice        = DataManager.Invoice.SelectById(SiteAction.SiteID, invoiceComment.ContentID);

            if (invoice == null)
            {
                return;
            }

            subject = subject.Replace("#Invoice.Number#", invoice.Number).Replace("#Invoice.CreatedAt#", invoice.CreatedAt.ToString("dd.MM.yyyy"));
            body    = body.Replace("#Invoice.Number#", invoice.Number).Replace("#Invoice.CreatedAt#", invoice.CreatedAt.ToString("dd.MM.yyyy")).Replace("#Invoice.Comment#", invoiceComment.Comment);

            if (invoice.BuyerCompanyID.HasValue)
            {
                var company = DataManager.Company.SelectById(SiteAction.SiteID, invoice.BuyerCompanyID.Value);
                subject = subject.Replace("#Invoice.Notification.Company#", company.Name);
                body    = body.Replace("#Invoice.Notification.Company#", company.Name);
            }
            else
            {
                subject = subject.Replace("#Invoice.Notification.Company#", string.Empty);
                body    = body.Replace("#Invoice.Notification.Company#", string.Empty);
            }
        }
Esempio n. 3
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());
                }
            }
        }