public IActionResult Insert(DiscountProduct discountProduct)
        {
            var lProduct = _unitOfWork.SP_Call.List <Product>("SP_GetAll_Product");

            discountProduct.ProductList = lProduct.Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.Id.ToString()
            });

            try
            {
                var parameter = new DynamicParameters();
                parameter.Add("@DiscountId", discountProduct.DiscountId);
                parameter.Add("@ProductId", discountProduct.ProductId);

                _unitOfWork.SP_Call.Excute("SP_Create_Discount_Product", parameter);
                return(RedirectToAction("Upsert", "Discount", new { id = discountProduct.DiscountId }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(discountProduct));
            }
        }
예제 #2
0
        public void CreateSaleItem()
        {
            using (SimpleSaleDbContext _context = new SimpleSaleDbContext())
            {
                //Handles product Qty
                int quantity = 1;
                if (txtgetItemQuantity.Text != null && txtgetItemQuantity.Text != "")
                {
                    quantity = int.Parse(txtgetItemQuantity.Text);
                }

                Product product = _context.Products
                                  .FirstOrDefault(x =>
                                                  x.Barcode ==
                                                  txtgetAddItemToCartBarcode.Text
                                                  .ToString());

                if (product == null)
                {
                    MessageBox.Show("Please enter a valid product barcode", "Error - No Value", MessageBoxButton.OK, MessageBoxImage.Error);
                    txtgetAddItemToCartBarcode.Focus();
                }
                else
                {
                    ValueAddedTax vat = _context.ValueAddedTaxes.FirstOrDefault(y => y.Id == 4);

                    DiscountProduct discountOnProduct = _context.DiscountOnProducts.FirstOrDefault(z => z.ProductId == product.Id);
                    Discount        discount          = new Discount();

                    if (discountOnProduct == null)
                    {
                        discount.DiscountName  = "No Discount";
                        discount.DiscountValue = 0;
                    }
                    else
                    {
                        discount = _context.Discounts.FirstOrDefault(z => z.Id == discountOnProduct.DiscountId);
                    }

                    SaleItem saleItem = new SaleItem();

                    saleItem.ProductId       = product.Id;
                    saleItem.ValueAddedTaxId = vat.Id;
                    saleItem.DiscountId      = discount.Id;
                    saleItem.Item            = product.ProductName;
                    saleItem.Barcode         = product.Barcode;
                    saleItem.Quantity        = quantity;
                    saleItem.UnitPrice       = product.SellingPrice;
                    saleItem.Discount        = (saleItem.UnitPrice * saleItem.Quantity) * (discount.DiscountValue / 100);
                    saleItem.PriceVat        = saleItem.UnitPrice + (saleItem.UnitPrice * vat.VATValue / 100);

                    saleItem.ItemsPrice = (saleItem.Quantity * saleItem.PriceVat) - saleItem.Discount;

                    dgSaleItem.Items.Add(saleItem);
                    saleItemsList.Add(saleItem);
                }
            }
        }
        public void LargePriceLargePercentage_ShouldHaveNoInternalOverflow()
        {
            var discount = new DiscountProduct {
                DiscountType = DiscountType.Percentage, DiscountValue = 5000
            };
            var actual = discount.GetAdjustedPrice(1000000);

            Assert.AreEqual(500000, actual);
        }
        public void AppliesDiscountInTheSimpleProduct()
        {
            IProduct p = new SimpleProduct("Product 1", 4.00);

            //Applies 50% discount in the product p
            DiscountProduct dicountProduct = new DiscountProduct(p, 50.0 / 100.0);

            Assert.AreEqual(2, dicountProduct.Price); //because 4.00/2 = 2.00
        }
 public static void SetProductDiscountOnProductInfo(ProductInfo productInfo, DiscountProduct discount)
 {
     // todo: NewPrice. Maybe move this functionality elsewhere? (duplicate logic)
     if (discount.DiscountType == DiscountType.Amount)
     {
         productInfo.DiscountAmountInCents = discount.RangedDiscountValue(productInfo.ItemCount.GetValueOrDefault(1));
     }
     else
     {
         productInfo.DiscountPercentage = discount.RangedDiscountValue(productInfo.ItemCount.GetValueOrDefault(1)) / 100m;
     }
 }
예제 #6
0
            static void Main(string[] args)
            {
                Product p = new Product();
                p.Name = "Iphone";
                p.Price = 800;
                DiscountProduct p1 = new DiscountProduct();
                p1.Name = "Iphone";
                p1.Price = 800;
                p1.Discount = 10;

                Print(p);
                Print(p1);

                Console.ReadKey();
            }
        public IActionResult Insert(string?id)
        {
            var             lProduct        = _unitOfWork.SP_Call.List <Product>("SP_GetAll_Product");
            DiscountProduct discountProduct = new DiscountProduct()
            {
                DiscountId  = id, //id của Discount
                ProductList = lProduct.Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                })
            };

            return(View(discountProduct));
        }
