public string Send() { if (!Enabled) { return("Рассылка отключена"); } if (TargetMail.IsNullOrEmpty()) { return(!IsForAdmin ? "Не указан адрес рассылки." : ""); } _replacements.AddRange(DefaultReplacements); var mail = new Email(); if (Attachments != null) { mail = mail.WithAttachments(Attachments); } if (MemoryAttachments != null) { mail = mail.WithAttachments(MemoryAttachments); } return (mail.WithSubject(FillWithReplacements(Header)) .WithBody(FillWithReplacements(Letter)) .From(SiteSetting.Get <string>("SMTPLogin")) .To(TargetMail) .Send()); }
public HeaderViewModel() { var main = CMSPage.GetByType("MainPage").ToList(); if (main.Any()) { MainMenu = main.Concat(CMSPage.FullPageTable.Where(x => x.ViewMenu && x.Visible && !x.Deleted && x.ParentID == main.First().ID) .OrderBy( x => x.OrderNum).ToList()).ToList(); } HeaderPhones = SiteSetting.Get <string>("HeaderPhone"); FooterPhones = SiteSetting.Get <string>("FooterAdress"); }
private byte[] CreateReceipt() { var rg = new ReceiptGenerator() { SellerName = SiteSetting.Get <string>("Requisites.OrgName"), SellerINN = SiteSetting.Get <string>("Requisites.INN"), SellerAccount = SiteSetting.Get <string>("Requisites.RS"), SellerBank = SiteSetting.Get <string>("Requisites.Bank"), SellerBIK = SiteSetting.Get <string>("Requisites.BIK"), SellerBankAccount = SiteSetting.Get <string>("Requisites.KS"), BuyerAddress = "", BuyerName = User.UserProfile.SurnameAndName, PaymentName = "Оплата заказа №" + ID.ToString("d10"), PaymentTotal = FinalSumWithDelivery }; var bytes = rg.Render(); return(bytes); }
public static CommonPageInfo InitFromQueryParams(List <string> allSlashedParams, List <KeyValuePair <string, string> > queryParams) { var db = new DB(); var url = ""; foreach (var allSlashedParam in allSlashedParams) { } var slashedParams = allSlashedParams.Where(x => AccessHelper.CurrentLang.AvailableList.All(z => z.ShortName != x)).ToList(); //var request = HttpContext.Current.Request; url = slashedParams.All(x => x.IsNullOrEmpty()) ? db.CMSPages.First(x => x.PageType.TypeName == "Catalog").URL : slashedParams.Last(x => !x.IsNullOrEmpty()); var routes = new RouteValueDictionary(); CommonPageInfo info; var main = CatalogBrowser.ParentPage; if (main == null) { main = db.CMSPages.FirstOrDefault(x => x.PageType.TypeName == "MainPage"); } if (main == null) { main = db.CMSPages.First(); } if (slashedParams.Any() && slashedParams[0] == "Master") { var offset = AccessHelper.CurrentLang.AvailableList.Any(z => slashedParams.Contains(z.ShortName)) ? 0 : 1; routes = ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData.Values; if (routes.ContainsKey("url")) { return(InitFromQueryParams(routes["url"].ToString())); } if (slashedParams.Count == 1) { slashedParams.Add(AccessHelper.MasterPanel.DefaultController); slashedParams.Add(AccessHelper.MasterPanel.DefaultAction); } if (slashedParams.Count < 3) { slashedParams.Add("Index"); } info = new CommonPageInfo() { Controller = slashedParams[2 - offset], Action = slashedParams[3 - offset], CurrentPage = main.LoadLangValues(), CurrentLang = AccessHelper.CurrentLang, Layout = "_Master", Routes = ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData.Values }; return(info); } var pathPairs = slashedParams.Where(x => !x.IsNullOrEmpty()).Select((x, index) => new { Key = "url" + (index + 1), Value = x }).ToList(); var cntBefore = pathPairs.Count; pathPairs = pathPairs.Where(x => !CatalogBrowser.CategoriesList.ContainsKey(x.Value) || x.Value == "catalog").ToList(); pathPairs = pathPairs.Where(x => !CatalogBrowser.Products.ContainsValue(x.Value) || x.Value == "catalog").ToList(); if (pathPairs.Count != cntBefore && pathPairs.Count > 0) { url = pathPairs.Last().Value; } foreach (var pair in pathPairs) { routes.Add(pair.Key, pair.Value); } foreach (var pair in queryParams) { routes.Add(pair.Key, pair.Value); } var cmsPage = db.CMSPages.FirstOrDefault(x => x.URL.ToLower() == url.ToLower()); var browser = CatalogBrowser.Init(); if (cmsPage == null && CatalogBrowser.CategoriesList.ContainsKey(url.ToLower())) { cmsPage = db.CMSPages.FirstOrDefault(x => x.ID == main.ID); } /* * var trunks = url.Split<string>("-").ToList(); * if (trunks.Count() > 1 && CatalogBrowser.Products.ContainsKey(trunks.Last().ToInt())) * { * cmsPage = db.CMSPages.FirstOrDefault(x => x.ID == main.ID); * } * else * { */ if (cmsPage == null && CatalogBrowser.Products.ContainsValue(url.ToLower())) { cmsPage = db.CMSPages.FirstOrDefault(x => x.ID == main.ID); } /* * } */ if (cmsPage == null || (slashedParams.Any() && slashedParams[0] == "404") || (CatalogBrowser.ParentPage != null && CatalogBrowser.ParentPage.ID == cmsPage.ID && browser.IsNotFound(cmsPage))) { info = new CommonPageInfo { URL = "404", Action = "NotFound", Controller = "TextPage", CurrentPage = main.LoadLangValues(), CurrentLang = AccessHelper.CurrentLang, Routes = ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData.Values, StatusCode = 404, Title = SiteSetting.Get <string>("CommonTitle") + "Страница не найдена" }; } else { info = new CommonPageInfo() { ID = cmsPage.ID, URL = url, CurrentPage = cmsPage.LoadLangValues(), Routes = routes, CurrentLang = AccessHelper.CurrentLang, StatusCode = 200 }; info.CurrentPage.Title = SiteSetting.Get <string>("CommonTitle") + (cmsPage.Title.IsNullOrEmpty() ? cmsPage.PageName : cmsPage.Title); if (browser.IsCategory(cmsPage)) { if (browser.CurrentCategory.ID == 1) { info.CurrentPage.Title = SiteSetting.Get <string>("CommonTitle") + cmsPage.Title; info.CurrentPage.Keywords = cmsPage.Keywords; info.CurrentPage.Description = cmsPage.Description; } else { info.CurrentPage.Title = SiteSetting.Get <string>("CommonTitle") + browser.CurrentCategory.PageTitle; info.CurrentPage.Keywords = browser.CurrentCategory.PageKeywords; info.CurrentPage.Description = browser.CurrentCategory.PageDescription; } } if (browser.IsProductPage) { info.CurrentPage.Title = SiteSetting.Get <string>("CommonTitle") + browser.CurrentProduct.PageTitle; info.CurrentPage.Keywords = browser.CurrentProduct.PageKeywords; info.CurrentPage.Description = browser.CurrentProduct.PageDescription; } } info.Layout = "MainPage"; if (cmsPage != null) { var currentRole = AccessHelper.CurrentRole; var rel = db.CMSPageRoleRels.FirstOrDefault( x => x.PageID == cmsPage.ID && (!HttpContext.Current.User.Identity.IsAuthenticated || currentRole.IsNullOrEmpty() ? !x.RoleID.HasValue : x.Role.RoleName == currentRole)); if (rel == null) { info.Controller = "TextPage"; info.Action = "AccessDenied"; info.Layout = "MainPage"; info.StatusCode = 403; info.Title = SiteSetting.Get <string>("CommonTitle") + "Доступ к этой странице ограничен"; } info.Layout = cmsPage.PageType.CMSPageTemplate.Layout; } return(info); }
protected static bool Send(string sendTo, string sendFrom, string sendSubject, string sendMessage, List <string> attachments, List <KeyValuePair <string, MemoryStream> > memAttaches, out string result) { try { bool bTest = sendTo.IsMailAdress(); if (bTest == false) { result = "Неправильно указан адрес: " + sendTo; return(false); } var message = new MailMessage( sendFrom, sendTo, sendSubject, sendMessage); message.IsBodyHtml = true; message.BodyEncoding = Encoding.UTF8; foreach (string attach in attachments) { var attached = new Attachment(attach, MediaTypeNames.Application.Octet); //attached.NameEncoding = Encoding.UTF8; message.Attachments.Add(attached); } foreach (var pair in memAttaches) { pair.Value.Position = 0; var attached = new Attachment(pair.Value, pair.Key, MIMETypeWrapper.GetMIME(Path.GetExtension(pair.Key).Substring(1))); //attached.NameEncoding = Encoding.UTF8; message.Attachments.Add(attached); } // create smtp client at mail server location var client = new SmtpClient(SiteSetting.Get <string>("SMTP")); if (SiteSetting.Get <Int32>("SMTPPort") > 0) { client.Port = SiteSetting.Get <Int32>("SMTPPort"); } if (SiteSetting.Get <string>("SMTPLogin").IsNullOrEmpty() || SiteSetting.Get <string>("SMTPPass").IsNullOrEmpty()) { client.UseDefaultCredentials = true; } else { client.Credentials = new NetworkCredential(SiteSetting.Get <string>("SMTPLogin"), SiteSetting.Get <string>("SMTPPass")); } client.Send(message); result = ""; return(true); } catch (Exception ex) { result = ex.Message; return(false); } }