/// <summary>
        /// Gets the dates range by service level contact.
        /// </summary>
        /// <param name="serviceLevelContact">The service level contact.</param>
        /// <param name="date">The date.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <returns></returns>
        public static bool GetDatesRangeByServiceLevelContact(tbl_ServiceLevelContact serviceLevelContact, DateTime date, ref DateTime startDate, ref DateTime endDate)
        {
            var firstDayOfWeek = date.AddDays(-(date.DayOfWeek - new CultureInfo("ru-RU").DateTimeFormat.FirstDayOfWeek));

            if (!serviceLevelContact.InformRequestID.HasValue)
            {
                return(false);
            }

            switch ((ServiceLevelInform)serviceLevelContact.InformRequestID)
            {
            case ServiceLevelInform.Not:
                return(false);

            case ServiceLevelInform.EveryDay:
                startDate = date.AddDays(-1);
                break;

            case ServiceLevelInform.EveryWeek:
                if (date == firstDayOfWeek)
                {
                    startDate = date.AddDays(-7);
                }
                else
                {
                    return(false);
                }
                break;
            }

            return(true);
        }
        private string AddInvoiceRow(tbl_Invoice invoice, tbl_ServiceLevelContact serviceLevelContact)
        {
            var printLink = string.Empty;

            if (PortalSettings != null)
            {
                PortalLink = DataManager.PortalSettings.SelectPortalLink(PortalSettings.SiteID, true);
                printLink  = string.Format(InvoicePrintLinkTemplate.Replace("#PortalLink#", PortalLink), invoice.ID);
            }


            if (serviceLevelContact.InvoiceInformFormID != (int)InvoiceInformForm.None)
            {
                var siteActionAttachment = new tbl_SiteActionAttachment
                {
                    SiteID       = SiteAction.SiteID,
                    SiteActionID = SiteAction.ID,
                    FileName     = printLink + "?autoexport=pdf"
                };
                DataManager.SiteActionAttachment.Add(siteActionAttachment);

                var webClient = new WebClient();
                var file      = webClient.DownloadData(siteActionAttachment.FileName);
                MailMessage.Attachments.Add(new Attachment(new MemoryStream(file), string.Format("Счет #{0}.pdf", invoice.Number), MediaTypeNames.Application.Pdf));
            }

            var row = SiteActionTemplates.InvoiceRowTemplate;

            row = row.Replace("#Invoice.List.PrintVersion.Link#", printLink).Replace("#Invoice.List.Number#", invoice.Number)
                  .Replace("#Invoice.List.CreatedAt#", invoice.CreatedAt.ToString("dd.MM.yyyy"))
                  .Replace("#Invoice.List.Amount#", invoice.InvoiceAmount.ToString("F"))
                  .Replace("#Invoice.List.PaymentDatePlanned#", invoice.PaymentDatePlanned.HasValue ? invoice.PaymentDatePlanned.Value.ToString("dd.MM.yyyy") : "")
                  .Replace("#Invoice.List.Note#", invoice.Note);

            return(row);
        }
        private void ProceedInvoices(ref string body, IEnumerable <tbl_Invoice> invoices, tbl_ServiceLevelContact serviceLevelContact)
        {
            var tableTemplate = SiteActionTemplates.InvoiceTableTemplate;
            var sb            = new StringBuilder();

            foreach (var invoice in invoices.ToList())
            {
                sb.Append(AddInvoiceRow(invoice, serviceLevelContact));
            }

            body = body.Replace("#Invoice.PayableList#", tableTemplate.Replace("#Rows#", sb.ToString()));
        }