예제 #8
0
 public static void SetToDisctount(string productCode, string discountCode)
 {
     using (DiscountCardContext context = new DiscountCardContext())
     {
         var discount = context.Discounts.FirstOrDefault(d => d.Code == discountCode);
         var product  = context.Products.FirstOrDefault(d => d.Code == productCode);
         if (discount == null)
         {
             Console.WriteLine("Discount code {0} not exists", discountCode);
         }
         else if (product == null)
         {
             Console.WriteLine("Product code {0} not exists", productCode);
         }
         else
         {
             using (var transaction = context.Database.BeginTransaction())
             {
                 var discountProduct = new DiscountProduct
                 {
                     Discount = discount,
                     Product  = product
                 };
                 context.DiscountProducts.Add(discountProduct);
                 try {
                     context.SaveChanges();
                 } catch (Exception ex) {
                     Console.WriteLine("Relation exist");
                 }
                 transaction.Commit();
                 string[] args = { };
                 Program.Main(args);
             }
         }
     }
 }
예제 #9
0
        public static void DecoratorPatternTest()
        {
            var product1 = new NormalProduct
            {
                Price      = 100,
                TaxPercent = 8
            };
            var discountProduct = new DiscountProduct(product1)
            {
                DiscountPercent = 4
            };
            var product2 = new NormalProduct
            {
                Price      = 200,
                TaxPercent = 8
            };
            var premiumProduct = new PremiumProduct(product2)
            {
                PremiumPrice = 25
            };

            Console.WriteLine($"Total price of product on discount is {discountProduct.CalculateTotalPrice()}");
            Console.WriteLine($"Total price of premium product is {premiumProduct.CalculateTotalPrice()}");
        }
        public static ProductInfo CreateProductInfo(int productPriceInCents, int itemCount, decimal vat = 19, DiscountProduct discount = null, IOrderInfo order = null)
        {
            var productInfo = new ProductInfo();

            productInfo.IsDiscounted         = discount == null;
            productInfo.OriginalPriceInCents = productPriceInCents;
            productInfo.Ranges    = new List <Range>();
            productInfo.Vat       = vat;
            productInfo.ItemCount = itemCount;
            productInfo.Tags      = new string[0];
            if (order != null)
            {
                order.OrderLines = new List <OrderLine> {
                    new OrderLine(productInfo, order)
                };
            }
            productInfo.Order = order ?? CreateOrderInfo(productInfo);
            if (discount != null)
            {
                SetProductDiscountOnProductInfo(productInfo, discount);
            }
            return(productInfo);
        }
 public static ProductInfo CreateProductInfo(int productPriceInCents, int itemCount, DiscountProduct discount)
 {
     return(CreateProductInfo(productPriceInCents, itemCount, 19, discount));
 }
        private void ContentOnAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs documentCacheEventArgs)
        {
            //if (sender.ContentType.Alias.StartsWith("uwbs") && sender.ContentType.Alias != Order.NodeAlias)
            //todo: work with aliasses from config
            var alias = sender.ContentType.Alias;

            // todo: make a nice way for this block
            if (Product.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (ProductVariant.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (Category.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (PaymentProvider.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (PaymentProviderMethod.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (DiscountProduct.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (DiscountOrder.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (ShippingProvider.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (ShippingProviderMethod.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (Store.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (alias.StartsWith("uwbs") && alias != Order.NodeAlias)
            {
                ResetAll(sender.Id, alias);
            }

            var storePickerProperty = sender.getProperty(Constants.StorePickerAlias);

            if (storePickerProperty != null)
            {
                int storeId;
                if (storePickerProperty.Value != null && int.TryParse(storePickerProperty.Value.ToString(), out storeId))
                {
                    var storeService = StoreHelper.StoreService;
                    var storeById    = storeService.GetById(storeId, null);
                    if (storeById != null)
                    {
                        storeService.TriggerStoreChangedEvent(storeById);
                    }
                }
            }

            if (alias.StartsWith(Settings.NodeAlias))
            {
                IO.Container.Resolve <ISettingsService>().TriggerSettingsChangedEvent(SettingsLoader.GetSettings());
            }

            if (alias.StartsWith(Store.NodeAlias))
            {
                //todo: naar nieuwe v6+ API omzetten
                var storeService = StoreHelper.StoreService;
                storeService.TriggerStoreChangedEvent(storeService.GetById(sender.Id, null));
                var node = new Node(sender.Id);
                if (!sender.Text.Equals(node.Name))
                {
                    StoreHelper.RenameStore(node.Name, sender.Text);
                }
            }
        }
예제 #13
0
 public DiscountProductViewModel()
 {
     DiscountProduct = new DiscountProduct();
 }