Esempio n. 1
0
        public IHttpActionResult PutPromotionProduct(int id, PromotionProduct promotionProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != promotionProduct.id_promotion_product)
            {
                return(BadRequest());
            }

            db.Entry(promotionProduct).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PromotionProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        static void TestPercentPromotion()
        {
            //X% on Product D when N item brought;
            //Apply 10% discount when ProductD is ordered 10 or more
            var cart     = new Cart();
            var products = GetProducts();
            var productD = products.Where(prod => prod.SKU == Constants.SKUD).FirstOrDefault();

            PopulateCartForSKUD(cart, 10);

            var percentPromo = new Promotion()
            {
                Id = 1004, Type = PromotionType.Percent
            };
            var promoProduct = new PromotionProduct()
            {
                Product         = productD,
                PriceMultiplier = .10,
                ProductCount    = 10
            };

            percentPromo.PromotionProducts.Add(promoProduct);

            percentPromo.ApplyPromotion(cart.CartProducts);

            cart.GenerateCartStatement();

            Console.WriteLine("End Case PercentPromotion");
            Console.WriteLine();
        }
Esempio n. 3
0
        List <Promotion> GetPromotionForSKUCD()
        {
            var products   = GetProducts();
            var promotions = new List <Promotion>();

            //Promotion for C & D
            var promotionCD = new Promotion()
            {
                Type = PromotionType.Combo, Id = 1003
            };
            var productC      = products.Where(prod => prod.SKU == Constants.SKUC).FirstOrDefault();
            var productD      = products.Where(prod => prod.SKU == Constants.SKUD).FirstOrDefault();
            var promoCProduct = new PromotionProduct()
            {
                Product = productC, ProductCount = 1, PriceMultiplier = 0
            };
            var promoDProduct = new PromotionProduct()
            {
                Product = productD, ProductCount = 1, PriceMultiplier = 30
            };

            promotionCD.PromotionProducts.Add(promoCProduct);
            promotionCD.PromotionProducts.Add(promoDProduct);
            promotions.Add(promotionCD);

            return(promotions);
        }
        public virtual double CalculateDiscountedPrice(PromotionProduct promotionProduct, DiscountedProduct discountedProduct)
        {
            //price is calculated for a batch on N
            var productCount = (int)discountedProduct.Count / promotionProduct.ProductCount;

            return(productCount * promotionProduct.PriceMultiplier);
        }
        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 }));
        }
Esempio n. 6
0
        /// <summary>
        /// Price calculation is diff from base, so overriding
        /// </summary>
        /// <param name="promotionProduct"></param>
        /// <param name="discountedProduct"></param>
        /// <returns></returns>
        public override double CalculateDiscountedPrice(PromotionProduct promotionProduct, DiscountedProduct discountedProduct)
        {
            //price is calculated for a batch of N products
            var productBatchCount = (int)discountedProduct.Count / promotionProduct.ProductCount;

            return(discountedProduct.Count * (1 - promotionProduct.PriceMultiplier) * promotionProduct.Product.Price);
        }
Esempio n. 7
0
        public void Update(PromotionProduct p)
        {
            var obj = db.PromotionProducts.SingleOrDefault(pp => pp.ID == p.ID);

            obj.BeginDate = p.BeginDate;
            obj.Discount  = p.Discount;
            obj.EndDate   = p.EndDate;
            db.SubmitChanges();
        }
Esempio n. 8
0
        /// <summary>
        /// 更新PromotionProduct信息
        /// </summary>
        public static void UpdatePromotionProduct(PromotionProduct entity)
        {
            IDataCommand cmd = IocManager.Instance.Resolve <IDataCommand>();

            cmd.CreateCommand("UpdatePromotionProduct");

            //DataCommand cmd = new DataCommand("UpdatePromotionProduct");
            cmd.SetParameter <PromotionProduct>(entity);
            cmd.ExecuteNonQuery();
        }
