public ActionResult PromotionFromPriceSave(PromotionFromPriceViewModel model) { var promotion = DbSession.Query <ProducerPromotion>().FirstOrDefault(r => r.Id == model.PromotionId); if (promotion == null) { return(HttpNotFound()); } var products = DbSession.Query <PromotionProduct>() .Where(r => r.Promotion == promotion) .ToArray(); var productIds = model.SelectedProductIds.Split(',').Select(r => uint.Parse(r)).ToArray(); productIds.Where(p => !products.Any(r => r.Product.Id == p)).ForEach(r => { var product = new PromotionProduct { Promotion = promotion, Product = DbSession.Query <Product>().First(p => p.Id == r) }; DbSession.Save(product); }); EditedPromotionFromPrice = null; return(RedirectToAction("PromotionList", new { id = CurrentMarketingEvent.Id })); }
public ActionResult PromotionEditFromPrice(uint id) { var model = new PromotionFromPriceViewModel(); model.Init(DbSession, id); EditedPromotionFromPrice = model; return(View(model)); }