コード例 #1
0
 public decimal GetAllDiscountsInPercent()
 {
     if (MoneyDiscount > 0)
     {
         return(((Price - PriceWithDiscount) / Price) * 100);
     }
     return(PercentDiscount.GetValueOrDefault());
 }
コード例 #2
0
 public override string ToString()
 {
     return("Code: "
            + Code
            + ", Name: "
            + Name
            + ", Cache: $"
            + Cache.ToString("F2", CultureInfo.InvariantCulture)
            + ", PercentDiscount: "
            + PercentDiscount.ToString("F2", CultureInfo.InvariantCulture));
 }
コード例 #3
0
 public override string ToString()
 {
     return("Product: "
            + product.Description
            + ", Price: "
            + product.Price.ToString("F2", CultureInfo.InvariantCulture)
            + ", Amount: "
            + Amount
            + ", Discount:"
            + PercentDiscount.ToString("F2", CultureInfo.InvariantCulture)
            + ", SubTotal: "
            + SubTotal().ToString("F2", CultureInfo.InvariantCulture));
 }
コード例 #4
0
        public void CanMakeTenPercentDiscountOnPepsi()
        {
            // arrange
            var pepsiTenPercentOff = new PercentDiscount {
                PercentOff = 10m, Product = Pepsi
            };

            _order.AddDiscount(pepsiTenPercentOff);
            _order.ApplyDiscounts();

            // act
            var total = _order.CalculateTotal();

            // assert
            Assert.Equal(0.9m, total);
        }
コード例 #5
0
        public void UnableToApplySameDiscountsTwice()
        {
            // arrange
            var pepsiTenPercentOff = new PercentDiscount {
                PercentOff = 10m, Product = Pepsi
            };

            _order.AddDiscount(pepsiTenPercentOff);

            // act
            _order.ApplyDiscounts();
            _order.ApplyDiscounts();

            // assert
            var total = _order.CalculateTotal();

            Assert.Equal(0.9m, total);
        }
コード例 #6
0
        public async Task <CreateDiscoutPercentCommandResponse> Handle(CreateDiscountPercentCommand command)
        {
            await _percentDiscountDomainService.CheckPercentDiscountDate(command.FromDate.ConvertToDate(), command.ToDate.ConvertToDate());

            var userInfo = new UserInfo(command.UserInfoCommand.UserId, command.UserInfoCommand.FirstName,
                                        command.UserInfoCommand.LastName);

            var discount = new PercentDiscount(Guid.NewGuid(), command.Description, userInfo, command.FromDate.ConvertToDate(),
                                               command.ToDate.ConvertToDate(), command.Title, command.Percent, command.MaxOrderCount, command.MaxProductCount,
                                               command.FromTime, command.ToTime)
            {
                ProductDiscounts = new List <ProductDiscount>(),
                Sells            = new List <DiscountSell>()
            };

            _percentRepository.Add(discount);
            return(new CreateDiscoutPercentCommandResponse());
        }
コード例 #7
0
        public void DoDiscountCategoryPriceTest(double price, int discountValue, Category discountCategory,
                                                Category productCategory)
        {
            var product = new Product()
            {
                BasePrice = price, ResultPrice = price, Type = productCategory
            };

            var discount = new PercentDiscount()
            {
                DiscountValue = discountValue, CategoryOfProduct = discountCategory
            };

            discount.DoDiscount(product);

            if (discount.CategoryOfProduct == product.Type || discount.CategoryOfProduct == Category.All)
            {
                Assert.That(() => product.ResultPrice, Is.EqualTo(price * (1 - (discountValue * 0.01))));
            }
        }
コード例 #8
0
        static void Main()
        {
            Form1       view  = new Form1();
            List <item> items = item.all();

            CashierController controller = new CashierController(view, items);

            controller.Cashier.ClearDiscounts();

            PercentComboDiscount comboDiscount = new PercentComboDiscount();

            comboDiscount.Ids        = new int[] { 0, 2, 3 };
            comboDiscount.Quantities = new int[] { 2, 1, 1 };
            comboDiscount.Percent    = 40; //40%
            controller.Cashier.AddDiscount(comboDiscount);

            PriceComboDiscount comboDiscount1 = new PriceComboDiscount();

            comboDiscount1.Ids        = new int[] { 0, 2 };
            comboDiscount1.Quantities = new int[] { 1, 1 };
            comboDiscount1.Price      = 5000; //VND
            controller.Cashier.AddDiscount(comboDiscount1);

            PercentDiscount discount = new PercentDiscount();

            discount.ItemId  = 3;
            discount.Percent = 10; //10%
            //controller.Cashier.AddDiscount(discount);

            PriceDiscount discount1 = new PriceDiscount();

            discount1.ItemId = 2;
            discount1.Price  = 4000; //VND
            //controller.Cashier.AddDiscount(discount1);

            controller.LoadView();
            view.ShowDialog();
        }
コード例 #9
0
        private void randomButton_Click(object sender, EventArgs e)
        {
            switch (Project.Rnd.Next(2))
            {
            case 0:
                var percentDiscount = new PercentDiscount()
                {
                    CategoryOfProduct = (Category)Project.Rnd.Next(4), DiscountValue = Project.Rnd.Next(101)
                };
                iDiscountBindingSource.Add(percentDiscount);
                WriteDiscountInfo(percentDiscount, iDiscountBindingSource.Count - 1);
                break;

            case 1:
                var certificateDiscount = new CertificateDiscount()
                {
                    CategoryOfProduct = (Category)Project.Rnd.Next(4), DiscountValue = Project.Rnd.Next(100000)
                };
                iDiscountBindingSource.Add(certificateDiscount);
                WriteDiscountInfo(certificateDiscount, iDiscountBindingSource.Count - 1);
                break;
            }
            discountListDataGridView.Update();
        }
コード例 #10
0
        public double ValueTest(double value)
        {
            var discount = new PercentDiscount(value);

            return(discount.Value());
        }
コード例 #11
0
        public double PercentTest(double value)
        {
            var discount = new PercentDiscount(value);

            return(discount.Percent);
        }
コード例 #12
0
        public void PercentCalculateTestThrows(double price, double value)
        {
            var discount = new PercentDiscount(value);

            Assert.That(() => discount.Calculate(price), Throws.TypeOf <ArgumentException>());
        }
コード例 #13
0
        public void PercentCalculateTest(double price, double value, double result)
        {
            var discount = new PercentDiscount(value);

            Assert.That(() => discount.Calculate(price), Is.EqualTo(result));
        }
コード例 #14
0
        public string DescriptionTest(double value)
        {
            var discount = new PercentDiscount(value);

            return(discount.Description);
        }
コード例 #15
0
        public void NegativeDiscountValueTest(int value)
        {
            var discount = new PercentDiscount();

            Assert.That(() => discount.DiscountValue = value, Throws.Exception.TypeOf <ArgumentOutOfRangeException>());
        }
コード例 #16
0
        public void PositiveDiscountValueTest(int value)
        {
            var discount = new PercentDiscount();

            Assert.That(() => discount.DiscountValue = value, Is.EqualTo(value));
        }
コード例 #17
0
 public static IPercentDiscountDto ToDiscountDto(this PercentDiscount src)
 {
     return(AutoMapper.Mapper.Map <IPercentDiscountDto>(src));
 }