Esempio n. 9
0
 private bool IsDuplicateItems(IList <PromotionProduct> promotionProductList, PromotionProduct newPromotionProduct)
 {
     foreach (PromotionProduct promotionProduct in promotionProductList)
     {
         if (promotionProduct.ProductID == newPromotionProduct.ProductID)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 10
0
        public IHttpActionResult GetPromotionProduct(int id)
        {
            PromotionProduct promotionProduct = db.PromotionProduct.Find(id);

            if (promotionProduct == null)
            {
                return(NotFound());
            }

            return(Ok(promotionProduct));
        }
Esempio n. 11
0
    public void PopulateControl()
    {
        product      = DataAccessContext.ProductRepository.GetOne(StoreContext.Culture, ProductID, StoreID);
        promoProduct = DataAccessContextDeluxe.PromotionProductRepository.GetOne(PromotionSubGroupID, ProductID);

        ProductImage image = product.GetPrimaryProductImage();

        uxProductImage.ImageUrl = "~/" + image.ThumbnailImage;

        uxNameText.Text         = product.Name;
        uxNameLink.NavigateUrl  = Vevo.UrlManager.GetMobileProductUrl(product.ProductID, product.UrlName);
        uxImageLink.NavigateUrl = Vevo.UrlManager.GetMobileProductUrl(product.ProductID, product.UrlName);
        uxQuantityText.Text     = promoProduct.Quantity.ToString();
        uxPriceText.Text        = StoreContext.Currency.FormatPrice(product.GetProductPrice(StoreID).Price);

        if (IsAuthorizedToViewPrice())
        {
            uxPriceText.Visible = true;
        }
        else
        {
            uxPriceText.Visible = false;
        }


        if (String.IsNullOrEmpty(promoProduct.OptionItemID))
        {
            uxFixOptionPanel.Visible = false;
            uxPopupPanel.Visible     = false;
        }
        else if (promoProduct.OptionItemID.Equals("0"))
        {
            uxFixOptionPanel.Visible       = false;
            uxPopupPanel.Visible           = true;
            uxOptionGroupDetails.ProductID = ProductID;
        }
        else
        {
            uxFixOptionPanel.Visible = true;
            uxPopupPanel.Visible     = false;

            string displayName = "";
            foreach (string optionItemID in promoProduct.OptionItemID.Split(','))
            {
                OptionItem  optionItem  = DataAccessContext.OptionItemRepository.GetOne(StoreContext.Culture, optionItemID);
                OptionGroup optionGroup = DataAccessContext.OptionGroupRepository.GetOne(StoreContext.Culture, optionItem.OptionGroupID);
                displayName += optionGroup.DisplayText + ": " + optionItem.Name + "<br />";
            }

            uxFixOption.Text            = displayName;
            uxOptionHidden.Value        = promoProduct.OptionItemID;
            uxOptionItemHiddenText.Text = uxOptionHidden.Value;
        }
    }
Esempio n. 12
0
        /// <summary>
        /// 创建PromotionProduct信息
        /// </summary>
        public static int InsertPromotionProduct(PromotionProduct entity)
        {
            IDataCommand cmd = IocManager.Instance.Resolve <IDataCommand>();

            cmd.CreateCommand("InsertPromotionProduct");

            //DataCommand cmd = new DataCommand("InsertPromotionProduct");
            cmd.SetParameter <PromotionProduct>(entity);
            int result = cmd.ExecuteScalar <int>();

            return(result);
        }
Esempio n. 13
0
        public IHttpActionResult PostPromotionProduct(PromotionProduct promotionProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PromotionProduct.Add(promotionProduct);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = promotionProduct.id_promotion_product }, promotionProduct));
        }
Esempio n. 14
0
        public IHttpActionResult DeletePromotionProduct(int id)
        {
            PromotionProduct promotionProduct = db.PromotionProduct.Find(id);

            if (promotionProduct == null)
            {
                return(NotFound());
            }

            db.PromotionProduct.Remove(promotionProduct);
            db.SaveChanges();

            return(Ok(promotionProduct));
        }
        public async Task <IActionResult> ProductAdd(PromotionProduct promotionProduct)
        {
            promotionProduct.Id = 0;
            if (promotionProduct.PromotionId == 0)
            {
                return(NotFound());
            }
            if (promotionProduct.ProductId <= 0)
            {
                ModelState.AddModelError("ProductId", "商品ID必须大于0");
            }
            if (!promotionProduct.StockQuantity.HasValue && !promotionProduct.Price.HasValue)
            {
                ModelState.AddModelError("StockQuantity", "活动库存和活动价必填一项");
                ModelState.AddModelError("Price", "活动库存和活动价必填一项");
            }
            if (ModelState.IsValid)
            {
                var promotion = await _promotionContext.Promotions
                                .FirstOrDefaultAsync(m => m.Id == promotionProduct.PromotionId);

                if (promotion == null)
                {
                    return(NotFound());
                }
                var item = await _promotionContext.PromotionProducts
                           .FirstOrDefaultAsync(m => m.PromotionId == promotionProduct.PromotionId &&
                                                m.ProductId == promotionProduct.ProductId && m.Deleted == false);

                if (item == null)
                {
                    _promotionContext.PromotionProducts.Add(promotionProduct);
                    await _promotionContext.SaveChangesAsync();

                    return(RedirectToAction("Products", new
                    {
                        id = promotionProduct.PromotionId
                    }));
                }
                else
                {
                    ModelState.AddModelError("ProductId", "此活动已设置此商品");
                }
            }

            return(View(promotionProduct));
        }
        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 async Task <IActionResult> ProductEdit(PromotionProduct promotionProduct)
        {
            if (!promotionProduct.StockQuantity.HasValue && !promotionProduct.Price.HasValue)
            {
                ModelState.AddModelError("StockQuantity", "活动库存和活动价必填一项");
                ModelState.AddModelError("Price", "活动库存和活动价必填一项");
            }

            if (ModelState.IsValid)
            {
                _promotionContext.PromotionProducts.Update(promotionProduct);
                await _promotionContext.SaveChangesAsync();

                return(RedirectToAction("Products", new
                {
                    id = promotionProduct.PromotionId
                }));
            }
            return(View(promotionProduct));
        }
