Exemplo n.º 1
0
        protected void DoExport(object objConfiguration)
        {
            try
            {
                var conf = objConfiguration as ExportConfiguration;

                HccRequestContext.Current = conf.HccRequestContext;
                DnnGlobal.SetPortalSettings(conf.DnnPortalSettings);
                Factory.HttpContext = conf.HttpContext;
                CultureSwitch.SetCulture(HccApp.CurrentStore, conf.DnnPortalSettings);

                var products = HccApp.CatalogServices.Products.FindByCriteria(conf.Criteria, 1, int.MaxValue,
                                                                              ref RowCount, false);

                var export   = new CatalogExport(HccApp);
                var fileName = string.Format("Hotcakes_Products_{0}_{1:yyyyMMddhhMMss}.xlsx", HccApp.CurrentCustomerId,
                                             DateTime.UtcNow);
                var filePath = DiskStorage.GetStoreDataPhysicalPath(HccApp.CurrentStore.Id, "Exports/" + fileName);
                export.ExportToExcel(products, filePath);

                var pageLink    = DiskStorage.GetHccAdminUrl(HccApp, "catalog/default.aspx", false);
                var mailMessage = new MailMessage(conf.DnnPortalSettings.Email, HccApp.CurrentCustomer.Email);
                mailMessage.IsBodyHtml = true;
                mailMessage.Body       = Localization.GetFormattedString("ExportProductsMailBody", pageLink);
                mailMessage.Subject    = Localization.GetString("ExportProductsMailSubject");
                MailServices.SendMail(mailMessage, HccApp.CurrentStore);
            }
            catch (Exception ex)
            {
                EventLog.LogEvent(ex);
            }
        }