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 }); } } }
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); }