Esempio n. 18
0
        static List <Promotion> GetPromotionForSKUB()
        {
            var products   = GetProducts();
            var promotions = new List <Promotion>();

            //Promotion for A
            var promotionB = new Promotion()
            {
                Type = PromotionType.Single, Id = 1002
            };
            var productB      = products.Where(prod => prod.SKU == Constants.SKUB).FirstOrDefault();
            var promoProductB = new PromotionProduct()
            {
                Product = productB, ProductCount = 2, PriceMultiplier = 45
            };

            promotionB.PromotionProducts.Add(promoProductB);
            promotions.Add(promotionB);

            return(promotions);
        }
Esempio n. 19
0
        static List <Promotion> GetPromotionForSKUA()
        {
            var products   = GetProducts();
            var promotions = new List <Promotion>();

            //Promotion for A
            var promotionA = new Promotion()
            {
                Type = PromotionType.Single, Id = 1001
            };
            var productA      = products.Where(prod => prod.SKU == Constants.SKUA).FirstOrDefault();
            var promoAProduct = new PromotionProduct()
            {
                Product = productA, ProductCount = 3, PriceMultiplier = 130
            };

            promotionA.PromotionProducts.Add(promoAProduct);
            promotions.Add(promotionA);

            return(promotions);
        }
        public async Task <IActionResult> ProductAdd(int id)
        {
            if (id == 0)
            {
                return(NotFound());
            }

            var promotion = await _promotionContext.Promotions
                            .FirstOrDefaultAsync(m => m.Id == id);

            if (promotion == null)
            {
                return(NotFound());
            }
            var promotionProduct = new PromotionProduct()
            {
                PromotionId = promotion.Id
            };

            return(View(promotionProduct));
        }
Esempio n. 21
0
    protected void uxAddItemButton_Click(object sender, EventArgs e)
    {
        string errMeg = String.Empty;

        try
        {
            if (uxPromotionProductDetails.VerifyValidInput(out errMeg))
            {
                PromotionSubGroup promotionSubGroup = DataAccessContextDeluxe.PromotionSubGroupRepository.GetOne(PromotionSubGroupID);
                PromotionProduct  promotionProduct  = new PromotionProduct();
                promotionProduct.ProductID           = uxPromotionProductDetails.ProductID;
                promotionProduct.OptionItemID        = uxPromotionProductDetails.GetSelectedOptions();
                promotionProduct.PromotionSubGroupID = PromotionSubGroupID;
                promotionProduct.Quantity            = uxPromotionProductDetails.GetQuantity();
                promotionProduct.SortOrder           = ConvertUtilities.ToInt32(PromotionSubGroupID);


                if (!IsDuplicateItems(promotionSubGroup.PromotionProducts, promotionProduct))
                {
                    promotionSubGroup.PromotionProducts.Add(promotionProduct);
                    DataAccessContextDeluxe.PromotionSubGroupRepository.Save(promotionSubGroup);
                    uxMessage.DisplayMessage("Add Promotion Product Complete");

                    OnBubbleEvent(e);
                }
                else
                {
                    uxMessage.DisplayError("Cannot Add Duplicate Product");
                }
            }
            else
            {
                DisplayErrorAndPopup(errMeg);
            }
        }
        catch (Exception ex)
        {
            MessageControl.DisplayError(ex.ToString());
        }
    }
        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 }));
        }
Esempio n. 23
0
 public void Insert(PromotionProduct pp)
 {
     db.PromotionProducts.InsertOnSubmit(pp);
     db.SubmitChanges();
 }
Esempio n. 24
0
 public static void updatePromotionProduct(this PromotionProduct promotionProduct, PromotionProductViewModel promotionProductVm)
 {
     promotionProduct.PromotionID = promotionProductVm.PromotionID;
     promotionProduct.ProductID   = promotionProductVm.ProductID;
 }