public void Execute(ISession session) { Catalog = Catalog ?? session.Query <Catalog>().First(x => x.HaveOffers); ProducerPromotion = new ProducerPromotion() { Suppliers = session.Query <Supplier>().Take(5).ToList(), Annotation = "Тестовая промоакция производителя", Name = "Тестовая промоакция производителя", Producer = session.Query <Producer>().First(), RegionMask = "0", PromoFileId = 1 }; if (Verbose) { Console.WriteLine("Создана промоакция производителя для товара {0}", Catalog.FullName); } ProducerPromotion.Catalogs.Add(Catalog); session.Save(ProducerPromotion); if (!String.IsNullOrEmpty(file)) { file = FileHelper.MakeRooted(Path.Combine(GetRoot(".."), file)); } var dir = Path.Combine(Config.RootDir, "producerpromotions"); if (!string.IsNullOrEmpty(file)) { Directory.CreateDirectory(dir); } File.Copy(file, Path.Combine(dir, ProducerPromotion.Id + Path.GetExtension(file)), true); }
public ActionResult PromotionChange(ProducerPromotion model) { var promotion = DbSession.Query <ProducerPromotion>().First(s => s.Id == model.Id); if (!promotion.Enabled && model.Enabled) { if (model.DateFinished < DateTime.Today) { ModelState.AddModelError("", "Нельзя включить акцию, так как она просрочена"); } if (string.IsNullOrWhiteSpace(model.Description)) { ModelState.AddModelError("", "Нельзя включить акцию, так как не заполнено краткое описание"); } if (string.IsNullOrWhiteSpace(model.FeeInformation)) { ModelState.AddModelError("", "Нельзя включить акцию, так как не заполнена информация о вознаграждении"); } if (string.IsNullOrWhiteSpace(model.PromoRequirements)) { ModelState.AddModelError("", "Нельзя включить акцию, так как не указаны требования по выкладке акционного товара"); } } if (!ModelState.IsValid) { ViewBag.MarketingEvent = CurrentMarketingEvent; return(View(model)); } promotion.Name = model.Name; promotion.DateStarted = model.DateStarted; promotion.DateFinished = model.DateFinished; promotion.Enabled = model.Enabled; promotion.Description = model.Description; promotion.PromoRequirements = model.PromoRequirements; promotion.FeeInformation = model.FeeInformation; promotion.FeeType = model.FeeType; promotion.CalculationUnit = model.CalculationUnit; promotion.FeeBase = model.FeeBase; promotion.MinLimit = model.MinLimit; promotion.SameConditions = model.SameConditions; promotion.Accounting = model.Accounting; if (!promotion.SameConditions || promotion.FeeBase != FeeBase.Amount) { promotion.FeeSums.ForEach(x => DbSession.Delete(x)); promotion.FeeSums.Clear(); } if (!promotion.SameConditions || promotion.FeeBase != FeeBase.Percentage) { promotion.FeePercents.ForEach(x => DbSession.Delete(x)); promotion.FeePercents.Clear(); } DbSession.Update(promotion); DbSession.Flush(); return(RedirectToAction("PromotionList", new { id = CurrentMarketingEvent.Id })); }
public ActionResult PromotionAdd(uint id) { var model = new ProducerPromotion(); model.MarketingEvent = CurrentMarketingEvent; model.DateStarted = DateTime.Today.AddMonths(1); model.DateStarted = model.DateStarted.AddDays(1 - model.DateStarted.Day); model.DateFinished = model.DateStarted.AddYears(1); model.DateFinished = model.DateFinished.AddDays(1 - model.DateFinished.Day).AddMonths(1 - model.DateFinished.Month).AddDays(-1); ViewBag.MarketingEvent = CurrentMarketingEvent; return(View(model)); }
public ActionResult PromotionCopy(uint id) { var source = DbSession.Query <ProducerPromotion>().First(r => r.Id == id); var promotion = new ProducerPromotion { MarketingEvent = source.MarketingEvent, Name = "Копия " + source.Name, DateStarted = source.DateStarted, DateFinished = source.DateFinished, Enabled = source.Enabled, Description = source.Description, PromoRequirements = source.PromoRequirements, FeeInformation = source.FeeInformation }; DbSession.Save(promotion); source.Suppliers.ForEach(r => { var supplier = new PromotionSupplier { Supplier = r.Supplier, Promotion = promotion }; DbSession.Save(supplier); }); source.Products.ForEach(r => { var product = new PromotionProduct { Promotion = promotion, Product = r.Product, Price = r.Price, DealerPercent = r.DealerPercent, MemberPercent = r.MemberPercent }; DbSession.Save(product); }); source.Subscribes.ForEach(r => { var subscribe = new PromotionSubscribe { Promotion = promotion, Member = r.Member }; DbSession.Save(subscribe); }); DbSession.Flush(); return(RedirectToAction("PromotionList", new { id = CurrentMarketingEvent.Id })); }
public ActionResult PromotionAdd(ProducerPromotion model) { if (!this.ModelState.IsValid) { ViewBag.MarketingEvent = CurrentMarketingEvent; return(View(model)); } var newItem = new ProducerPromotion() { MarketingEvent = CurrentMarketingEvent, Name = model.Name, DateStarted = model.DateStarted, DateFinished = model.DateFinished, Enabled = false, Description = model.Description, FeeInformation = model.FeeInformation }; DbSession.Save(newItem); SuccessMessage($"Акция \"{newItem.Name}\" успешно добавлена."); return(RedirectToAction("PromotionList", new { id = CurrentMarketingEvent.Id })); }
public IResult Open(ProducerPromotion ProducerPromotion) { return(new DialogResult(new DocModel <ProducerPromotion>(ProducerPromotion.Id), resizable: true)); }