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 PromotionFromAssortmentSave(PromotionFromAssortmentViewModel model)
        {
            var promotion = DbSession.Query <ProducerPromotion>().FirstOrDefault(r => r.Id == model.PromotionId);

            if (promotion == null)
            {
                return(HttpNotFound());
            }

            promotion.SuppliersType = model.SuppliersType;

            var products = DbSession.Query <PromotionProduct>().Where(r => r.Promotion == promotion).ToArray();
            var ids      = model.SelectedProductIds.Split(',').Select(r => uint.Parse(r)).ToArray();

            products.Where(r => !ids.Contains(r.Product.Id)).ForEach(r => DbSession.Delete(r));
            ids.Where(x => !products.Any(r => r.Product.Id == x)).ForEach(x => {
                var product = new PromotionProduct {
                    Promotion = promotion,
                    Product   = DbSession.Query <Product>().First(p => p.Id == x)
                };
                DbSession.Save(product);
            });

            var suppliers   = DbSession.Query <PromotionSupplier>().Where(r => r.Promotion == promotion).ToArray();
            var supplierIds = model.SuppliersListToSetList.Split(',').Select(r => uint.Parse(r)).ToArray();

            suppliers.Where(r => !supplierIds.Contains(r.Supplier.Id)).ForEach(r => DbSession.Delete(r));
            supplierIds.Where(x => !suppliers.Any(r => r.Supplier.Id == x)).ForEach(x => {
                var supplier = new PromotionSupplier {
                    Promotion = promotion,
                    Supplier  = DbSession.Query <Supplier>().First(s => s.Id == x)
                };
                DbSession.Save(supplier);
            });

            DbSession.Flush();

            return(RedirectToAction("PromotionList", new { id = model.MarketingEventId }));
        }