/// <summary> //отправка уведомления о новой промо-акции /// </summary> /// <param name="promotion"></param> void SendNotificationAboutUpdatePromotion(SupplierPromotion promotion) { try { var mailFrom = ConfigurationManager.AppSettings["NewPromotionNotifier"]; var sender = new DefaultSmtpSender(ConfigurationManager.AppSettings["SmtpServer"]); var message = new MailMessage(); message.Subject = "Обновлена промо-акция"; message.From = new MailAddress(mailFrom); message.To.Add(new MailAddress(mailFrom)); message.BodyEncoding = Encoding.UTF8; message.HeadersEncoding = Encoding.UTF8; message.Body = string.Format(@"Обновлена промо-акция. Поставщик : {0} Акция : '{1}' ({2}) Период : с {3} по {4} Время : {5} Ip-адрес : {6}", promotion.PromotionOwnerSupplier.Name, promotion.Name, promotion.Id, promotion.Begin.ToShortDateString(), promotion.End.ToShortDateString(), DateTime.Now.ToString("dd.MM.yyyy HH:mm"), HttpContext.Current?.Request?.UserHostAddress); #if !DEBUG sender.Send(message); #endif } catch (Exception e) { #if DEBUG throw; #endif log.Error(String.Format("Ошибка при отправке уведомления об обновлении промо-акции {0}", promotion.Id), e); } }
public void New(uint supplierId, [DataBind("PromoRegions")] ulong[] promoRegions) { RenderView("/Promotions/Edit"); PropertyBag["allowedExtentions"] = GetAllowedExtentions(); Binder.Validator = Validator; PropertyBag["IsNew"] = true; var client = DbSession.Load <PromotionOwnerSupplier>(supplierId); var promotion = new SupplierPromotion { Enabled = true, Catalogs = new List <Catalog>(), PromotionOwnerSupplier = client, RegionMask = client.HomeRegion.Id, Begin = DateTime.Now.Date, End = DateTime.Now.AddDays(6).Date, }; PropertyBag["promotion"] = promotion; PropertyBag["AllowRegions"] = Region.GetRegionsByMask(DbSession, promotion.PromotionOwnerSupplier.MaskRegion); if (IsPost) { promotion.RegionMask = promoRegions.Aggregate(0UL, (v, a) => a + v); BindObjectInstance(promotion, "promotion"); if (IsValid(promotion)) { var file = Request.Files["inputfile"] as HttpPostedFile; if (file != null && file.ContentLength > 0) { if (!IsAllowedExtention(Path.GetExtension(file.FileName))) { Error("Выбранный файл имеет недопустимый формат."); return; } promotion.PromoFile = file.FileName; } promotion.UpdateStatus(); DbSession.Save(promotion); //отправка уведомления о новой промо-акции SendNotificationAboutNewPromotion(promotion); if (file != null && file.ContentLength > 0) { var newLocalPromoFile = GetPromoFile(promotion); using (var newFile = File.Create(newLocalPromoFile)) { file.InputStream.CopyTo(newFile); } } RedirectToAction("EditCatalogs", new[] { "id=" + promotion.Id }); } } }
public TableRow RowPromotionExists(SupplierPromotion promotion) { var row = browser.TableRow("SupplierPromotionRow" + promotion.Id); Assert.That(row.Exists, Is.True); Assert.That(row.OwnTableCell(Find.ByText(promotion.PromotionOwnerSupplier.Name)).Exists, Is.True); Assert.That(row.OwnTableCell(Find.ByText(promotion.Name)).Exists, Is.True); Assert.That(row.OwnTableCells[1].CheckBoxes.Count, Is.EqualTo(1)); Assert.That(row.OwnTableCells[1].CheckBoxes[0].Checked, Is.EqualTo(promotion.Enabled)); return(row); }
public void SetUp() { session.CreateQuery(@"delete SupplierPromotion").ExecuteUpdate(); _supplier = CreateSupplier(); _catalog = FindFirstFreeCatalog(); _promotion = CreatePromotion(_supplier, _catalog); _promotionWithFile = CreatePromotion(_supplier, _catalog, withFile: true); _promotionNotModerated = CreatePromotion(_supplier, _catalog, false); Open(); Click("Промо-акции"); AssertText("Список акций"); }
private SupplierPromotion CreatePromotion(PromotionOwnerSupplier supplier, Catalog catalog, bool moderated) { var supplierPromotion = new SupplierPromotion { Enabled = true, PromotionOwnerSupplier = supplier, Annotation = catalog.Name, Name = catalog.Name, Begin = DateTime.Now.Date.AddDays(-7), End = DateTime.Now.Date, Moderated = moderated, Catalogs = new List <Catalog> { catalog } }; supplierPromotion.UpdateStatus(); session.Save(supplierPromotion); return(supplierPromotion); }
private SupplierPromotion CreatePromotion(PromotionOwnerSupplier supplier, Catalog catalog, bool moderated = true, bool withFile = false) { var supplierPromotion = new SupplierPromotion { Enabled = true, PromotionOwnerSupplier = supplier, Annotation = catalog.Name, Name = catalog.Name, Begin = DateTime.Now.Date.AddDays(-7), End = DateTime.Now.Date.AddDays(1), Moderated = moderated, Catalogs = new List <Catalog> { catalog } }; if (withFile) { supplierPromotion.PromoFile = "testName.jpg"; } supplierPromotion.UpdateStatus(); session.Save(supplierPromotion); return(supplierPromotion); }
private void RefreshPromotion(SupplierPromotion promotion) { session.Refresh(promotion); }
public void RowPromotionNotExists(SupplierPromotion promotion) { var row = browser.TableRow("SupplierPromotionRow" + promotion.Id); Assert.That(row.Exists, Is.False); }
private string GetPromoFile(SupplierPromotion promotion) { return(Path.Combine(Config.PromotionsPath, promotion.Id + Path.GetExtension(promotion.PromoFile))); }