コード例 #1
0
 public bool AddProductToPromotion(int productId, int promotionId)
 {
     if (_repo.GetProductPromotion(productId, promotionId) == null)
     {
         ProductPromotion productPromotion = new ProductPromotion {
             ProductId = productId, PromotionId = promotionId
         };
         _repo.AddProductPromotion(productPromotion);
         return(true);
     }
     return(false);
 }
コード例 #2
0
ファイル: Order.cs プロジェクト: AlexDeusdete/XPedido
        public bool AddProduct(Product product, int Quantity, ProductPromotion productPromotion)
        {
            try
            {
                if (_products.Any(x => x.Product.Id == product.Id))
                {
                    //Pega o Produto que já existia e atualiza a quantidade dele
                    OrderProduct existingOrderProduct = _products.FirstOrDefault(x => x.Product.Id == product.Id);
                    existingOrderProduct.IncrementDecrementQuantity(Quantity - existingOrderProduct.Quantity);
                    return(true);
                }

                _products.Add(new OrderProduct(product, Quantity, productPromotion));
                return(true);
            }
            catch (ArgumentNullException)
            {
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// Adds product-promotion pairs to the database
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="productIds">A collection of product ids</param>
        /// <param name="promotionId">A promotion id</param>
        /// <returns></returns>
        private async Task AddProductPromotionsToDb <T>(ICollection <string> productIds, string promotionId)
        {
            if (typeof(T) == typeof(ProductPromotion))
            {
                ICollection <ProductPromotion> productPromotions = new List <ProductPromotion>();

                foreach (string productId in productIds)
                {
                    ProductPromotion productPromotion = new ProductPromotion
                    {
                        ProductId   = productId,
                        PromotionId = promotionId
                    };

                    productPromotions.Add(productPromotion);
                }

                await this.db.ProductsPromotions.AddRangeAsync(productPromotions);

                await this.db.SaveChangesAsync();
            }
            else
            {
                ICollection <DiscountedProductPromotion> productPromotions = new List <DiscountedProductPromotion>();

                foreach (string productId in productIds)
                {
                    DiscountedProductPromotion productPromotion = new DiscountedProductPromotion
                    {
                        ProductId   = productId,
                        PromotionId = promotionId
                    };

                    productPromotions.Add(productPromotion);
                }

                await this.db.DiscountedProductsPromotions.AddRangeAsync(productPromotions);

                await this.db.SaveChangesAsync();
            }
        }
コード例 #4
0
        private OrderProduct GetOrderProductFake(int qtyProduct, float priceProduct = 0, int qtyMinPromotion = 0, float percentDiscount = 0)
        {
            Product product = new Product()
            {
                Category_id = 1, Description = "Descrição do Produto", Id = 1, Name = "Teste Produto", Photo = "", Price = priceProduct
            };
            ProductPromotion productPromotion = new ProductPromotion()
            {
                Category_id = 1,
                Name        = "Promoção Teste",
                Policies    = new Policy[1]
                {
                    new Policy()
                    {
                        Discount = percentDiscount, Min = qtyMinPromotion
                    }
                }
            };

            return(new OrderProduct(product, qtyProduct, productPromotion));
        }
コード例 #5
0
ファイル: OrderProduct.cs プロジェクト: AlexDeusdete/XPedido
 public OrderProduct(Product product, int quantity, ProductPromotion productPromotion)
 {
     Product = product ?? throw new ArgumentNullException(nameof(product));
     SetQuantity(quantity);
     _productPromotion = productPromotion;
 }
コード例 #6
0
 public void AddProductPromotion(ProductPromotion productPromotion)
 {
     _context.ProductPromotions.Add(productPromotion);
     _context.SaveChanges();
 }
コード例 #7
0
 public void RemoveProductPromotion(ProductPromotion productPromotion)
 {
     _context.ProductPromotions.Remove(productPromotion);
     _context.SaveChanges();
 }